Files
babel/packages/babel-parser/src/util/identifier.js
Huáng Jùnliàng cbad50ac1d Faster checkReservedWord (#13386)
* perf: faster parser scope check

* perf: early return for identifier length > 10

* perf: early return for normal identifier names

* chore: add benchmark

* Update packages/babel-parser/src/parser/expression.js
2021-06-01 08:42:23 -04:00

87 lines
1.5 KiB
JavaScript

/* eslint max-len: 0 */
// @flow
import * as charCodes from "charcodes";
export {
isIdentifierStart,
isIdentifierChar,
isReservedWord,
isStrictBindOnlyReservedWord,
isStrictBindReservedWord,
isStrictReservedWord,
isKeyword,
} from "@babel/helper-validator-identifier";
export const keywordRelationalOperator = /^in(stanceof)?$/;
// Test whether a current state character code and next character code is @
export function isIteratorStart(current: number, next: number): boolean {
return current === charCodes.atSign && next === charCodes.atSign;
}
// This is the comprehensive set of JavaScript reserved words
// If a word is in this set, it could be a reserved word,
// depending on sourceType/strictMode/binding info. In other words
// if a word is not in this set, it is not a reserved word under
// any circumstance.
const reservedWordLikeSet = new Set([
"break",
"case",
"catch",
"continue",
"debugger",
"default",
"do",
"else",
"finally",
"for",
"function",
"if",
"return",
"switch",
"throw",
"try",
"var",
"const",
"while",
"with",
"new",
"this",
"super",
"class",
"extends",
"export",
"import",
"null",
"true",
"false",
"in",
"instanceof",
"typeof",
"void",
"delete",
// strict
"implements",
"interface",
"let",
"package",
"private",
"protected",
"public",
"static",
"yield",
// strictBind
"eval",
"arguments",
// reservedWorkLike
"enum",
"await",
]);
export function canBeReservedWord(word: string): boolean {
return reservedWordLikeSet.has(word);
}