Disallow const let or let let

This commit is contained in:
Daniel Tschinder
2019-01-21 23:38:27 -08:00
parent 178f2d7949
commit 8071dca9ad
4 changed files with 15 additions and 10 deletions

View File

@@ -907,7 +907,7 @@ export default class StatementParser extends ExpressionParser {
node.kind = kind;
for (;;) {
const decl = this.startNode();
this.parseVarHead(decl);
this.parseVarId(decl, kind);
if (this.eat(tt.eq)) {
decl.init = this.parseMaybeAssign(isFor);
} else {
@@ -937,7 +937,10 @@ export default class StatementParser extends ExpressionParser {
return node;
}
parseVarHead(decl: N.VariableDeclarator): void {
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, true, undefined, "variable declaration");
}