From 1488698e4977ed0eb6b262669eb4ca0432bc8f93 Mon Sep 17 00:00:00 2001 From: Kai Cataldo Date: Wed, 19 Jun 2019 19:07:12 +0000 Subject: [PATCH 1/2] Disallow let as identifier name in patterns --- acorn/src/lval.js | 4 +++- acorn/src/statement.js | 3 --- test/tests-harmony.js | 20 ++++++++++++++++++-- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/acorn/src/lval.js b/acorn/src/lval.js index dbd220f93..8ad4b2639 100644 --- a/acorn/src/lval.js +++ b/acorn/src/lval.js @@ -1,7 +1,7 @@ import {types as tt} from "./tokentype" import {Parser} from "./state" import {has} from "./util" -import {BIND_NONE, BIND_OUTSIDE} from "./scopeflags" +import {BIND_NONE, BIND_OUTSIDE, BIND_LEXICAL} from "./scopeflags" const pp = Parser.prototype @@ -189,6 +189,8 @@ pp.parseMaybeDefault = function(startPos, startLoc, left) { pp.checkLVal = function(expr, bindingType = BIND_NONE, checkClashes) { switch (expr.type) { case "Identifier": + if (bindingType === BIND_LEXICAL && expr.name === "let") + this.raiseRecoverable(expr.start, "let is disallowed as a lexically bound name") if (this.strict && this.reservedWordsStrictBind.test(expr.name)) this.raiseRecoverable(expr.start, (bindingType ? "Binding " : "Assigning to ") + expr.name + " in strict mode") if (checkClashes) { diff --git a/acorn/src/statement.js b/acorn/src/statement.js index b6e2a69d7..6bc47c3fc 100644 --- a/acorn/src/statement.js +++ b/acorn/src/statement.js @@ -501,9 +501,6 @@ pp.parseVar = function(node, isFor, kind) { } pp.parseVarId = function(decl, kind) { - if ((kind === "const" || kind === "let") && this.isContextual("let")) { - this.raiseRecoverable(this.start, "let is disallowed as a lexically bound name") - } decl.id = this.parseBindingAtom() this.checkLVal(decl.id, kind === "var" ? BIND_VAR : BIND_LEXICAL, false) } diff --git a/test/tests-harmony.js b/test/tests-harmony.js index a76d5a36f..a37495efe 100644 --- a/test/tests-harmony.js +++ b/test/tests-harmony.js @@ -13409,9 +13409,25 @@ testFail("let let", "let is disallowed as a lexically bound name (1:4)", {ecmaVe testFail("const let", "let is disallowed as a lexically bound name (1:6)", {ecmaVersion: 6}) -testFail("'use strict'; let let", "let is disallowed as a lexically bound name (1:18)", {ecmaVersion: 6}) +testFail("let { let } = {};", "let is disallowed as a lexically bound name (1:6)", {ecmaVersion: 6}) -testFail("'use strict'; const let", "let is disallowed as a lexically bound name (1:20)", {ecmaVersion: 6}) +testFail("const { let } = {};", "let is disallowed as a lexically bound name (1:8)", {ecmaVersion: 6}) + +testFail("let [let] = [];", "let is disallowed as a lexically bound name (1:5)", {ecmaVersion: 6}) + +testFail("const [let] = [];", "let is disallowed as a lexically bound name (1:7)", {ecmaVersion: 6}) + +testFail("'use strict'; let let", "The keyword 'let' is reserved (1:18)", {ecmaVersion: 6}) + +testFail("'use strict'; const let", "The keyword 'let' is reserved (1:20)", {ecmaVersion: 6}) + +testFail("'use strict'; let { let } = {};", "The keyword 'let' is reserved (1:20)", {ecmaVersion: 6}) + +testFail("'use strict'; const { let } = {};", "The keyword 'let' is reserved (1:22)", {ecmaVersion: 6}) + +testFail("'use strict'; let [let] = [];", "The keyword 'let' is reserved (1:19)", {ecmaVersion: 6}) + +testFail("'use strict'; const [let] = [];", "The keyword 'let' is reserved (1:21)", {ecmaVersion: 6}) test("if (1) let\n{}", {}, {ecmaVersion: 6}) From 1c4aea68d5e319aa7a0a84b6484077bc69ec72ba Mon Sep 17 00:00:00 2001 From: Kai Cataldo Date: Wed, 19 Jun 2019 19:20:19 +0000 Subject: [PATCH 2/2] Group strict mode let keyword tests --- test/tests-harmony.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/tests-harmony.js b/test/tests-harmony.js index a37495efe..ade46a220 100644 --- a/test/tests-harmony.js +++ b/test/tests-harmony.js @@ -13403,7 +13403,6 @@ test("var let = 1", { ] }, {ecmaVersion: 6}) -testFail("'use strict'; let + 1", "The keyword 'let' is reserved (1:14)", {ecmaVersion: 6}) testFail("let let", "let is disallowed as a lexically bound name (1:4)", {ecmaVersion: 6}) @@ -13417,6 +13416,8 @@ testFail("let [let] = [];", "let is disallowed as a lexically bound name (1:5)", testFail("const [let] = [];", "let is disallowed as a lexically bound name (1:7)", {ecmaVersion: 6}) +testFail("'use strict'; let + 1", "The keyword 'let' is reserved (1:14)", {ecmaVersion: 6}) + testFail("'use strict'; let let", "The keyword 'let' is reserved (1:18)", {ecmaVersion: 6}) testFail("'use strict'; const let", "The keyword 'let' is reserved (1:20)", {ecmaVersion: 6})