Mirror: The magical sticky regex-based parser generator 🧙
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Replace sticky polyfill with shorter variant

See: https://github.com/slevithan/xregexp/blob/760ab95bcef8948f313df55e9483981200b70e2d/src/xregexp.js#L844-L865

+9 -12
+9 -12
src/core.js
··· 8 8 const source = typeof input !== 'string' ? input.source : input; 9 9 return isStickySupported 10 10 ? new RegExp(source, 'y') 11 - : new RegExp(`^(?:${source})`, 'g'); 11 + : new RegExp(source + '|()', 'g'); 12 12 }; 13 13 14 14 export const _exec = (state, pattern) => { ··· 17 17 if (typeof pattern === 'function') { 18 18 if (!pattern.length) pattern = pattern(); 19 19 return pattern(state); 20 - } else if (isStickySupported) { 21 - pattern.lastIndex = state.index; 22 - if (pattern.test(state.input)) { 20 + } 21 + 22 + pattern.lastIndex = state.index; 23 + 24 + if (isStickySupported) { 25 + if (pattern.test(state.input)) 23 26 match = state.input.slice(state.index, pattern.lastIndex); 24 - state.index = pattern.lastIndex; 25 - } 26 27 } else { 27 - pattern.lastIndex = 0; 28 - if (pattern.test(state.input.slice(state.index))) { 29 - const lastIndex = state.index + pattern.lastIndex; 30 - match = state.input.slice(state.index, lastIndex); 31 - state.index = lastIndex; 32 - } 28 + match = pattern.exec(state.input)[0] || match; 33 29 } 34 30 31 + state.index = pattern.lastIndex; 35 32 return match; 36 33 }; 37 34