From b6e83108482aec1d6a4e68d42993c59a7271eeee Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Thu, 19 Mar 2015 12:46:36 +0100 Subject: [PATCH] Require an initalization value when let/var/const-declaring a complex pattern Closes #222 --- acorn.js | 2 ++ test/tests-harmony.js | 2 ++ 2 files changed, 4 insertions(+) diff --git a/acorn.js b/acorn.js index 17ca02ce82..0e9845a2d5 100644 --- a/acorn.js +++ b/acorn.js @@ -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; } diff --git a/test/tests-harmony.js b/test/tests-harmony.js index 3a8c55db7c..e4b0ee4ff8 100644 --- a/test/tests-harmony.js +++ b/test/tests-harmony.js @@ -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});