make parenthesized array patterns illegal - cc @michaelficarra

This commit is contained in:
Sebastian McKenzie
2015-04-13 16:16:57 -07:00
parent fb30e79e03
commit 6763c4415e
2 changed files with 9 additions and 1 deletions

View File

@@ -103,7 +103,7 @@ pp.parseMaybeAssign = function(noIn, refShorthandDefaultPos, afterLeftParse) {
node.left = this.type === tt.eq ? this.toAssignable(left) : left
refShorthandDefaultPos.start = 0 // reset because shorthand default was used correctly
this.checkLVal(left)
if (left.parenthesizedExpression && left.type === "ObjectPattern") {
if (left.parenthesizedExpression && (left.type === "ObjectPattern" || left.type === "ArrayPattern")) {
this.raise(left.start, "You're trying to assign to a parenthesized expression, instead of `({ foo }) = {}` use `({ foo } = {})`");
}
this.next()

View File

@@ -2,6 +2,14 @@ var test = require("./driver.js").test;
var testFail = require("./driver.js").testFail;
var testAssert = require("./driver.js").testAssert;
testFail("({a}) = 2;", "You're trying to assign to a parenthesized expression, instead of `({ foo }) = {}` use `({ foo } = {})` (1:1)", {
ecmaVersion: 6
});
testFail("([a]) = 2;", "You're trying to assign to a parenthesized expression, instead of `({ foo }) = {}` use `({ foo } = {})` (1:1)", {
ecmaVersion: 6
});
// ES7: Exponentiation Operator
test('a **= 2;', {