Mirror: The magical sticky regex-based parser generator 🧙

Remove special string optimisation

This made little difference compard to the RegExp#test
optimisation.

+3 -17
+3 -1
src/babel/__snapshots__/plugin.test.js.snap
··· 40 40 exports[`works with local recursion 1`] = ` 41 41 "import { match as m, tag, _exec, _pattern } from 'reghex'; 42 42 43 + var _inner_expression = _pattern(/inner/); 44 + 43 45 const inner = function (state) { 44 46 var index_1 = state.index; 45 47 var node = []; 46 48 var match; 47 49 48 - if (match = _exec(state, \\"inner\\")) { 50 + if (match = _exec(state, _inner_expression)) { 49 51 node.push(match); 50 52 } else { 51 53 state.index = index_1;
-9
src/babel/transform.js
··· 115 115 const matchPath = binding.path.get('init'); 116 116 if (this.isMatch(matchPath)) return expression; 117 117 } 118 - } else if ( 119 - t.isRegExpLiteral(expression) && 120 - !regexPatternsRe.test(expression.pattern) 121 - ) { 122 - // NOTE: This is an optimisation path, where the pattern regex is inlined 123 - // and has determined to be "simple" enough to be turned into a string 124 - return t.stringLiteral( 125 - expression.pattern.replace(/\\./g, (x) => x[1]) 126 - ); 127 118 } 128 119 129 120 const id = path.scope.generateUidIdentifier(
-7
src/core.js
··· 17 17 if (typeof pattern === 'function') { 18 18 while (typeof pattern === 'function') pattern = pattern(state); 19 19 return pattern; 20 - } else if (typeof pattern === 'string') { 21 - const end = state.index + pattern.length; 22 - const sub = state.input.slice(state.index, end); 23 - if (sub === pattern) { 24 - state.index = end; 25 - match = sub; 26 - } 27 20 } else if (isStickySupported) { 28 21 pattern.lastIndex = state.index; 29 22 if (pattern.test(state.input)) {