Unify reserved word checking and update error messages (#9402)
* Unify reserved word checking and update error messages * Fix test
This commit is contained in:
@@ -4,27 +4,52 @@
|
||||
|
||||
import * as charCodes from "charcodes";
|
||||
|
||||
export const isES2015ReservedWord = (word: string): boolean => {
|
||||
return word === "enum" || word === "await";
|
||||
const reservedWords = {
|
||||
strict: [
|
||||
"implements",
|
||||
"interface",
|
||||
"let",
|
||||
"package",
|
||||
"private",
|
||||
"protected",
|
||||
"public",
|
||||
"static",
|
||||
"yield",
|
||||
],
|
||||
strictBind: ["eval", "arguments"],
|
||||
};
|
||||
|
||||
const reservedWordsStrict = new Set([
|
||||
"implements",
|
||||
"interface",
|
||||
"let",
|
||||
"package",
|
||||
"private",
|
||||
"protected",
|
||||
"public",
|
||||
"static",
|
||||
"yield",
|
||||
]);
|
||||
export function isStrictReservedWord(word: string): boolean {
|
||||
return reservedWordsStrict.has(word);
|
||||
const reservedWordsStrictSet = new Set(reservedWords.strict);
|
||||
const reservedWordsStrictBindSet = new Set(
|
||||
reservedWords.strict.concat(reservedWords.strictBind),
|
||||
);
|
||||
|
||||
/**
|
||||
* Checks if word is a reserved word in non-strict mode
|
||||
*/
|
||||
export const isReservedWord = (word: string, inModule: boolean): boolean => {
|
||||
return (inModule && word === "await") || word === "enum";
|
||||
};
|
||||
|
||||
/**
|
||||
* Checks if word is a reserved word in non-binding strict mode
|
||||
*
|
||||
* Includes non-strict reserved words
|
||||
*/
|
||||
export function isStrictReservedWord(word: string, inModule: boolean): boolean {
|
||||
return isReservedWord(word, inModule) || reservedWordsStrictSet.has(word);
|
||||
}
|
||||
|
||||
export function isStrictBindReservedWord(word: string): boolean {
|
||||
return word === "eval" || word === "arguments";
|
||||
/**
|
||||
* Checks if word is a reserved word in binding strict mode
|
||||
*
|
||||
* Includes non-strict reserved words and non-binding strict reserved words
|
||||
*/
|
||||
export function isStrictBindReservedWord(
|
||||
word: string,
|
||||
inModule: boolean,
|
||||
): boolean {
|
||||
return isReservedWord(word, inModule) || reservedWordsStrictBindSet.has(word);
|
||||
}
|
||||
|
||||
const keywords = new Set([
|
||||
|
||||
Reference in New Issue
Block a user