From bebc9b76e8995ce93879362d4b3ce678cfcd5fa0 Mon Sep 17 00:00:00 2001 From: Josh Goebel Date: Thu, 27 Feb 2020 18:06:15 -0500 Subject: [PATCH] simplify code --- src/lib/mode_compiler.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/lib/mode_compiler.js b/src/lib/mode_compiler.js index c8703f769c..7da04db10d 100644 --- a/src/lib/mode_compiler.js +++ b/src/lib/mode_compiler.js @@ -44,25 +44,22 @@ export function compileLanguage(language) { } compile() { + if (this.regexes.length === 0) { + // avoids the need to check length every time exec is called + this.exec = () => null; + } let terminators = this.regexes.map(el => el[1]); this.matcherRe = langRe(regex.join(terminators, '|'), true); this.lastIndex = 0; } exec(s) { - var matchData; - if (this.regexes.length === 0) return null; - this.matcherRe.lastIndex = this.lastIndex; let match = this.matcherRe.exec(s); if (!match) { return null; } - for(var i = 0; i i>0 && el!=undefined); + let matchData = this.matchIndexes[i]; return Object.assign(match, matchData); }