Disallow "let" as name at lexical bindings (#10099)
* Disallow "let" as name at lexical bindings * Simplify * Clean up
This commit is contained in:
parent
505b2cc18d
commit
11fa2461ce
@ -16,7 +16,7 @@ import type {
|
|||||||
import type { Pos, Position } from "../util/location";
|
import type { Pos, Position } from "../util/location";
|
||||||
import { isStrictBindReservedWord } from "../util/identifier";
|
import { isStrictBindReservedWord } from "../util/identifier";
|
||||||
import { NodeUtils } from "./node";
|
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 {
|
export default class LValParser extends NodeUtils {
|
||||||
// Forward-declaration: defined in expression.js
|
// Forward-declaration: defined in expression.js
|
||||||
@ -363,6 +363,12 @@ export default class LValParser extends NodeUtils {
|
|||||||
checkClashes[key] = true;
|
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)) {
|
if (!(bindingType & BIND_NONE)) {
|
||||||
this.scope.declareName(expr.name, bindingType, expr.start);
|
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 {
|
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();
|
decl.id = this.parseBindingAtom();
|
||||||
this.checkLVal(
|
this.checkLVal(
|
||||||
decl.id,
|
decl.id,
|
||||||
|
|||||||
1
packages/babel-parser/test/fixtures/es2015/let/let-at-binding-list-fail-1/input.js
vendored
Normal file
1
packages/babel-parser/test/fixtures/es2015/let/let-at-binding-list-fail-1/input.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
let { let } = {};
|
||||||
3
packages/babel-parser/test/fixtures/es2015/let/let-at-binding-list-fail-1/options.json
vendored
Normal file
3
packages/babel-parser/test/fixtures/es2015/let/let-at-binding-list-fail-1/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"throws": "'let' is not allowed to be used as a name in 'let' or 'const' declarations. (1:6)"
|
||||||
|
}
|
||||||
1
packages/babel-parser/test/fixtures/es2015/let/let-at-binding-list-fail-2/input.js
vendored
Normal file
1
packages/babel-parser/test/fixtures/es2015/let/let-at-binding-list-fail-2/input.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
const { let } = {};
|
||||||
3
packages/babel-parser/test/fixtures/es2015/let/let-at-binding-list-fail-2/options.json
vendored
Normal file
3
packages/babel-parser/test/fixtures/es2015/let/let-at-binding-list-fail-2/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"throws": "'let' is not allowed to be used as a name in 'let' or 'const' declarations. (1:8)"
|
||||||
|
}
|
||||||
1
packages/babel-parser/test/fixtures/es2015/let/let-at-binding-list-fail-3/input.js
vendored
Normal file
1
packages/babel-parser/test/fixtures/es2015/let/let-at-binding-list-fail-3/input.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
let [let] = [];
|
||||||
3
packages/babel-parser/test/fixtures/es2015/let/let-at-binding-list-fail-3/options.json
vendored
Normal file
3
packages/babel-parser/test/fixtures/es2015/let/let-at-binding-list-fail-3/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"throws": "'let' is not allowed to be used as a name in 'let' or 'const' declarations. (1:5)"
|
||||||
|
}
|
||||||
1
packages/babel-parser/test/fixtures/es2015/let/let-at-binding-list-fail-4/input.js
vendored
Normal file
1
packages/babel-parser/test/fixtures/es2015/let/let-at-binding-list-fail-4/input.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
const [let] = [];
|
||||||
3
packages/babel-parser/test/fixtures/es2015/let/let-at-binding-list-fail-4/options.json
vendored
Normal file
3
packages/babel-parser/test/fixtures/es2015/let/let-at-binding-list-fail-4/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"throws": "'let' is not allowed to be used as a name in 'let' or 'const' declarations. (1:7)"
|
||||||
|
}
|
||||||
1
packages/babel-parser/test/fixtures/es2015/let/let-at-binding-list-fail-5/input.js
vendored
Normal file
1
packages/babel-parser/test/fixtures/es2015/let/let-at-binding-list-fail-5/input.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
let let
|
||||||
3
packages/babel-parser/test/fixtures/es2015/let/let-at-binding-list-fail-5/options.json
vendored
Normal file
3
packages/babel-parser/test/fixtures/es2015/let/let-at-binding-list-fail-5/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"throws": "'let' is not allowed to be used as a name in 'let' or 'const' declarations. (1:4)"
|
||||||
|
}
|
||||||
1
packages/babel-parser/test/fixtures/es2015/let/let-at-binding-list-fail-6/input.js
vendored
Normal file
1
packages/babel-parser/test/fixtures/es2015/let/let-at-binding-list-fail-6/input.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
const let = ''
|
||||||
3
packages/babel-parser/test/fixtures/es2015/let/let-at-binding-list-fail-6/options.json
vendored
Normal file
3
packages/babel-parser/test/fixtures/es2015/let/let-at-binding-list-fail-6/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"throws": "'let' is not allowed to be used as a name in 'let' or 'const' declarations. (1:6)"
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user