Repro for invariant on value block in try/catch
The code for value block handling assumes a small set of terminal kinds, but try/catch causes the entire body to get wrapped in MaybeThrow terminals. We need to skip over these and delegate to the inner content.
Joe Savona committed
Feb 26, 2024 at 16:21 UTC
5acfc13575274ad52f1a84d9e222ec24ed9c318c
2 files changed
+39
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-logical-expression-within-try-catch.expect.md
new
+30
@@ -0,0 +1,30 @@
1
+
2
+## Input
3
+
4
+```javascript
5
+function Component(props) {
6
+ let result;
7
+ try {
8
+ result = props.cond && props.foo;
9
+ } catch (e) {
10
+ console.log(e);
11
+ }
12
+ return result;
13
+}
14
+
15
+```
16
+
17
+
18
+## Error
19
+
20
+```
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)
25
+ 5 | } catch (e) {
26
+ 6 | console.log(e);
27
+ 7 | }
28
+```
29
+
30
+
\ No newline at end of file
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-logical-expression-within-try-catch.js
new
+9
@@ -0,0 +1,9 @@
1
+function Component(props) {
2
+ let result;
3
+ try {
4
+ result = props.cond && props.foo;
5
+ } catch (e) {
6
+ console.log(e);
7
+ }
8
+ return result;
9
+}