Mirror: The magical sticky regex-based parser generator 🧙

Update tests and codegen

+52 -1
+2 -1
src/codegen.js
··· 26 26 `; 27 27 28 28 const astExpression = (ast, depth, opts) => { 29 + const capture = !!opts.capture && !ast.capture; 29 30 const restoreLength = 30 31 (opts.length && opts.abort && js`${_node}.length = ln${opts.length};`) || 31 32 ''; 32 33 const expression = `${ast.expression.id}(${_state})`; 33 34 return js` 34 35 if ((${_match} = ${ast.expression.id}(${_state})) != null) { 35 - ${opts.capture ? js`${_node}.push(${_match})` : ''} 36 + ${capture ? js`${_node}.push(${_match})` : ''} 36 37 } else { 37 38 ${opts.onAbort} 38 39 ${restoreIndex(opts.index)}
+50
src/core.test.js
··· 358 358 ); 359 359 }); 360 360 361 + describe('non-capturing shorthand', () => { 362 + const node = match('node')`${/1/} :${/2/}+`; 363 + it.each` 364 + input | result | lastIndex 365 + ${'12'} | ${['1']} | ${2} 366 + ${'122'} | ${['1']} | ${3} 367 + ${'13'} | ${undefined} | ${0} 368 + ${'1'} | ${undefined} | ${0} 369 + ${'_'} | ${undefined} | ${0} 370 + `( 371 + 'should return $result when $input is passed', 372 + ({ input, result, lastIndex }) => { 373 + expectToParse(node, input, result, lastIndex); 374 + } 375 + ); 376 + }); 377 + 361 378 describe('non-capturing group with plus matcher, then required matcher', () => { 362 379 const node = match('node')`(?: ${/1/}+) ${/2/}`; 363 380 it.each` ··· 445 462 ); 446 463 }); 447 464 465 + describe('positive lookahead shorthand', () => { 466 + const node = match('node')`=${/1/} ${/\d/}`; 467 + it.each` 468 + input | result | lastIndex 469 + ${'1'} | ${['1']} | ${1} 470 + ${'13'} | ${['1']} | ${1} 471 + ${'2'} | ${undefined} | ${0} 472 + ${'_'} | ${undefined} | ${0} 473 + `( 474 + 'should return $result when $input is passed', 475 + ({ input, result, lastIndex }) => { 476 + expectToParse(node, input, result, lastIndex); 477 + } 478 + ); 479 + }); 480 + 448 481 describe('positive lookahead group with plus matcher', () => { 449 482 const node = match('node')`(?= ${/1/}+) ${/\d/}`; 450 483 it.each` ··· 484 517 485 518 describe('negative lookahead group', () => { 486 519 const node = match('node')`(?! ${/1/}) ${/\d/}`; 520 + it.each` 521 + input | result | lastIndex 522 + ${'2'} | ${['2']} | ${1} 523 + ${'23'} | ${['2']} | ${1} 524 + ${'1'} | ${undefined} | ${0} 525 + ${'1'} | ${undefined} | ${0} 526 + ${'_'} | ${undefined} | ${0} 527 + `( 528 + 'should return $result when $input is passed', 529 + ({ input, result, lastIndex }) => { 530 + expectToParse(node, input, result, lastIndex); 531 + } 532 + ); 533 + }); 534 + 535 + describe('negative lookahead shorthand', () => { 536 + const node = match('node')`!${/1/} ${/\d/}`; 487 537 it.each` 488 538 input | result | lastIndex 489 539 ${'2'} | ${['2']} | ${1}