Turn value block within try/catch into todo (from invariant)
Within a try/catch, every instruction is followed by a maybe-throw terminal. This currently breaks the logic in BuildReactiveFunction which tries to reassemble the value block, since it isn't expecting the maybe-throw. Conceptually the logic should just ignore it — we could even flatten away maybe-throw terminals before this pass — but for now since this pattern is rare we can just make it a todo.
Joe Savona committed
Mar 6, 2024 at 15:28 UTC
854a810f0598def185f3f9593b070960433b21fd
2 files changed
+9
-1
compiler/packages/babel-plugin-react-forget/src/ReactiveScopes/BuildReactiveFunction.ts
+8
@@ -1061,6 +1061,14 @@ class Driver {
1061
id: terminal.id,
1062
};
1063
}
1064
+ case "maybe-throw": {
1065
+ CompilerError.throwTodo({
1066
+ reason: `Support value blocks (conditional, logical, optional chaining, etc) within a try/catch statement`,
1067
+ description: null,
1068
+ loc: terminal.loc,
1069
+ suggestions: null,
1070
+ });
1071
+ }
1072
default: {
1073
CompilerError.invariant(false, {
1074
reason: `Unexpected value block terminal kind '${terminal.kind}'`,
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-logical-expression-within-try-catch.expect.md
+1
-1
@@ -21,7 +21,7 @@ function Component(props) {
21
2 | let result;
22
3 | try {
23
> 4 | result = props.cond && props.foo;
24
- | ^^^^^ [ReactForget] Invariant: Unexpected value block terminal kind 'maybe-throw' (4:4)
24
+ | ^^^^^ [ReactForget] Todo: Support value blocks (conditional, logical, optional chaining, etc) within a try/catch statement (4:4)
25
5 | } catch (e) {
26
6 | console.log(e);
27
7 | }