Mirror: The magical sticky regex-based parser generator 🧙

Use RegExp#test instead of #exec

Changed files
+10 -5
src
+10 -5
src/core.js
···
let match;
if (isStickySupported) {
pattern.lastIndex = state.index;
-
match = pattern.exec(state.input);
-
state.index = pattern.lastIndex;
+
if (pattern.test(state.input)) {
+
match = state.input.slice(state.index, pattern.lastIndex);
+
state.index = pattern.lastIndex;
+
}
} else {
pattern.lastIndex = 0;
-
match = pattern.exec(state.input.slice(state.input));
-
state.index += pattern.lastIndex;
+
if (pattern.test(state.input.slice(state.index))) {
+
const lastIndex = state.index + pattern.lastIndex;
+
match = state.input.slice(state.index, lastIndex);
+
state.index = lastIndex;
+
}
}
-
return match && match[0];
+
return match;
};
export const tag = (array, tag) => {