Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 71ce863

Browse files
fix: mangle destruction incorrect with export named default
2 parents ddbea27 + 0d856a3 commit 71ce863

File tree

5 files changed

+40
-1
lines changed

5 files changed

+40
-1
lines changed

lib/dependencies/HarmonyImportSpecifierDependency.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,27 @@ HarmonyImportSpecifierDependency.Template = class HarmonyImportSpecifierDependen
343343
}
344344

345345
if (dep.referencedPropertiesInDestructuring) {
346-
const prefixedIds = ids[0] === "default" ? ids.slice(1) : ids;
346+
let prefixedIds = ids;
347+
348+
if (ids[0] === "default") {
349+
const selfModule = moduleGraph.getParentModule(dep);
350+
const importedModule =
351+
/** @type {Module} */
352+
(moduleGraph.getModule(dep));
353+
const exportsType = importedModule.getExportsType(
354+
moduleGraph,
355+
/** @type {BuildMeta} */
356+
(selfModule.buildMeta).strictHarmonyModule
357+
);
358+
if (
359+
(exportsType === "default-only" ||
360+
exportsType === "default-with-named") &&
361+
ids.length >= 1
362+
) {
363+
prefixedIds = ids.slice(1);
364+
}
365+
}
366+
347367
for (const {
348368
id,
349369
shorthand,
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import namespace from "./re-exports";
2+
3+
it("should mangle exports imported", () => {
4+
const { foo } = namespace;
5+
expect(foo).toBe('foo')
6+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const foo = 'foo';
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import * as namespace from './module';
2+
3+
export { namespace as default };
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/** @type {import("../../../../").Configuration} */
2+
module.exports = {
3+
optimization: {
4+
mangleExports: true,
5+
usedExports: true,
6+
providedExports: true,
7+
sideEffects: false // disable reexports optimization
8+
}
9+
};

0 commit comments

Comments
 (0)