Skip to content

Commit

Permalink
Disallow "let" as name at lexical bindings (#10099)
Browse files Browse the repository at this point in the history
* Disallow "let" as name at lexical bindings

* Simplify

* Clean up
  • Loading branch information
g-plane authored and nicolo-ribaudo committed Jun 18, 2019
1 parent 505b2cc commit 11fa246
Show file tree
Hide file tree
Showing 14 changed files with 31 additions and 4 deletions.
8 changes: 7 additions & 1 deletion packages/babel-parser/src/parser/lval.js
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down
3 changes: 0 additions & 3 deletions packages/babel-parser/src/parser/statement.js
Expand Up @@ -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,
Expand Down
@@ -0,0 +1 @@
let { let } = {};
@@ -0,0 +1,3 @@
{
"throws": "'let' is not allowed to be used as a name in 'let' or 'const' declarations. (1:6)"
}
@@ -0,0 +1 @@
const { let } = {};
@@ -0,0 +1,3 @@
{
"throws": "'let' is not allowed to be used as a name in 'let' or 'const' declarations. (1:8)"
}
@@ -0,0 +1 @@
let [let] = [];
@@ -0,0 +1,3 @@
{
"throws": "'let' is not allowed to be used as a name in 'let' or 'const' declarations. (1:5)"
}
@@ -0,0 +1 @@
const [let] = [];
@@ -0,0 +1,3 @@
{
"throws": "'let' is not allowed to be used as a name in 'let' or 'const' declarations. (1:7)"
}
@@ -0,0 +1 @@
let let
@@ -0,0 +1,3 @@
{
"throws": "'let' is not allowed to be used as a name in 'let' or 'const' declarations. (1:4)"
}
@@ -0,0 +1 @@
const let = ''
@@ -0,0 +1,3 @@
{
"throws": "'let' is not allowed to be used as a name in 'let' or 'const' declarations. (1:6)"
}

0 comments on commit 11fa246

Please sign in to comment.