tangled
alpha
login
or
join now
kitten.sh
/
reghex
0
fork
atom
Mirror: The magical sticky regex-based parser generator 🧙
0
fork
atom
overview
issues
pulls
pipelines
Compile away thunks returning matchers in Babel plugin
kitten.sh
5 years ago
28b6152d
fa46d01a
+17
-3
2 changed files
expand all
collapse all
unified
split
src
babel
__snapshots__
plugin.test.js.snap
transform.js
+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
138
-
var _inner_expression = _pattern(() => node);
139
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
145
-
if (match = _exec(state, _inner_expression)) {
143
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
110
+
t.isArrowFunctionExpression(expression) &&
111
111
+
t.isIdentifier(expression.body)
112
112
+
) {
113
113
+
expression = expression.body;
114
114
+
} else if (
115
115
+
(t.isFunctionExpression(expression) ||
116
116
+
t.isArrowFunctionExpression(expression)) &&
117
117
+
t.isBlockStatement(expression.body) &&
118
118
+
expression.body.body.length === 1 &&
119
119
+
t.isReturnStatement(expression.body.body[0]) &&
120
120
+
t.isIdentifier(expression.body.body[0].argument)
121
121
+
) {
122
122
+
expression = expression.body.body[0].argument;
123
123
+
}
124
124
+
125
125
+
if (
110
126
t.isIdentifier(expression) &&
111
127
path.scope.hasBinding(expression.name)
112
128
) {