Mirror: The magical sticky regex-based parser generator 🧙

Add test for self-referential case

+38 -10
+35 -7
src/babel/__snapshots__/plugin.test.js.snap
··· 130 };" 131 `; 132 133 - exports[`works with self-referential thuns 1`] = ` 134 "import { match, tag, _exec, _pattern } from 'reghex'; 135 - const inner = m('inner')\` 136 - \${() => node} 137 - \`; 138 - const node = m('node')\` 139 - \${inner} 140 - \`;" 141 `; 142 143 exports[`works with standard features 1`] = `
··· 130 };" 131 `; 132 133 + exports[`works with self-referential thunks 1`] = ` 134 "import { match, tag, _exec, _pattern } from 'reghex'; 135 + 136 + var _inner_expression = _pattern(() => node); 137 + 138 + const inner = function (state) { 139 + var index_1 = state.index; 140 + var node = []; 141 + var match; 142 + 143 + if (match = _exec(state, _inner_expression)) { 144 + node.push(match); 145 + } else { 146 + state.index = index_1; 147 + return; 148 + } 149 + 150 + node.tag = 'inner'; 151 + return node; 152 + }; 153 + 154 + const node = function (state) { 155 + var index_1 = state.index; 156 + var node = []; 157 + var match; 158 + 159 + if (match = inner(state)) { 160 + node.push(match); 161 + } else { 162 + state.index = index_1; 163 + return; 164 + } 165 + 166 + node.tag = 'node'; 167 + return node; 168 + };" 169 `; 170 171 exports[`works with standard features 1`] = `
+3 -3
src/babel/plugin.test.js
··· 54 ).toMatchSnapshot(); 55 }); 56 57 - it('works with self-referential thuns', () => { 58 const code = ` 59 import { match, tag } from 'reghex'; 60 61 - const inner = m('inner')\` 62 \${() => node} 63 \`; 64 65 - const node = m('node')\` 66 \${inner} 67 \`; 68 `;
··· 54 ).toMatchSnapshot(); 55 }); 56 57 + it('works with self-referential thunks', () => { 58 const code = ` 59 import { match, tag } from 'reghex'; 60 61 + const inner = match('inner')\` 62 \${() => node} 63 \`; 64 65 + const node = match('node')\` 66 \${inner} 67 \`; 68 `;