From 7605e89a50baf37780976f33a441086a3793d643 Mon Sep 17 00:00:00 2001 From: Joe Savona Date: Fri, 8 Mar 2024 13:59:20 -0800 Subject: [PATCH] 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. --- ...ted-function-in-unreachable-code.expect.md | 26 +++++++++++++++++++ ...do-hoisted-function-in-unreachable-code.js | 6 +++++ 2 files changed, 32 insertions(+) create mode 100644 compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-hoisted-function-in-unreachable-code.expect.md create mode 100644 compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-hoisted-function-in-unreachable-code.js diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-hoisted-function-in-unreachable-code.expect.md b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-hoisted-function-in-unreachable-code.expect.md new file mode 100644 index 0000000000..9fb8c349e0 --- /dev/null +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-hoisted-function-in-unreachable-code.expect.md @@ -0,0 +1,26 @@ + +## Input + +```javascript +function Component() { + return ; + + // This is unreachable from a control-flow perspective, but it gets hoisted + function Foo() {} +} + +``` + + +## Error + +``` + 1 | function Component() { +> 2 | return ; + | ^^^ [ReactForget] Invariant: [hoisting] Expected value for identifier to be initialized. Foo$0 (2:2) + 3 | + 4 | // This is unreachable from a control-flow perspective, but it gets hoisted + 5 | function Foo() {} +``` + + \ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-hoisted-function-in-unreachable-code.js b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-hoisted-function-in-unreachable-code.js new file mode 100644 index 0000000000..ce7215e0c8 --- /dev/null +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-hoisted-function-in-unreachable-code.js @@ -0,0 +1,6 @@ +function Component() { + return ; + + // This is unreachable from a control-flow perspective, but it gets hoisted + function Foo() {} +}