Skip to content

Commit 272c105

Browse files
committed
support destructing on assignment
fixes webpack#4870
1 parent 6d24f0d commit 272c105

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

lib/Parser.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -993,8 +993,9 @@ class Parser extends Tapable {
993993
}
994994
} else {
995995
this.walkExpression(expression.right);
996-
this.scope.renames["$" + expression.left.name] = undefined;
997-
this.walkExpression(expression.left);
996+
this.enterPattern(expression.left, (name, decl) => {
997+
this.scope.renames["$" + name] = undefined;
998+
});
998999
}
9991000
}
10001001

test/cases/parsing/issue-4870/file.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export var test = "test";
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { test } from "./file";
2+
3+
it("should allow import in array destructing", function() {
4+
var other;
5+
[other = test] = [];
6+
other.should.be.eql("test");
7+
});
8+
9+
it("should allow import in object destructing", function() {
10+
var other;
11+
({other = test} = {});
12+
other.should.be.eql("test");
13+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
var supportsIteratorDestructuring = require("../../../helpers/supportsIteratorDestructuring");
2+
var supportsObjectDestructuring = require("../../../helpers/supportsObjectDestructuring");
3+
4+
module.exports = function(config) {
5+
return !config.minimize && supportsObjectDestructuring() && supportsIteratorDestructuring();
6+
};

0 commit comments

Comments
 (0)