mirror of https://github.com/webpack/webpack.git
fix: destructuring namespace import with default (#19526)
This commit is contained in:
parent
c6ae84152e
commit
a66acdc81e
|
@ -2852,8 +2852,15 @@ class JavascriptParser extends Parser {
|
|||
for (let i = 0; i < properties.length; i++) {
|
||||
const property = properties[i];
|
||||
if (property.type !== "Property") return;
|
||||
if (property.shorthand && property.value.type === "Identifier") {
|
||||
this.scope.inShorthand = property.value.name;
|
||||
if (property.shorthand) {
|
||||
if (property.value.type === "Identifier") {
|
||||
this.scope.inShorthand = property.value.name;
|
||||
} else if (
|
||||
property.value.type === "AssignmentPattern" &&
|
||||
property.value.left.type === "Identifier"
|
||||
) {
|
||||
this.scope.inShorthand = property.value.left.name;
|
||||
}
|
||||
}
|
||||
const key = property.key;
|
||||
if (key.type === "Identifier") {
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
import * as namespace from "./module.js";
|
||||
|
||||
it("should work with destructuring", function() {
|
||||
{
|
||||
const { foo } = namespace;
|
||||
expect(foo).toBe("bar");
|
||||
}
|
||||
|
||||
{
|
||||
let foo;
|
||||
({ foo } = namespace);
|
||||
expect(foo).toBe("bar");
|
||||
}
|
||||
|
||||
{
|
||||
let foo;
|
||||
({ foo = 'foo' } = namespace);
|
||||
expect(foo).toBe("bar");
|
||||
}
|
||||
|
||||
{
|
||||
const { foo = 'foo' } = namespace;
|
||||
expect(foo).toBe("bar");
|
||||
}
|
||||
|
||||
{
|
||||
const strings = [];
|
||||
({ foo : strings[0] } = namespace);
|
||||
expect(strings[0]).toBe("bar");
|
||||
}
|
||||
|
||||
{
|
||||
const { foo: otherFoo = 'foo' } = namespace;
|
||||
expect(otherFoo).toBe("bar");
|
||||
}
|
||||
|
||||
{
|
||||
const { bar = 'foo' } = namespace;
|
||||
expect(bar).toBe("foo");
|
||||
}
|
||||
});
|
|
@ -0,0 +1 @@
|
|||
export const foo = 'bar';
|
|
@ -0,0 +1,6 @@
|
|||
/** @type {import("../../../../").Configuration} */
|
||||
module.exports = {
|
||||
optimization: {
|
||||
concatenateModules: true
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue