fix: mangle destruction incorrect with export named default

This commit is contained in:
Alexander Akait 2024-08-14 19:14:31 +03:00 committed by GitHub
commit 71ce863569
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 40 additions and 1 deletions

View File

@ -343,7 +343,27 @@ HarmonyImportSpecifierDependency.Template = class HarmonyImportSpecifierDependen
}
if (dep.referencedPropertiesInDestructuring) {
const prefixedIds = ids[0] === "default" ? ids.slice(1) : ids;
let prefixedIds = ids;
if (ids[0] === "default") {
const selfModule = moduleGraph.getParentModule(dep);
const importedModule =
/** @type {Module} */
(moduleGraph.getModule(dep));
const exportsType = importedModule.getExportsType(
moduleGraph,
/** @type {BuildMeta} */
(selfModule.buildMeta).strictHarmonyModule
);
if (
(exportsType === "default-only" ||
exportsType === "default-with-named") &&
ids.length >= 1
) {
prefixedIds = ids.slice(1);
}
}
for (const {
id,
shorthand,

View File

@ -0,0 +1,6 @@
import namespace from "./re-exports";
it("should mangle exports imported", () => {
const { foo } = namespace;
expect(foo).toBe('foo')
});

View File

@ -0,0 +1 @@
export const foo = 'foo';

View File

@ -0,0 +1,3 @@
import * as namespace from './module';
export { namespace as default };

View File

@ -0,0 +1,9 @@
/** @type {import("../../../../").Configuration} */
module.exports = {
optimization: {
mangleExports: true,
usedExports: true,
providedExports: true,
sideEffects: false // disable reexports optimization
}
};