Disallow "let" as name at lexical bindings (#10099)

* Disallow "let" as name at lexical bindings

* Simplify

* Clean up
This commit is contained in:
Pig Fang 2019-06-19 05:17:00 +08:00 committed by Nicolò Ribaudo
parent 505b2cc18d
commit 11fa2461ce
14 changed files with 31 additions and 4 deletions

View File

@ -16,7 +16,7 @@ import type {
import type { Pos, Position } from "../util/location";
import { isStrictBindReservedWord } from "../util/identifier";
import { NodeUtils } from "./node";
import { type BindingTypes, BIND_NONE } from "../util/scopeflags";
import { type BindingTypes, BIND_NONE, BIND_LEXICAL } from "../util/scopeflags";
export default class LValParser extends NodeUtils {
// Forward-declaration: defined in expression.js
@ -363,6 +363,12 @@ export default class LValParser extends NodeUtils {
checkClashes[key] = true;
}
}
if (bindingType === BIND_LEXICAL && expr.name === "let") {
this.raise(
expr.start,
"'let' is not allowed to be used as a name in 'let' or 'const' declarations.",
);
}
if (!(bindingType & BIND_NONE)) {
this.scope.declareName(expr.name, bindingType, expr.start);
}

View File

@ -1010,9 +1010,6 @@ export default class StatementParser extends ExpressionParser {
}
parseVarId(decl: N.VariableDeclarator, kind: "var" | "let" | "const"): void {
if ((kind === "const" || kind === "let") && this.isContextual("let")) {
this.unexpected(null, "let is disallowed as a lexically bound name");
}
decl.id = this.parseBindingAtom();
this.checkLVal(
decl.id,

View File

@ -0,0 +1 @@
let { let } = {};

View File

@ -0,0 +1,3 @@
{
"throws": "'let' is not allowed to be used as a name in 'let' or 'const' declarations. (1:6)"
}

View File

@ -0,0 +1 @@
const { let } = {};

View File

@ -0,0 +1,3 @@
{
"throws": "'let' is not allowed to be used as a name in 'let' or 'const' declarations. (1:8)"
}

View File

@ -0,0 +1 @@
let [let] = [];

View File

@ -0,0 +1,3 @@
{
"throws": "'let' is not allowed to be used as a name in 'let' or 'const' declarations. (1:5)"
}

View File

@ -0,0 +1 @@
const [let] = [];

View File

@ -0,0 +1,3 @@
{
"throws": "'let' is not allowed to be used as a name in 'let' or 'const' declarations. (1:7)"
}

View File

@ -0,0 +1 @@
let let

View File

@ -0,0 +1,3 @@
{
"throws": "'let' is not allowed to be used as a name in 'let' or 'const' declarations. (1:4)"
}

View File

@ -0,0 +1 @@
const let = ''

View File

@ -0,0 +1,3 @@
{
"throws": "'let' is not allowed to be used as a name in 'let' or 'const' declarations. (1:6)"
}