Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default function(
path: NodePath,
helpers: { wrapAsync: Object, wrapAwait: Object },
) {
path.traverse(awaitVisitor, {
wrapAwait: helpers.wrapAwait,
});
const isIIFE = checkIsIIFE(path);
path.node.async = false;
path.node.generator = true;
wrapFunction(path, t.cloneNode(helpers.wrapAsync));
const isProperty =
path.isObjectMethod() ||
path.isClassMethod() ||
path.parentPath.isObjectProperty() ||
path.parentPath.isClassProperty();
if (!isProperty && !isIIFE && path.isExpression()) {
annotateAsPure(path);
}
function checkIsIIFE(path: NodePath) {
if (path.parentPath.isCallExpression({ callee: path.node })) {
return true;
}
const fnPath = path.getFunctionParent();
if (!fnPath.node.generator) {
throw new Error("Parent generator function not found");
}
const sentId = path.scope.generateUid("function.sent");
fnPath.traverse(yieldVisitor, { sentId });
fnPath.node.body.body.unshift(
t.variableDeclaration("let", [
t.variableDeclarator(t.identifier(sentId), t.yieldExpression()),
]),
);
wrapFunction(fnPath, state.addHelper("skipFirstGeneratorNext"));
},
},
const fnPath = path.getFunctionParent();
if (!fnPath.node.generator) {
throw new Error("Parent generator function not found");
}
const sentId = path.scope.generateUidIdentifier("function.sent");
fnPath.traverse(yieldVisitor, { sentId });
fnPath.node.body.body.unshift(
t.variableDeclaration("let", [
t.variableDeclarator(sentId, t.yieldExpression()),
]),
);
wrapFunction(fnPath, state.addHelper("skipFirstGeneratorNext"));
},
},