perf: remove double check for keywords in readWord

Instead of calling isKeyword we simple check directly if the keyword token is available
This commit is contained in:
Daniel Tschinder
2019-01-17 01:46:22 -08:00
parent b66d921053
commit 4e5e319d5b
4 changed files with 70 additions and 84 deletions

View File

@@ -3,11 +3,7 @@
import type { Options } from "../options";
import type { Position } from "../util/location";
import * as charCodes from "charcodes";
import {
isIdentifierStart,
isIdentifierChar,
isKeyword,
} from "../util/identifier";
import { isIdentifierStart, isIdentifierChar } from "../util/identifier";
import { types as tt, keywords as keywordTypes, type TokenType } from "./types";
import { type TokContext, types as ct } from "./context";
import LocationParser from "../parser/location";
@@ -157,12 +153,6 @@ export default class Tokenizer extends LocationParser {
// TODO
isKeyword(word: string): boolean {
return isKeyword(word);
}
// TODO
lookahead(): State {
const old = this.state;
this.state = old.clone(true);
@@ -1336,14 +1326,10 @@ export default class Tokenizer extends LocationParser {
readWord(): void {
const word = this.readWord1();
let type = tt.name;
const type = keywordTypes[word] || tt.name;
if (this.isKeyword(word)) {
if (this.state.containsEsc) {
this.raise(this.state.pos, `Escape sequence in keyword ${word}`);
}
type = keywordTypes[word];
if (type.keyword && this.state.containsEsc) {
this.raise(this.state.pos, `Escape sequence in keyword ${word}`);
}
// Allow @@iterator and @@asyncIterator as a identifier only inside type