Skip to content

Commit 592b67c

Browse files
committed
Fixed TCO tryCatch logic
1 parent 99bff90 commit 592b67c

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/BabelPlugin.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -388,14 +388,18 @@ function Plugin(babel) {
388388
));
389389
}
390390
}
391-
if (isTailCall && (tryStack.length === 0 || finalStack.length > 0)) {
391+
if (isTailCall) {
392392
if (tryStack.length > 0) {
393393
const inTryCatch = tryStack[tryStack.length - 1];
394-
if (path.getFunctionParent().node === inTryCatch.function.node && finalStack.length > 0) {
395-
const inFinalizer = finalStack[finalStack.length - 1];
396-
if ("finalizer" in inTryCatch.node && inFinalizer === inTryCatch.node.finalizer) {
397-
path.node.expressions[0].argument.arguments.push(t.booleanLiteral(true));
394+
if (path.getFunctionParent().node === inTryCatch.function.node) {
395+
if (finalStack.length > 0) {
396+
const inFinalizer = finalStack[finalStack.length - 1];
397+
if ("finalizer" in inTryCatch.node && inFinalizer === inTryCatch.node.finalizer) {
398+
path.node.expressions[0].argument.arguments.push(t.booleanLiteral(true));
399+
}
398400
}
401+
} else {
402+
path.node.expressions[0].argument.arguments.push(t.booleanLiteral(true));
399403
}
400404
} else {
401405
path.node.expressions[0].argument.arguments.push(t.booleanLiteral(true));

0 commit comments

Comments
 (0)