[test] Add failing test for component syntax with refs

The desugaring of Component syntax with refs is not compatible with our gating 
lowering.
This commit is contained in:
Sathya Gunasekaran
2023-11-28 14:18:24 +00:00
parent be03439687
commit 42fa01ec87
5 changed files with 68 additions and 0 deletions
@@ -0,0 +1,38 @@
## Input
```javascript
// @flow @gating
component Foo(ref: React.RefSetter<Controls>) {
return <Bar ref={ref}/>;
}
```
## Code
```javascript
import { isForgetEnabled_Fixtures } from "ReactForgetFeatureFlag";
import { unstable_useMemoCache as useMemoCache } from "react";
const Foo = React.forwardRef(Foo_withRef);
const Foo_withRef = isForgetEnabled_Fixtures()
? function Foo_withRef(_$$empty_props_placeholder$$, ref) {
const $ = useMemoCache(2);
let t0;
if ($[0] !== ref) {
t0 = <Bar ref={ref} />;
$[0] = ref;
$[1] = t0;
} else {
t0 = $[1];
}
return t0;
}
: function Foo_withRef(
_$$empty_props_placeholder$$: $ReadOnly<{ ... }>,
ref: React.RefSetter<Controls>
) {
return <Bar ref={ref} />;
};
```
@@ -0,0 +1,4 @@
// @flow @gating
component Foo(ref: React.RefSetter<Controls>) {
return <Bar ref={ref}/>;
}
@@ -0,0 +1,20 @@
## Input
```javascript
// @gating
const Foo = React.forwardRef(Foo_withRef);
function Foo_withRef(props, ref) {
return <Bar ref={ref} {...props}></Bar>;
}
```
## Error
```
[ReactForget] Invariant: Encountered Foo_withRef used before declaration which breaks Forget's gating codegen due to hoisting. Rewrite the reference to not use hoisting to fix this issue (3:3)
```
@@ -0,0 +1,5 @@
// @gating
const Foo = React.forwardRef(Foo_withRef);
function Foo_withRef(props, ref) {
return <Bar ref={ref} {...props}></Bar>;
}
@@ -514,6 +514,7 @@ const skipFilter = new Set([
// bug
"bug-jsx-memberexpr-tag-in-lambda",
"bug-invalid-code-when-bailout",
"component-syntax-ref-gating.flow",
]);
export default skipFilter;