diff --git a/src/statement.js b/src/statement.js index d6b94bea24..e90e97b489 100644 --- a/src/statement.js +++ b/src/statement.js @@ -364,7 +364,7 @@ pp.parseForIn = function(node, init) { // Parse a list of variable declarations. -pp.parseVar = function(node, noIn, kind) { +pp.parseVar = function(node, isFor, kind) { node.declarations = [] node.kind = kind.keyword for (;;) { @@ -372,10 +372,10 @@ pp.parseVar = function(node, noIn, kind) { decl.id = this.parseBindingAtom() this.checkLVal(decl.id, true) if (this.eat(tt.eq)) { - decl.init = this.parseMaybeAssign(noIn) + decl.init = this.parseMaybeAssign(isFor) } else if (kind === tt._const && !(this.type === tt._in || (this.options.ecmaVersion >= 6 && this.isContextual("of")))) { this.unexpected() - } else if (decl.id.type != "Identifier") { + } else if (decl.id.type != "Identifier" && !(isFor && (this.type === tt._in || this.isContextual("of")))) { this.raise(this.lastTokEnd, "Complex binding patterns require an initialization value") } else { decl.init = null diff --git a/test/tests-harmony.js b/test/tests-harmony.js index 75019ce3af..bf55f8bfde 100644 --- a/test/tests-harmony.js +++ b/test/tests-harmony.js @@ -15522,6 +15522,47 @@ test("[x,,] = 1", { ] }, {ecmaVersion: 6}); +test("for (var [name, value] in obj) {}", { + body: [ + { + left: { + declarations: [ + { + id: { + elements: [ + { + name: "name", + type: "Identifier" + }, + { + name: "value", + type: "Identifier" + } + ], + type: "ArrayPattern" + }, + init: null, + type: "VariableDeclarator" + } + ], + kind: "var", + type: "VariableDeclaration" + }, + right: { + name: "obj", + type: "Identifier" + }, + body: { + body: [], + type: "BlockStatement" + }, + type: "ForInStatement" + } + ], + sourceType: "script", + type: "Program" +}, {ecmaVersion: 6}) + testFail("let [x]", "Complex binding patterns require an initialization value (1:7)", {ecmaVersion: 6}) testFail("var [x]", "Complex binding patterns require an initialization value (1:7)", {ecmaVersion: 6}) testFail("var _ð–«µ = 11;", "Unexpected character 'ð–«µ' (1:5)", {ecmaVersion: 6});