Skip to content

Commit

Permalink
fix ExportsInfo
Browse files Browse the repository at this point in the history
- should mark every export canMangleProvide=false if there are unknown exports
- add __webpack_exports_info__.<name>.canMangle to api
- add test case
  • Loading branch information
vankop committed Feb 10, 2022
1 parent 0d38e57 commit 4830503
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 5 deletions.
8 changes: 4 additions & 4 deletions lib/ExportsInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,15 +291,15 @@ class ExportsInfo {
}
}
for (const exportInfo of this._exports.values()) {
if (!canMangle && exportInfo.canMangleProvide !== false) {
exportInfo.canMangleProvide = false;
changed = true;
}
if (excludeExports && excludeExports.has(exportInfo.name)) continue;
if (exportInfo.provided !== true && exportInfo.provided !== null) {
exportInfo.provided = null;
changed = true;
}
if (!canMangle && exportInfo.canMangleProvide !== false) {
exportInfo.canMangleProvide = false;
changed = true;
}
if (targetKey) {
exportInfo.setTarget(targetKey, targetModule, [exportInfo.name], -1);
}
Expand Down
6 changes: 6 additions & 0 deletions lib/dependencies/ExportsInfoDependency.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ const getProperty = (moduleGraph, module, exportName, property, runtime) => {
}
}
switch (property) {
case "canMangle": {
const exportsInfo = moduleGraph.getExportsInfo(module);
const exportInfo = exportsInfo.getExportInfo(exportName);
if (exportInfo) return exportInfo.canMangle;
return exportsInfo.otherExportsInfo.canMangleProvide;
}
case "used":
return (
moduleGraph.getExportsInfo(module).getUsed(exportName, runtime) !==
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 @@ -3274,7 +3274,7 @@ cacheable modules 1.22 KiB
ModuleConcatenation bailout: Module is not an ECMAScript module
webpack x.x.x compiled successfully in X ms
asset main.no-side.js 979 bytes [emitted] [minimized] (name: main)
asset main.no-side.js 993 bytes [emitted] [minimized] (name: main)
runtime modules 1010 bytes 4 modules
orphan modules 102 bytes [orphan] 2 modules
cacheable modules 1.35 KiB
Expand Down
7 changes: 7 additions & 0 deletions test/configCases/parsing/harmony-reexport/a.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { b } from "./b";

export function a() {
return b();
}
export const aUsed = __webpack_exports_info__.a.used;
export const aProvided = __webpack_exports_info__.a.provideInfo;
1 change: 1 addition & 0 deletions test/configCases/parsing/harmony-reexport/b.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export function b() {}
Empty file.
9 changes: 9 additions & 0 deletions test/configCases/parsing/harmony-reexport/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { a, aUsed, aCanBeMangled, aProvided } from "./reexport";

if (a()) console.log("a");

it("should not allow mangle if some exports are unknown", () => {
expect(aUsed).toBe(true);
expect(aProvided).toBe(true);
expect(aCanBeMangled).toBe(false);
});
3 changes: 3 additions & 0 deletions test/configCases/parsing/harmony-reexport/reexport.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from "./a";
export * from "./empty";
export const aCanBeMangled = __webpack_exports_info__.a.canMangle;
2 changes: 2 additions & 0 deletions test/configCases/parsing/harmony-reexport/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/** @type {import("../../../../").Configuration} */
module.exports = {};

0 comments on commit 4830503

Please sign in to comment.