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

Configure Feed

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

Fix index restoration for negative lookaheads

+33 -9
+17
src/babel/__tests__/suite.js
··· 536 536 ); 537 537 }); 538 538 539 + describe('longer negative lookahead group', () => { 540 + const node = match('node')`${/1/} (?! ${/2/} ${/3/}) ${/\d/} ${/\d/}`; 541 + it.each` 542 + input | result | lastIndex 543 + ${'145'} | ${['1', '4', '5']} | ${3} 544 + ${'124'} | ${['1', '2', '4']} | ${3} 545 + ${'123'} | ${undefined} | ${0} 546 + ${'2'} | ${undefined} | ${0} 547 + ${'_'} | ${undefined} | ${0} 548 + `( 549 + 'should return $result when $input is passed', 550 + ({ input, result, lastIndex }) => { 551 + expectToParse(node, input, result, lastIndex); 552 + } 553 + ); 554 + }); 555 + 539 556 describe('negative lookahead group with plus matcher', () => { 540 557 const node = match('node')`(?! ${/1/}+) ${/\d/}`; 541 558 it.each`
+16 -9
src/babel/generator.js
··· 201 201 } 202 202 203 203 if (ast.type === 'group' && ast.lookahead === 'negative') { 204 + childOpts.abort = new AbortNode(invertId); 205 + childOpts.restoreIndex = this.restoreIndex; 206 + this.restoreIndex = opts.restoreIndex; 204 207 this.blockId = invertId; 205 208 this.abort = opts.abort; 206 - childOpts.abort = new AbortNode(invertId); 207 209 } 208 210 209 211 if (quantifier && !quantifier.singular && quantifier.required) { ··· 270 272 statements = this.childNode.statements(); 271 273 } 272 274 273 - if (this.restoreIndex && this.assignIndex) { 274 - statements.unshift(this.assignIndex.statement()); 275 - statements.push(this.restoreIndex.statement()); 276 - } 277 - 278 - if (this.blockId) { 275 + if (this.blockId && this.assignIndex && this.restoreIndex) { 279 276 statements = [ 280 277 t.labeledStatement( 281 278 this.blockId, 282 - t.blockStatement([...statements, this.abort.statement()]) 279 + t.blockStatement( 280 + [ 281 + this.assignIndex.statement(), 282 + ...statements, 283 + this.restoreIndex.statement(), 284 + this.abort.statement(), 285 + ].filter(Boolean) 286 + ) 283 287 ), 284 - ]; 288 + ].filter(Boolean); 289 + } else if (this.assignIndex && this.restoreIndex) { 290 + statements.unshift(this.assignIndex.statement()); 291 + statements.push(this.restoreIndex.statement()); 285 292 } 286 293 287 294 return statements;