Skip to content

Commit

Permalink
Fix throws when certain parts of the AST are rewritten by other plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
rpetrich committed Apr 27, 2019
1 parent b3b6e48 commit 3657169
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion async-to-promises.ts
Expand Up @@ -2436,6 +2436,9 @@ export default function({ types, template, traverse, transformFromAst, version }
let shouldPushExitIdentifier = false;
while (targetPath !== path) {
const parent = targetPath.parentPath;
if (parent == null) {
break;
}
if (!parent.isSwitchCase() && !parent.isBlockStatement()) {
let exitIdentifier;
const explicitExits = pathsReturnOrThrow(parent);
Expand Down Expand Up @@ -2606,7 +2609,7 @@ export default function({ types, template, traverse, transformFromAst, version }
}
}
const forIdentifier = path.scope.generateUidIdentifier("for");
const bodyFunction = rewriteAsyncNode(state.generatorState, parent, functionize(pluginState, [], blockStatement(parent.node.body), targetPath), additionalConstantNames, exitIdentifier);
const bodyFunction = rewriteAsyncNode(state.generatorState, parent, functionize(pluginState, [], blockStatement(parent.node.body || []), targetPath), additionalConstantNames, exitIdentifier);
const testFunction = unwrapReturnCallWithEmptyArguments(testExpression || voidExpression(), path.scope, additionalConstantNames);
const updateFunction = unwrapReturnCallWithEmptyArguments(updateExpression || voidExpression(), path.scope, additionalConstantNames);
loopCall = isDoWhile ? types.callExpression(helperReference(pluginState, parent, "_do"), [bodyFunction, testFunction]) : types.callExpression(helperReference(pluginState, parent, "_for"), [testFunction, updateFunction, bodyFunction]);
Expand Down

0 comments on commit 3657169

Please sign in to comment.