Require an initalization value when let/var/const-declaring a complex pattern

Closes #222
This commit is contained in:
Marijn Haverbeke 2015-03-19 12:46:36 +01:00
parent a75a685610
commit b6e8310848
2 changed files with 4 additions and 0 deletions

View File

@ -2134,6 +2134,8 @@
decl.init = this.parseMaybeAssign(noIn);
} else if (kind === tt._const && !(this.type === tt._in || (this.options.ecmaVersion >= 6 && this.isContextual("of")))) {
this.unexpected();
} else if (decl.id.type != "Identifier") {
this.raise(this.lastTokEnd, "Complex binding patterns require an initialization value")
} else {
decl.init = null;
}

View File

@ -15466,6 +15466,8 @@ test("let {x} = y", {
"end": 11
}, {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});
testFail("var 𫠞_ = 12;", "Unexpected character '𫠞' (1:4)", {ecmaVersion: 6});
testFail("var 𫠝_ = 10;", "Unexpected character '𫠝' (1:4)", {ecmaVersion: 5});