Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disallow "let" as name at lexical bindings #10099

Merged
merged 3 commits into from Jun 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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(
g-plane marked this conversation as resolved.
Show resolved Hide resolved
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)"
}