Debian Codegraph @

packages/babel-helper-validator-identifier/src/keyword.ts

raw symbols SCIP
1 const reservedWords = {
2 keyword: [
3 "break",
4 "case",
5 "catch",
6 "continue",
7 "debugger",
8 "default",
9 "do",
10 "else",
11 "finally",
12 "for",
13 "function",
14 "if",
15 "return",
16 "switch",
17 "throw",
18 "try",
19 "var",
20 "const",
21 "while",
22 "with",
23 "new",
24 "this",
25 "super",
26 "class",
27 "extends",
28 "export",
29 "import",
30 "null",
31 "true",
32 "false",
33 "in",
34 "instanceof",
35 "typeof",
36 "void",
37 "delete",
38 ],
39 strict: [
40 "implements",
41 "interface",
42 "let",
43 "package",
44 "private",
45 "protected",
46 "public",
47 "static",
48 "yield",
49 ],
50 strictBind: ["eval", "arguments"],
51 };
52 const keywords = new Set(reservedWords.keyword);
53 const reservedWordsStrictSet = new Set(reservedWords.strict);
54 const reservedWordsStrictBindSet = new Set(reservedWords.strictBind);
55
56 /**
57 * Checks if word is a reserved word in non-strict mode
58 */
59 export function isReservedWord(word: string, inModule: boolean): boolean {
60 return (inModule && word === "await") || word === "enum";
61 }
62
63 /**
64 * Checks if word is a reserved word in non-binding strict mode
65 *
66 * Includes non-strict reserved words
67 */
68 export function isStrictReservedWord(word: string, inModule: boolean): boolean {
69 return isReservedWord(word, inModule) || reservedWordsStrictSet.has(word);
70 }
71
72 /**
73 * Checks if word is a reserved word in binding strict mode, but it is allowed as
74 * a normal identifier.
75 */
76 export function isStrictBindOnlyReservedWord(word: string): boolean {
77 return reservedWordsStrictBindSet.has(word);
78 }
79
80 /**
81 * Checks if word is a reserved word in binding strict mode
82 *
83 * Includes non-strict reserved words and non-binding strict reserved words
84 */
85 export function isStrictBindReservedWord(
86 word: string,
87 inModule: boolean,
88 ): boolean {
89 return (
90 isStrictReservedWord(word, inModule) || isStrictBindOnlyReservedWord(word)
91 );
92 }
93
94 export function isKeyword(word: string): boolean {
95 return keywords.has(word);
96 }