Mirror: The magical sticky regex-based parser generator 🧙

Merge pull request #12 from kitten/fix/zero-length-matches

breaking: Only consider undefined/null failed matches

authored by kitten.sh and committed by GitHub 4baff28e 72c3cfff

Changed files
+8 -7
src
+4 -4
src/babel/__snapshots__/plugin.test.js.snap
··· 13 13 var node = []; 14 14 var x; 15 15 16 - if (x = __private.exec(state, _re_expression)) { 16 + if ((x = __private.exec(state, _re_expression)) != null) { 17 17 node.push(x); 18 18 } else { 19 19 state.y = y1; ··· 21 21 return; 22 22 } 23 23 24 - if (x = __private.exec(state, str)) { 24 + if ((x = __private.exec(state, str)) != null) { 25 25 node.push(x); 26 26 } else { 27 27 state.y = y1; ··· 39 39 var node = []; 40 40 var x; 41 41 42 - if (x = __private.exec(state, _re_expression)) { 42 + if ((x = __private.exec(state, _re_expression)) != null) { 43 43 node.push(x); 44 44 } else { 45 45 state.y = y1; ··· 47 47 return; 48 48 } 49 49 50 - if (x = __private.exec(state, \\"2\\")) { 50 + if ((x = __private.exec(state, \\"2\\")) != null) { 51 51 node.push(x); 52 52 } else { 53 53 state.y = y1;
+1 -1
src/codegen.js
··· 36 36 : `${_private}.exec(${_state}, ${ast.expression.id})`; 37 37 38 38 return js` 39 - if (${_match} = ${expression}) { 39 + if ((${_match} = ${expression}) != null) { 40 40 ${opts.capture ? js`${_node}.push(${_match})` : ''} 41 41 } else { 42 42 ${opts.onAbort}
+2 -1
src/core.js
··· 38 38 if (pattern.test(input)) 39 39 match = input.slice(state.y, pattern.lastIndex); 40 40 } else { 41 - match = pattern.exec(input)[0] || match; 41 + const x = pattern.exec(input); 42 + match = x[1] == null ? x[0] : match; 42 43 } 43 44 44 45 state.y = pattern.lastIndex;
+1 -1
src/core.test.js
··· 556 556 describe('interpolation parsing', () => { 557 557 const node = match('node')` 558 558 ${/1/} 559 - ${interpolation((x) => x > 1 && x)} 559 + ${interpolation((x) => (x > 1 ? x : null))} 560 560 ${/3/} 561 561 `; 562 562