lib/condenser/processors/node_modules/regenerator-transform/src/emit.js in condenser-0.2 vs lib/condenser/processors/node_modules/regenerator-transform/src/emit.js in condenser-0.3

- old
+ new

@@ -993,18 +993,18 @@ case "CallExpression": let calleePath = path.get("callee"); let argsPath = path.get("arguments"); let newCallee; - let newArgs = []; + let newArgs; - let hasLeapingArgs = false; - argsPath.forEach(function(argPath) { - hasLeapingArgs = hasLeapingArgs || - meta.containsLeap(argPath.node); - }); + let hasLeapingArgs = argsPath.some( + argPath => meta.containsLeap(argPath.node) + ); + let injectFirstArg = null; + if (t.isMemberExpression(calleePath.node)) { if (hasLeapingArgs) { // If the arguments of the CallExpression contained any yield // expressions, then we need to be sure to evaluate the callee // before evaluating the arguments, but if the callee was a member @@ -1020,11 +1020,11 @@ let newProperty = calleePath.node.computed ? explodeViaTempVar(null, calleePath.get("property")) : calleePath.node.property; - newArgs.unshift(newObject); + injectFirstArg = newObject; newCallee = t.memberExpression( t.memberExpression( t.cloneDeep(newObject), newProperty, @@ -1055,19 +1055,21 @@ t.cloneDeep(newCallee) ]); } } - argsPath.forEach(function(argPath) { - newArgs.push(explodeViaTempVar(null, argPath)); - }); + if (hasLeapingArgs) { + newArgs = argsPath.map(argPath => explodeViaTempVar(null, argPath)); + if (injectFirstArg) newArgs.unshift(injectFirstArg); - return finish(t.callExpression( - newCallee, - newArgs.map(arg => t.cloneDeep(arg)) - )); + newArgs = newArgs.map(arg => t.cloneDeep(arg)); + } else { + newArgs = path.node.arguments; + } + return finish(t.callExpression(newCallee, newArgs)); + case "NewExpression": return finish(t.newExpression( explodeViaTempVar(null, path.get("callee")), path.get("arguments").map(function(argPath) { return explodeViaTempVar(null, argPath); @@ -1090,10 +1092,16 @@ )); case "ArrayExpression": return finish(t.arrayExpression( path.get("elements").map(function(elemPath) { - return explodeViaTempVar(null, elemPath); + if (elemPath.isSpreadElement()) { + return t.spreadElement( + explodeViaTempVar(null, elemPath.get("argument")) + ); + } else { + return explodeViaTempVar(null, elemPath); + } }) )); case "SequenceExpression": let lastIndex = expr.expressions.length - 1;