From f73492b448f7099bc1dd63f2eae412abff92cae9 Mon Sep 17 00:00:00 2001 From: Phil Pluckthun Date: Sat, 28 Aug 2021 17:12:11 +0100 Subject: [PATCH] Add special case to keep codegen output small --- src/babel/__snapshots__/plugin.test.js.snap | 18 +++++++----------- src/codegen.js | 8 ++++++++ 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/babel/__snapshots__/plugin.test.js.snap b/src/babel/__snapshots__/plugin.test.js.snap index 8b94608..ec058af 100644 --- a/src/babel/__snapshots__/plugin.test.js.snap +++ b/src/babel/__snapshots__/plugin.test.js.snap @@ -328,18 +328,14 @@ const node = function (state) { break group_2; } - group_4: { - var y4 = state.y, - x4 = state.x; + var y4 = state.y, + x4 = state.x; - if ((x = _node_expression4(state)) != null) { - node.push(x); - } else { - state.y = y4; - state.x = x4; - node.length = ln2; - break group_4; - } + if ((x = _node_expression4(state)) != null) { + node.push(x); + } else { + state.y = y4; + state.x = x4; } if ((x = _node_expression5(state)) != null) { diff --git a/src/codegen.js b/src/codegen.js index 3160391..c96d8af 100644 --- a/src/codegen.js +++ b/src/codegen.js @@ -98,6 +98,14 @@ const astQuantifier = (ast, depth, opts) => { ${astChild(ast, depth, opts)} } `; + } else if (ast.quantifier === '?' && ast.expression) { + opts.index = depth; + opts.abort = ''; + + child = js` + ${assignIndex(depth)} + ${astChild(ast, depth, opts)} + `; } else if (ast.quantifier === '?') { opts.index = depth; opts.abort = js`break ${group}`; -- knotmirror 0.0.1