diff --git a/lib/Parser.js b/lib/Parser.js index dc2a5c3fc4f..a98ca4909c1 100644 --- a/lib/Parser.js +++ b/lib/Parser.js @@ -993,8 +993,9 @@ class Parser extends Tapable { } } else { this.walkExpression(expression.right); - this.scope.renames["$" + expression.left.name] = undefined; - this.walkExpression(expression.left); + this.enterPattern(expression.left, (name, decl) => { + this.scope.renames["$" + name] = undefined; + }); } } diff --git a/test/cases/parsing/issue-4870/file.js b/test/cases/parsing/issue-4870/file.js new file mode 100644 index 00000000000..173df5cb056 --- /dev/null +++ b/test/cases/parsing/issue-4870/file.js @@ -0,0 +1 @@ +export var test = "test"; diff --git a/test/cases/parsing/issue-4870/index.js b/test/cases/parsing/issue-4870/index.js new file mode 100644 index 00000000000..81774bc885b --- /dev/null +++ b/test/cases/parsing/issue-4870/index.js @@ -0,0 +1,13 @@ +import { test } from "./file"; + +it("should allow import in array destructing", function() { + var other; + [other = test] = []; + other.should.be.eql("test"); +}); + +it("should allow import in object destructing", function() { + var other; + ({other = test} = {}); + other.should.be.eql("test"); +}); diff --git a/test/cases/parsing/issue-4870/test.filter.js b/test/cases/parsing/issue-4870/test.filter.js new file mode 100644 index 00000000000..f4216934be7 --- /dev/null +++ b/test/cases/parsing/issue-4870/test.filter.js @@ -0,0 +1,6 @@ +var supportsIteratorDestructuring = require("../../../helpers/supportsIteratorDestructuring"); +var supportsObjectDestructuring = require("../../../helpers/supportsObjectDestructuring"); + +module.exports = function(config) { + return !config.minimize && supportsObjectDestructuring() && supportsIteratorDestructuring(); +};