Skip to content

Commit 4830503

Browse files
committed
fix ExportsInfo
- should mark every export canMangleProvide=false if there are unknown exports - add __webpack_exports_info__.<name>.canMangle to api - add test case
1 parent 0d38e57 commit 4830503

9 files changed

Lines changed: 33 additions & 5 deletions

File tree

lib/ExportsInfo.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -291,15 +291,15 @@ class ExportsInfo {
291291
}
292292
}
293293
for (const exportInfo of this._exports.values()) {
294+
if (!canMangle && exportInfo.canMangleProvide !== false) {
295+
exportInfo.canMangleProvide = false;
296+
changed = true;
297+
}
294298
if (excludeExports && excludeExports.has(exportInfo.name)) continue;
295299
if (exportInfo.provided !== true && exportInfo.provided !== null) {
296300
exportInfo.provided = null;
297301
changed = true;
298302
}
299-
if (!canMangle && exportInfo.canMangleProvide !== false) {
300-
exportInfo.canMangleProvide = false;
301-
changed = true;
302-
}
303303
if (targetKey) {
304304
exportInfo.setTarget(targetKey, targetModule, [exportInfo.name], -1);
305305
}

lib/dependencies/ExportsInfoDependency.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ const getProperty = (moduleGraph, module, exportName, property, runtime) => {
4646
}
4747
}
4848
switch (property) {
49+
case "canMangle": {
50+
const exportsInfo = moduleGraph.getExportsInfo(module);
51+
const exportInfo = exportsInfo.getExportInfo(exportName);
52+
if (exportInfo) return exportInfo.canMangle;
53+
return exportsInfo.otherExportsInfo.canMangleProvide;
54+
}
4955
case "used":
5056
return (
5157
moduleGraph.getExportsInfo(module).getUsed(exportName, runtime) !==

test/__snapshots__/StatsTestCases.basictest.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3274,7 +3274,7 @@ cacheable modules 1.22 KiB
32743274
ModuleConcatenation bailout: Module is not an ECMAScript module
32753275
webpack x.x.x compiled successfully in X ms
32763276
3277-
asset main.no-side.js 979 bytes [emitted] [minimized] (name: main)
3277+
asset main.no-side.js 993 bytes [emitted] [minimized] (name: main)
32783278
runtime modules 1010 bytes 4 modules
32793279
orphan modules 102 bytes [orphan] 2 modules
32803280
cacheable modules 1.35 KiB
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { b } from "./b";
2+
3+
export function a() {
4+
return b();
5+
}
6+
export const aUsed = __webpack_exports_info__.a.used;
7+
export const aProvided = __webpack_exports_info__.a.provideInfo;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export function b() {}

test/configCases/parsing/harmony-reexport/empty.js

Whitespace-only changes.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { a, aUsed, aCanBeMangled, aProvided } from "./reexport";
2+
3+
if (a()) console.log("a");
4+
5+
it("should not allow mangle if some exports are unknown", () => {
6+
expect(aUsed).toBe(true);
7+
expect(aProvided).toBe(true);
8+
expect(aCanBeMangled).toBe(false);
9+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export * from "./a";
2+
export * from "./empty";
3+
export const aCanBeMangled = __webpack_exports_info__.a.canMangle;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/** @type {import("../../../../").Configuration} */
2+
module.exports = {};

0 commit comments

Comments
 (0)