Repro for false positive gating mode hoisting check

ghstack-source-id: c4f5777b85751e9d5f0323384160adfba55d883f
Pull Request resolved: https://github.com/facebook/react-forget/pull/2875
This commit is contained in:
Joe Savona
2024-04-19 15:16:15 -07:00
parent a78da09640
commit 07ba52bc1a
2 changed files with 43 additions and 0 deletions
@@ -0,0 +1,32 @@
## Input
```javascript
// @flow @gating
import { memo } from "react";
// TODO: this appears as a hoisted reference to Component, but it's a type not runtime reference!
type Props = React.ElementConfig<typeof Component>;
component Component(value: string) {
return <div>{value}</div>;
}
export default memo<Props>(Component);
```
## Error
```
5 | type Props = React.ElementConfig<typeof Component>;
6 |
> 7 | component Component(value: string) {
| ^^^^^^^^^ 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)
8 | return <div>{value}</div>;
9 | }
10 |
```
@@ -0,0 +1,11 @@
// @flow @gating
import { memo } from "react";
// TODO: this appears as a hoisted reference to Component, but it's a type not runtime reference!
type Props = React.ElementConfig<typeof Component>;
component Component(value: string) {
return <div>{value}</div>;
}
export default memo<Props>(Component);