Disallow "let" as name at lexical bindings (#10099)
* Disallow "let" as name at lexical bindings * Simplify * Clean up
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user