Skip to content

Commit

Permalink
perf: use Set instead of string indexOf
Browse files Browse the repository at this point in the history
  • Loading branch information
danez committed Jan 18, 2019
1 parent a7757ec commit e4b8cfc
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/babel-parser/src/tokenizer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 _
Expand Down Expand Up @@ -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");
}
Expand Down

0 comments on commit e4b8cfc

Please sign in to comment.