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

Configure Feed

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

Add basic test case for interpolations

+18 -3
+1 -2
src/codegen.js
··· 20 20 21 21 const assignIndex = (depth) => 22 22 js`var y${depth} = ${_state}.y` + 23 - (_interpolations ? js`, var x${depth} = ${_state}.x;` : ';'); 23 + (_interpolations ? js`, x${depth} = ${_state}.x;` : ';'); 24 24 25 25 const restoreIndex = (depth) => 26 26 js`${_state}.y = y${depth}` + ··· 52 52 opts = copy(opts); 53 53 opts.capture = capture; 54 54 55 - let group = ''; 56 55 if (!opts.length && capture) { 57 56 opts.length = depth; 58 57 return js`
+17 -1
src/core.test.js
··· 1 - import { match } from './core'; 1 + import { parse, match, interpolation } from './core'; 2 2 3 3 const expectToParse = (node, input, result, lastIndex = 0) => { 4 4 const state = { quasis: [input], expressions: [], x: 0, y: 0 }; ··· 552 552 } 553 553 ); 554 554 }); 555 + 556 + describe('interpolation parsing', () => { 557 + const node = match('node')` 558 + ${/1/} 559 + ${interpolation} 560 + ${/3/} 561 + `; 562 + 563 + const expected = ['1', 2, '3']; 564 + expected.tag = 'node'; 565 + 566 + expect(parse(node)`1${2}3`).toEqual(expected); 567 + expect(parse(node)`13`).toBe(undefined); 568 + expect(parse(node)`13${2}`).toBe(undefined); 569 + expect(parse(node)`${2}13`).toBe(undefined); 570 + });