Skip to content

Commit d1caae9

Browse files
authored
fix: resolve member access through a namespace re-exported as default (#21702)
1 parent 6a64e5c commit d1caae9

7 files changed

Lines changed: 53 additions & 1 deletion

File tree

‎.changeset/lucky-pianos-repeat.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"webpack": patch
3+
---
4+
5+
Fix `import d from "./mod"; d.member` reading `undefined` when `mod` re-exports a namespace as `default`.

‎lib/util/chainedImports.js‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,11 @@ function trimIdsToThoseImported(ids, moduleGraph, dependency) {
7878
);
7979
for (let i = 0; i < ids.length; i++) {
8080
if (i === 0 && ids[i] === "default") {
81-
continue; // ExportInfo for the next level under default is still at the root ExportsInfo, so don't advance currentExportsInfo
81+
const nestedInfo = currentExportsInfo
82+
.getExportInfo(ids[i])
83+
.getNestedExportsInfo();
84+
if (nestedInfo) currentExportsInfo = nestedInfo;
85+
continue;
8286
}
8387
const exportInfo = currentExportsInfo.getExportInfo(ids[i]);
8488
if (exportInfo.provided === false) {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import * as ns from "./source";
2+
3+
export default ns;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import fromSpecifier from "./specifier";
2+
import fromExpression from "./expression";
3+
4+
it("should mangle a property read through a namespace re-exported as default", () => {
5+
expect(fromSpecifier.member.value).toBe(42);
6+
expect(fromExpression.member.value).toBe(42);
7+
});
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const member = { value: 42 };
2+
export const other = { value: 7 };
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import * as ns from "./source";
2+
3+
export { ns as default };
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"use strict";
2+
3+
/**
4+
* @param {string} name config name
5+
* @param {boolean} concatenateModules whether to enable module concatenation
6+
* @returns {import("../../../../").Configuration} config
7+
*/
8+
const config = (name, concatenateModules) => ({
9+
name,
10+
mode: "production",
11+
optimization: {
12+
concatenateModules,
13+
// keeps the re-exporting module in the graph; when it is skipped the ids
14+
// are rewritten to point straight at `source.js` and never reach the
15+
// cross-module lookup this exercises
16+
sideEffects: false,
17+
minimize: false
18+
}
19+
});
20+
21+
/** @type {import("../../../../").Configuration[]} */
22+
module.exports = [
23+
config(
24+
"mangled-namespace-default-reexport without module concatenation",
25+
false
26+
),
27+
config("mangled-namespace-default-reexport with module concatenation", true)
28+
];

0 commit comments

Comments
 (0)