Unify reserved word checking and update error messages (#9402)

* Unify reserved word checking and update error messages

* Fix test
This commit is contained in:
Daniel Tschinder
2019-01-31 19:02:32 -08:00
committed by GitHub
parent 7e9029e337
commit 9eb010da50
172 changed files with 347 additions and 331 deletions

View File

@@ -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([