Mirror: The magical sticky regex-based parser generator 🧙

Add test for self-referential case

Changed files
+38 -10
src
babel
+35 -7
src/babel/__snapshots__/plugin.test.js.snap
···
};"
`;
-
exports[`works with self-referential thuns 1`] = `
+
exports[`works with self-referential thunks 1`] = `
"import { match, tag, _exec, _pattern } from 'reghex';
-
const inner = m('inner')\`
-
\${() => node}
-
\`;
-
const node = m('node')\`
-
\${inner}
-
\`;"
+
+
var _inner_expression = _pattern(() => node);
+
+
const inner = function (state) {
+
var index_1 = state.index;
+
var node = [];
+
var match;
+
+
if (match = _exec(state, _inner_expression)) {
+
node.push(match);
+
} else {
+
state.index = index_1;
+
return;
+
}
+
+
node.tag = 'inner';
+
return node;
+
};
+
+
const node = function (state) {
+
var index_1 = state.index;
+
var node = [];
+
var match;
+
+
if (match = inner(state)) {
+
node.push(match);
+
} else {
+
state.index = index_1;
+
return;
+
}
+
+
node.tag = 'node';
+
return node;
+
};"
`;
exports[`works with standard features 1`] = `
+3 -3
src/babel/plugin.test.js
···
).toMatchSnapshot();
});
-
it('works with self-referential thuns', () => {
+
it('works with self-referential thunks', () => {
const code = `
import { match, tag } from 'reghex';
-
const inner = m('inner')\`
+
const inner = match('inner')\`
\${() => node}
\`;
-
const node = m('node')\`
+
const node = match('node')\`
\${inner}
\`;
`;