dillon1000/react

Commit

[compiler] Fix `for` loops in try/catch (#35686)

This is a combination of a) a subagent for investigating compiler errors
and b) testing that agent by fixing bugs with for loops within
try/catch. My recent diffs to support maybe-throw within value blocks
was incomplete and handled many cases, like optionals/logicals/etc
within try/catch. However, the handling for for loops was making more
assumptions and needed additional fixes.

Key changes:
* `maybe-throw` terminal `handler` is now nullable. PruneMaybeThrows
nulls the handler for blocks that cannot throw, rather than changing to
a `goto`. This preserves more information, and makes it easier for
BuildReactiveFunction's visitValueBlock() to reconstruct the value
blocks
* Updates BuildReactiveFunction's handling of `for` init/test/update
(and similar for `for..of` and `for..in`) to correctly extract value
blocks. The previous logic made assumptions about the shape of the
SequenceExpression which were incorrect in some cases within try/catch.
The new helper extracts a flattened SequenceExpression.

Supporting changes:
* The agent itself (tested via this diff)
* Updated the script for invoking snap to keep `compiler/` as the
working directory, allowing relative paths to work more easily
* Add an `--update` (`-u`) flag to `yarn snap minimize`, which updates
the fixture in place w the minimized version
Browse files
Changed paths24 files
First-parent comparison
A compiler/.claude/agents/investigate-error.md AddedM compiler/packages/babel-plugin-react-compiler/src/HIR/HIR.ts ModifiedM compiler/packages/babel-plugin-react-compiler/src/HIR/PrintHIR.ts ModifiedM compiler/packages/babel-plugin-react-compiler/src/HIR/visitors.ts ModifiedM compiler/packages/babel-plugin-react-compiler/src/Inference/InferMutationAliasingEffects.ts ModifiedM compiler/packages/babel-plugin-react-compiler/src/Optimization/PruneMaybeThrows.ts ModifiedM compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/BuildReactiveFunction.ts ModifiedD compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.bug-invariant-expected-break-target.expect.md DeletedD compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.bug-invariant-expected-break-target.js DeletedD compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.todo-repro-declaration-for-all-identifiers.expect.md DeletedD compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.todo-repro-declaration-for-all-identifiers.js DeletedA compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/repro-declaration-for-all-identifiers.expect.md AddedA compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/repro-declaration-for-all-identifiers.js AddedA compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/repro-for-in-in-try.expect.md AddedA compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/repro-for-in-in-try.js AddedA compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/repro-for-loop-in-try.expect.md AddedA compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/repro-for-loop-in-try.js AddedA compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/repro-for-of-in-try.expect.md AddedA compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/repro-for-of-in-try.js AddedA compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/repro-nested-try-catch-in-usememo.expect.md AddedA compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/repro-nested-try-catch-in-usememo.js AddedM compiler/packages/snap/src/minimize.ts ModifiedM compiler/packages/snap/src/reporter.ts ModifiedM compiler/packages/snap/src/runner.ts Modified
Patch

Files changed

Rendering syntax-highlighted changes…