refactor: move @babel/helper-validator-identifier to ts (#12409)
* refactor: rename helper-validator-identifier to ts * fix flow errors
This commit is contained in:
parent
a46cd643ab
commit
fc82169b4e
@ -116,3 +116,20 @@ declare module "@babel/code-frame" {
|
|||||||
opts?: Options
|
opts?: Options
|
||||||
): string;
|
): string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
declare module "@babel/helper-validator-identifier" {
|
||||||
|
declare function isReservedWord(word: string, inModule: boolean): boolean;
|
||||||
|
declare function isStrictReservedWord(
|
||||||
|
word: string,
|
||||||
|
inModule: boolean
|
||||||
|
): boolean;
|
||||||
|
declare function isStrictBindOnlyReservedWord(word: string): boolean;
|
||||||
|
declare function isStrictBindReservedWord(
|
||||||
|
word: string,
|
||||||
|
inModule: boolean
|
||||||
|
): boolean;
|
||||||
|
declare function isKeyword(word: string): boolean;
|
||||||
|
declare function isIdentifierStart(code: number): boolean;
|
||||||
|
declare function isIdentifierChar(code: number): boolean;
|
||||||
|
declare function isIdentifierName(name: string): boolean;
|
||||||
|
}
|
||||||
|
|||||||
@ -1,5 +1,3 @@
|
|||||||
// @flow
|
|
||||||
|
|
||||||
import * as charCodes from "charcodes";
|
import * as charCodes from "charcodes";
|
||||||
|
|
||||||
// ## Character categories
|
// ## Character categories
|
||||||
@ -38,7 +36,7 @@ const astralIdentifierCodes = [509,0,227,0,150,4,294,9,1368,2,2,1,6,3,41,2,5,0,1
|
|||||||
// This has a complexity linear to the value of the code. The
|
// This has a complexity linear to the value of the code. The
|
||||||
// assumption is that looking up astral identifier characters is
|
// assumption is that looking up astral identifier characters is
|
||||||
// rare.
|
// rare.
|
||||||
function isInAstralSet(code: number, set: $ReadOnlyArray<number>): boolean {
|
function isInAstralSet(code: number, set: readonly number[]): boolean {
|
||||||
let pos = 0x10000;
|
let pos = 0x10000;
|
||||||
for (let i = 0, length = set.length; i < length; i += 2) {
|
for (let i = 0, length = set.length; i < length; i += 2) {
|
||||||
pos += set[i];
|
pos += set[i];
|
||||||
@ -1,5 +1,3 @@
|
|||||||
// @flow
|
|
||||||
|
|
||||||
const reservedWords = {
|
const reservedWords = {
|
||||||
keyword: [
|
keyword: [
|
||||||
"break",
|
"break",
|
||||||
@ -522,7 +522,7 @@ defineType("Identifier", {
|
|||||||
// Ideally we should call isStrictReservedWord if this node is a descendant
|
// Ideally we should call isStrictReservedWord if this node is a descendant
|
||||||
// of a block in strict mode. Also, we should pass the inModule option so
|
// of a block in strict mode. Also, we should pass the inModule option so
|
||||||
// we can disable "await" in module.
|
// we can disable "await" in module.
|
||||||
(isKeyword(node.name) || isReservedWord(node.name)) &&
|
(isKeyword(node.name) || isReservedWord(node.name, false)) &&
|
||||||
// Even if "this" is a keyword, we are using the Identifier
|
// Even if "this" is a keyword, we are using the Identifier
|
||||||
// node to represent it.
|
// node to represent it.
|
||||||
node.name !== "this"
|
node.name !== "this"
|
||||||
|
|||||||
@ -15,10 +15,8 @@ export default function isValidIdentifier(
|
|||||||
if (typeof name !== "string") return false;
|
if (typeof name !== "string") return false;
|
||||||
|
|
||||||
if (reserved) {
|
if (reserved) {
|
||||||
if (isKeyword(name) || isStrictReservedWord(name)) {
|
// "await" is invalid in module, valid in script; better be safe (see #4952)
|
||||||
return false;
|
if (isKeyword(name) || isStrictReservedWord(name, true)) {
|
||||||
} else if (name === "await") {
|
|
||||||
// invalid in module, valid in script; better be safe (see #4952)
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user