@samitouri / QOS-React / commits / 07ba52bc1a

Repro for false positive gating mode hoisting check

ghstack-source-id: c4f5777b85751e9d5f0323384160adfba55d883f Pull Request resolved: https://github.com/facebook/react-forget/pull/2875

Joe Savona committed Apr 19, 2024 at 15:16 UTC 07ba52bc1a09d7650685fab1c0da01e208ea96b9
2 files changed +43
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-gating-with-react-memo.flow.expect.md new
+32
@@ -0,0 +1,32 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +// @flow @gating
6 +import { memo } from "react";
7 +
8 +// TODO: this appears as a hoisted reference to Component, but it's a type not runtime reference!
9 +type Props = React.ElementConfig<typeof Component>;
10 +
11 +component Component(value: string) {
12 + return <div>{value}</div>;
13 +}
14 +
15 +export default memo<Props>(Component);
16 +
17 +```
18 +
19 +
20 +## Error
21 +
22 +```
23 + 5 | type Props = React.ElementConfig<typeof Component>;
24 + 6 |
25 +> 7 | component Component(value: string) {
26 + | ^^^^^^^^^ Invariant: Encountered a function used before its declaration, which breaks Forget's gating codegen due to hoisting. Rewrite the reference to Component to not rely on hoisting to fix this issue (7:7)
27 + 8 | return <div>{value}</div>;
28 + 9 | }
29 + 10 |
30 +```
31 +
32 +
\ No newline at end of file
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-gating-with-react-memo.flow.js new
+11
@@ -0,0 +1,11 @@
1 +// @flow @gating
2 +import { memo } from "react";
3 +
4 +// TODO: this appears as a hoisted reference to Component, but it's a type not runtime reference!
5 +type Props = React.ElementConfig<typeof Component>;
6 +
7 +component Component(value: string) {
8 + return <div>{value}</div>;
9 +}
10 +
11 +export default memo<Props>(Component);