Mirror: The magical sticky regex-based parser generator 🧙

Compile away thunks returning matchers in Babel plugin

Changed files
+17 -3
src
babel
+1 -3
src/babel/__snapshots__/plugin.test.js.snap
··· 135 135 exports[`works with self-referential thunks 1`] = ` 136 136 "import { match, tag, _exec, _pattern } from 'reghex'; 137 137 138 - var _inner_expression = _pattern(() => node); 139 - 140 138 const inner = function (state) { 141 139 var index_1 = state.index; 142 140 var node = []; 143 141 var match; 144 142 145 - if (match = _exec(state, _inner_expression)) { 143 + if (match = node(state)) { 146 144 node.push(match); 147 145 } else { 148 146 state.index = index_1;
+16
src/babel/transform.js
··· 107 107 const hoistedExpressions = path.node.quasi.expressions.map( 108 108 (expression, i) => { 109 109 if ( 110 + t.isArrowFunctionExpression(expression) && 111 + t.isIdentifier(expression.body) 112 + ) { 113 + expression = expression.body; 114 + } else if ( 115 + (t.isFunctionExpression(expression) || 116 + t.isArrowFunctionExpression(expression)) && 117 + t.isBlockStatement(expression.body) && 118 + expression.body.body.length === 1 && 119 + t.isReturnStatement(expression.body.body[0]) && 120 + t.isIdentifier(expression.body.body[0].argument) 121 + ) { 122 + expression = expression.body.body[0].argument; 123 + } 124 + 125 + if ( 110 126 t.isIdentifier(expression) && 111 127 path.scope.hasBinding(expression.name) 112 128 ) {