Repro for "unreachable" hoisted function
For T175282529. We already detect hoisted functions and have a specific todo for them, but in this case the function is in unreachable code that gets pruned during BuildHIR. The later check for hoisted functions doesn't find it.
Joe Savona committed
Mar 8, 2024 at 13:59 UTC
7605e89a50baf37780976f33a441086a3793d643
2 files changed
+32
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-hoisted-function-in-unreachable-code.expect.md
new
+26
@@ -0,0 +1,26 @@
1
+
2
+## Input
3
+
4
+```javascript
5
+function Component() {
6
+ return <Foo />;
7
+
8
+ // This is unreachable from a control-flow perspective, but it gets hoisted
9
+ function Foo() {}
10
+}
11
+
12
+```
13
+
14
+
15
+## Error
16
+
17
+```
18
+ 1 | function Component() {
19
+> 2 | return <Foo />;
20
+ | ^^^ [ReactForget] Invariant: [hoisting] Expected value for identifier to be initialized. Foo$0 (2:2)
21
+ 3 |
22
+ 4 | // This is unreachable from a control-flow perspective, but it gets hoisted
23
+ 5 | function Foo() {}
24
+```
25
+
26
+
\ No newline at end of file
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-hoisted-function-in-unreachable-code.js
new
+6
@@ -0,0 +1,6 @@
1
+function Component() {
2
+ return <Foo />;
3
+
4
+ // This is unreachable from a control-flow perspective, but it gets hoisted
5
+ function Foo() {}
6
+}