lib/condenser/processors/node_modules/regenerator-transform/src/visit.js in condenser-0.2 vs lib/condenser/processors/node_modules/regenerator-transform/src/visit.js in condenser-0.3
- old
+ new
@@ -112,15 +112,13 @@
};
path.traverse(argumentsThisVisitor, context);
if (context.usesArguments) {
vars = vars || t.variableDeclaration("var", []);
- const argumentIdentifier = t.identifier("arguments");
- // we need to do this as otherwise arguments in arrow functions gets hoisted
- argumentIdentifier._shadowedFunctionLiteral = path;
vars.declarations.push(t.variableDeclarator(
- t.clone(argsId), argumentIdentifier
+ t.clone(argsId),
+ t.identifier("arguments"),
));
}
let emitter = new Emitter(contextId);
emitter.explode(path.get("body"));
@@ -132,22 +130,35 @@
let wrapArgs = [emitter.getContextFunction(innerFnId)];
let tryLocsList = emitter.getTryLocsList();
if (node.generator) {
wrapArgs.push(outerFnExpr);
- } else if (context.usesThis || tryLocsList) {
+ } else if (context.usesThis || tryLocsList || node.async) {
// Async functions that are not generators don't care about the
// outer function because they don't need it to be marked and don't
// inherit from its .prototype.
wrapArgs.push(t.nullLiteral());
}
if (context.usesThis) {
wrapArgs.push(t.thisExpression());
- } else if (tryLocsList) {
+ } else if (tryLocsList || node.async) {
wrapArgs.push(t.nullLiteral());
}
if (tryLocsList) {
wrapArgs.push(tryLocsList);
+ } else if (node.async) {
+ wrapArgs.push(t.nullLiteral());
+ }
+
+ if (node.async) {
+ // Rename any locally declared "Promise" variable,
+ // to use the global one.
+ let currentScope = path.scope;
+ do {
+ if (currentScope.hasOwnBinding("Promise")) currentScope.rename("Promise");
+ } while (currentScope = currentScope.parent);
+
+ wrapArgs.push(t.identifier("Promise"));
}
let wrapCall = t.callExpression(
util.runtimeProperty(node.async ? "async" : "wrap"),
wrapArgs