Skip to content

Commit

Permalink
update topLevelDeclarations for ConcatenatedModule
Browse files Browse the repository at this point in the history
update top level declarations for ConcatenatedModule in code generation step
  • Loading branch information
vankop committed Feb 4, 2022
1 parent afbf602 commit fee6837
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 3 deletions.
11 changes: 9 additions & 2 deletions lib/optimize/ConcatenatedModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -829,8 +829,6 @@ class ConcatenatedModule extends Module {
topLevelDeclarations.add(decl);
}
}
} else {
this.buildInfo.topLevelDeclarations = undefined;
}

// populate assets
Expand Down Expand Up @@ -1113,6 +1111,8 @@ class ConcatenatedModule extends Module {

// List of all used names to avoid conflicts
const allUsedNames = new Set(RESERVED_NAMES);
// Top level declarations should be updated with respect of renaming
const topLevelDeclarations = this.buildInfo.topLevelDeclarations;

// List of additional names in scope for module references
/** @type {Map<string, { usedNames: Set<string>, alreadyCheckedScopes: Set<TODO> }>} */
Expand Down Expand Up @@ -1257,6 +1257,7 @@ class ConcatenatedModule extends Module {
);
allUsedNames.add(newName);
info.internalNames.set(name, newName);
topLevelDeclarations.add(newName);
const source = info.source;
const allIdentifiers = new Set(
references.map(r => r.identifier).concat(variable.identifiers)
Expand All @@ -1283,6 +1284,7 @@ class ConcatenatedModule extends Module {
} else {
allUsedNames.add(name);
info.internalNames.set(name, name);
topLevelDeclarations.add(name);
}
}
let namespaceObjectName;
Expand All @@ -1300,6 +1302,7 @@ class ConcatenatedModule extends Module {
allUsedNames.add(namespaceObjectName);
}
info.namespaceObjectName = namespaceObjectName;
topLevelDeclarations.add(namespaceObjectName);
break;
}
case "external": {
Expand All @@ -1311,6 +1314,7 @@ class ConcatenatedModule extends Module {
);
allUsedNames.add(externalName);
info.name = externalName;
topLevelDeclarations.add(externalName);
break;
}
}
Expand All @@ -1323,6 +1327,7 @@ class ConcatenatedModule extends Module {
);
allUsedNames.add(externalNameInterop);
info.interopNamespaceObjectName = externalNameInterop;
topLevelDeclarations.add(externalNameInterop);
}
if (
info.module.buildMeta.exportsType === "default" &&
Expand All @@ -1336,6 +1341,7 @@ class ConcatenatedModule extends Module {
);
allUsedNames.add(externalNameInterop);
info.interopNamespaceObject2Name = externalNameInterop;
topLevelDeclarations.add(externalNameInterop);
}
if (
info.module.buildMeta.exportsType === "dynamic" ||
Expand All @@ -1349,6 +1355,7 @@ class ConcatenatedModule extends Module {
);
allUsedNames.add(externalNameInterop);
info.interopDefaultAccessName = externalNameInterop;
topLevelDeclarations.add(externalNameInterop);
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/__snapshots__/StatsTestCases.basictest.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1099,7 +1099,7 @@ chunk (runtime: main) trees.js (trees) 215 bytes [rendered]
`;

exports[`StatsTestCases should print correct stats for ignore-warnings 1`] = `
"asset main.js 1.37 KiB [emitted] (name: main)
"asset main.js 989 bytes [emitted] (name: main)
orphan modules 617 bytes [orphan] 9 modules
./index.js + 9 modules 790 bytes [built] [code generated]
Expand Down
3 changes: 3 additions & 0 deletions test/configCases/concatenate-modules/issue-13022/a.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const doc = console;

export default 1;
9 changes: 9 additions & 0 deletions test/configCases/concatenate-modules/issue-13022/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import "./a";

const doc = console;

export default 1;

it("should compile and run", () => {
expect(doc).toBe(console);
});
29 changes: 29 additions & 0 deletions test/configCases/concatenate-modules/issue-13022/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const path = require("path");

/** @type {import("../../../../").Configuration[]} */
module.exports = [
{
entry: {
index: path.resolve(__dirname, "./index.js")
},
output: {
library: "[name]",
libraryExport: "default"
},
optimization: {
concatenateModules: true
}
},
{
entry: {
index: path.resolve(__dirname, "./index.js")
},
output: {
library: "[name]_doc",
libraryExport: "default"
},
optimization: {
concatenateModules: true
}
}
];

0 comments on commit fee6837

Please sign in to comment.