Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Function(path: NodePath, state: any) {
const {node, scope} = path;
if (!node.async || node.generator) return;
const hasAwait = traverse.hasType(node.body, scope, 'AwaitExpression', FUNCTION_TYPES);
traverse(node, {
blacklist: FUNCTION_TYPES,
AwaitExpression(path2: NodePath) {
// eslint-disable-next-line no-param-reassign
path2.node.type = 'YieldExpression';
path2.node.argument = t.callExpression(
state.addImport('bluebird', 'resolve'),
[path2.node.argument]
);
},
}, scope);
const isClassOrObjectMethod = path.isClassMethod() || path.isObjectMethod();
(isClassOrObjectMethod ? classOrObjectMethod : plainFunction)(path, state, hasAwait);
var ref = fn;
if (this.loop) {
ref = this.scope.generateUidIdentifier("loop");
this.loopPath.insertBefore(t.variableDeclaration("var", [
t.variableDeclarator(ref, fn)
]));
}
// build a call and a unique id that we can assign the return value to
var call = t.callExpression(ref, args);
var ret = this.scope.generateUidIdentifier("ret");
// handle generators
var hasYield = traverse.hasType(fn.body, this.scope, "YieldExpression", t.FUNCTION_TYPES);
if (hasYield) {
fn.generator = true;
call = t.yieldExpression(call, true);
}
// handlers async functions
var hasAsync = traverse.hasType(fn.body, this.scope, "AwaitExpression", t.FUNCTION_TYPES);
if (hasAsync) {
fn.async = true;
call = t.awaitExpression(call);
}
this.buildClosure(ret, call);
}
]));
}
// build a call and a unique id that we can assign the return value to
var call = t.callExpression(ref, args);
var ret = this.scope.generateUidIdentifier("ret");
// handle generators
var hasYield = traverse.hasType(fn.body, this.scope, "YieldExpression", t.FUNCTION_TYPES);
if (hasYield) {
fn.generator = true;
call = t.yieldExpression(call, true);
}
// handlers async functions
var hasAsync = traverse.hasType(fn.body, this.scope, "AwaitExpression", t.FUNCTION_TYPES);
if (hasAsync) {
fn.async = true;
call = t.awaitExpression(call);
}
this.buildClosure(ret, call);
}
function array(node, parent, scope) {
var uid = scope.generateUidIdentifierBasedOnNode(parent);
var container = util.template("array-comprehension-container", {
KEY: uid
});
container.callee.shadow = true;
var block = container.callee.body;
var body = block.body;
if (traverse.hasType(node, scope, "YieldExpression", t.FUNCTION_TYPES)) {
container.callee.generator = true;
container = t.yieldExpression(container, true);
}
var returnStatement = body.pop();
body.push(buildComprehension(node, function () {
return util.template("array-push", {
STATEMENT: node.body,
KEY: uid
}, true);
}));
body.push(returnStatement);
return container;
}