perf: Use === or Set.has instead of array.indexOf for keyword checks

This commit is contained in:
Daniel Tschinder
2019-01-17 00:46:43 -08:00
parent f12905b531
commit b66d921053
4 changed files with 89 additions and 24 deletions

View File

@@ -21,7 +21,10 @@
import { types as tt, type TokenType } from "../tokenizer/types";
import * as N from "../types";
import LValParser from "./lval";
import { reservedWords } from "../util/identifier";
import {
isStrictReservedWord,
isStrictBindReservedWord,
} from "../util/identifier";
import type { Pos, Position } from "../util/location";
import * as charCodes from "charcodes";
@@ -1997,8 +2000,8 @@ export default class ExpressionParser extends LValParser {
): void {
if (
this.state.strict &&
(reservedWords.strict(word) ||
(isBinding && reservedWords.strictBind(word)))
(isStrictReservedWord(word) ||
(isBinding && isStrictBindReservedWord(word)))
) {
this.raise(startLoc, word + " is a reserved word in strict mode");
}