Skip to content

Commit

Permalink
fix: mangle export with destructuring
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Feb 8, 2024
2 parents 51f0f0a + 69127ae commit 2a063f8
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/dependencies/HarmonyImportSpecifierDependency.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
for (const key of this.referencedPropertiesInDestructuring) {
refs.push({
name: ids ? ids.concat([key]) : [key],
canMangle: false
canMangle: Array.isArray(ids) && ids.length > 0
});
}
return refs;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import * as module from "./module";

it("should not mangle export when destructuring module", () => {
const { obj: { a, b }, objCanMangle } = module
expect(a).toBe("a");
expect(b).toBe("b");
expect(objCanMangle).toBe(false)
});

it("should mangle export when destructuring module's porperty", () => {
const { a, b } = module.obj2
const { obj2CanMangle } = module
expect(a).toBe("a");
expect(b).toBe("b");
expect(obj2CanMangle).toBe(true)
});

it("should mangle export when using module dot property", () => {
expect(module.aaa).toBe("aaa");
expect(module.aaaCanMangle).toBe(true)
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const aaa = "aaa";
export const aaaCanMangle = __webpack_exports_info__.aaa.canMangle;

export const obj = { a: "a", b: "b" }
export const objCanMangle = __webpack_exports_info__.obj.canMangle;

export const obj2 = { a: "a", b: "b" }
export const obj2CanMangle = __webpack_exports_info__.obj2.canMangle;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** @type {import("../../../../").Configuration} */
module.exports = {
optimization: {
mangleExports: true,
usedExports: true,
providedExports: true
}
};

0 comments on commit 2a063f8

Please sign in to comment.