mirror of https://github.com/webpack/webpack.git
fix: mangle destructuring default in namespace import
This commit is contained in:
commit
e38e2bc31b
|
|
@ -344,13 +344,13 @@ HarmonyImportSpecifierDependency.Template = class HarmonyImportSpecifierDependen
|
|||
}
|
||||
|
||||
if (dep.referencedPropertiesInDestructuring) {
|
||||
const prefixedIds = ids[0] === "default" ? ids.slice(1) : ids;
|
||||
for (let {
|
||||
id,
|
||||
shorthand,
|
||||
range
|
||||
} of dep.referencedPropertiesInDestructuring) {
|
||||
const concatedIds = ids.concat([id]);
|
||||
if (concatedIds[0] === "default") concatedIds.shift();
|
||||
const concatedIds = prefixedIds.concat([id]);
|
||||
const module = moduleGraph.getModule(dep);
|
||||
const used = moduleGraph
|
||||
.getExportsInfo(module)
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import path from "path";
|
||||
import * as module from "./module";
|
||||
import { obj3, obj3CanMangle, obj4, obj4CanMangle } from "./reexport?side-effects" // enable side effects to ensure reexport is not skipped
|
||||
import data from "./data.json";
|
||||
import data2 from "./data.json?2";
|
||||
import path from "path";
|
||||
|
||||
it("should mangle export when destructuring module", () => {
|
||||
const { obj: { a, b }, objCanMangle } = module
|
||||
|
|
@ -39,6 +39,12 @@ it("should not mangle export when destructuring module's nested property is a mo
|
|||
expect(obj5CanMangle).toBe(false); // obj5 is used in unknown way
|
||||
});
|
||||
|
||||
it("should mangle default in namespace import", async () => {
|
||||
const { default: foo, defaultCanMangle } = module;
|
||||
expect(foo).toBe("default");
|
||||
expect(defaultCanMangle).toBe(true);
|
||||
});
|
||||
|
||||
it("should mangle when destructuring json", async () => {
|
||||
const { obj: {
|
||||
"arr": [
|
||||
|
|
|
|||
|
|
@ -6,3 +6,6 @@ export const objCanMangle = __webpack_exports_info__.obj.canMangle;
|
|||
|
||||
export const obj2 = { a: "a", b: "b" }
|
||||
export const obj2CanMangle = __webpack_exports_info__.obj2.canMangle;
|
||||
|
||||
export default "default";
|
||||
export const defaultCanMangle = __webpack_exports_info__.default.canMangle;
|
||||
|
|
|
|||
Loading…
Reference in New Issue