Skip to content

Commit b8a6bfa

Browse files
authored
[compiler] Support optional/logical/etc within try/catch (facebook#35606)
Adds support for value terminals (optional/logical/ternary/sequence) within try/catch clauses. Try/catch expressions insert maybe-throw terminals after each instruction, but BuildReactiveFunction's value block extraction was not expecting these terminals. The fix is to roughly treat maybe-throw similarly to goto, falling through to the continuation block, but there are a few edge cases to handle. I've also added extensive tests, including testing that errors correctly flow to the catch handler.
1 parent ed4bd54 commit b8a6bfa

30 files changed

+1313
-341
lines changed

compiler/packages/babel-plugin-react-compiler/src/Inference/DropManualMemoization.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,10 @@ function findOptionalPlaces(fn: HIRFunction): Set<IdentifierId> {
583583
testBlock = fn.body.blocks.get(terminal.fallthrough)!;
584584
break;
585585
}
586+
case 'maybe-throw': {
587+
testBlock = fn.body.blocks.get(terminal.continuation)!;
588+
break;
589+
}
586590
default: {
587591
CompilerError.invariant(false, {
588592
reason: `Unexpected terminal in optional`,

0 commit comments

Comments
 (0)