Mirror: The magical sticky regex-based parser generator 🧙

Use RegExp#test instead of #exec

+10 -5
+10 -5
src/core.js
··· 24 24 let match; 25 25 if (isStickySupported) { 26 26 pattern.lastIndex = state.index; 27 - match = pattern.exec(state.input); 28 - state.index = pattern.lastIndex; 27 + if (pattern.test(state.input)) { 28 + match = state.input.slice(state.index, pattern.lastIndex); 29 + state.index = pattern.lastIndex; 30 + } 29 31 } else { 30 32 pattern.lastIndex = 0; 31 - match = pattern.exec(state.input.slice(state.input)); 32 - state.index += pattern.lastIndex; 33 + if (pattern.test(state.input.slice(state.index))) { 34 + const lastIndex = state.index + pattern.lastIndex; 35 + match = state.input.slice(state.index, lastIndex); 36 + state.index = lastIndex; 37 + } 33 38 } 34 39 35 - return match && match[0]; 40 + return match; 36 41 }; 37 42 38 43 export const tag = (array, tag) => {