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

Configure Feed

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

Remove newlines in JS tag templates

+15 -20
+9 -12
src/babel/__snapshots__/plugin.test.js.snap
··· 8 8 var _node_expression = (0, _reghex._pattern)(1), 9 9 _node_expression2 = (0, _reghex._pattern)(2); 10 10 11 - const node = function _node(state) { 11 + const node = function (state) { 12 12 var index_1 = state.index; 13 13 var node = []; 14 14 var match; ··· 35 35 exports[`works with local recursion 1`] = ` 36 36 "import { tag, _exec, _pattern } from 'reghex'; 37 37 38 - const inner = function _inner(state) { 38 + const inner = function (state) { 39 39 var index_1 = state.index; 40 40 var node = []; 41 41 var match; ··· 51 51 return node; 52 52 }; 53 53 54 - const node = function _node(state) { 54 + const node = function (state) { 55 55 var index_1 = state.index; 56 56 var node = []; 57 57 var match; ··· 75 75 _node_expression2 = _pattern(2), 76 76 _node_expression3 = _pattern(3); 77 77 78 - const node = function _node(state) { 78 + const node = function (state) { 79 79 var index_1 = state.index; 80 80 var node = []; 81 81 var match; ··· 134 134 _node_expression4 = _pattern(4), 135 135 _node_expression5 = _pattern(5); 136 136 137 - const node = function _node(state) { 137 + const node = function (state) { 138 138 var index_1 = state.index; 139 139 var node = []; 140 140 var match; ··· 218 218 219 219 var _inner_transform = x => x; 220 220 221 - const first = function _inner(state) { 221 + const first = function (state) { 222 222 var index_1 = state.index; 223 223 var node = []; 224 224 var match; 225 225 node.tag = 'inner'; 226 - return; 227 - 228 - _inner_transform(node); 226 + return _inner_transform(node); 229 227 }; 230 228 231 229 const transform = x => x; 232 230 233 - const second = function _node(state) { 231 + const second = function (state) { 234 232 var index_1 = state.index; 235 233 var node = []; 236 234 var match; 237 235 node.tag = 'node'; 238 - return; 239 - transform(node); 236 + return transform(node); 240 237 };" 241 238 `;
+1 -3
src/babel/transform.js
··· 194 194 ); 195 195 } 196 196 197 - const matchName = this.getMatchName(path); 198 197 const name = path.node.tag.arguments[0]; 199 198 const quasis = path.node.quasi.quasis.map((x) => x.value.cooked); 200 199 ··· 209 208 throw path.get('quasi').buildCodeFrameError(error.message); 210 209 } 211 210 212 - const id = path.scope.generateUidIdentifier(matchName).name; 213 - const code = astRoot(ast, id, '%%name%%', transform && '%%transform%%'); 211 + const code = astRoot(ast, '%%name%%', transform && '%%transform%%'); 214 212 215 213 path.replaceWith( 216 214 template.expression(code)(transform ? { name, transform } : { name })
+5 -5
src/codegen.js
··· 2 2 const _match = 'match'; 3 3 const _node = 'node'; 4 4 5 - function js(/* arguments */) { 5 + export function js(/* arguments */) { 6 6 let body = arguments[0][0]; 7 7 for (let i = 1; i < arguments.length; i++) 8 8 body = body + arguments[i] + (arguments[0][i] || ''); 9 - return '\n' + body.trim(); 9 + return body.trim(); 10 10 } 11 11 12 12 const assignIndex = (depth) => ··· 216 216 `; 217 217 }; 218 218 219 - const astRoot = (ast, id, name, transform) => js` 220 - function ${id}(${_state}) { 219 + const astRoot = (ast, name, transform) => js` 220 + (function (${_state}) { 221 221 ${assignIndex(1)} 222 222 var ${_node} = []; 223 223 var ${_match}; ··· 232 232 233 233 ${_node}.tag = ${name}; 234 234 return ${transform ? js`(${transform})(${_node})` : _node}; 235 - } 235 + }) 236 236 `; 237 237 238 238 export { astRoot };