From e4b8cfc768cd6b1457f61ea6991630630a4ca3dc Mon Sep 17 00:00:00 2001 From: Daniel Tschinder Date: Tue, 15 Jan 2019 12:58:59 -0800 Subject: [PATCH] perf: use Set instead of string indexOf --- packages/babel-parser/src/tokenizer/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/babel-parser/src/tokenizer/index.js b/packages/babel-parser/src/tokenizer/index.js index 3e72b8a837..b940da2c97 100644 --- a/packages/babel-parser/src/tokenizer/index.js +++ b/packages/babel-parser/src/tokenizer/index.js @@ -20,7 +20,7 @@ import { } from "../util/whitespace"; import State from "./state"; -const VALID_REGEX_FLAGS = "gmsiyu"; +const VALID_REGEX_FLAGS = new Set(["g", "m", "s", "i", "y", "u"]); // The following character codes are forbidden from being // an immediate sibling of NumericLiteralSeparator _ @@ -874,7 +874,7 @@ export default class Tokenizer extends LocationParser { const char = this.state.input[this.state.pos]; const charCode = this.state.input.codePointAt(this.state.pos); - if (VALID_REGEX_FLAGS.indexOf(char) > -1) { + if (VALID_REGEX_FLAGS.has(char)) { if (mods.indexOf(char) > -1) { this.raise(this.state.pos + 1, "Duplicate regular expression flag"); }