[test] Add failing test for component syntax with refs
The desugaring of Component syntax with refs is not compatible with our gating lowering.
Sathya Gunasekaran committed
Nov 28, 2023 at 14:18 UTC
42fa01ec876f32e2c2da091c6934f25c3ddff562
5 files changed
+68
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/component-syntax-ref-gating.flow.expect.md
new
+38
@@ -0,0 +1,38 @@
1
+
2
+## Input
3
+
4
+```javascript
5
+// @flow @gating
6
+component Foo(ref: React.RefSetter<Controls>) {
7
+ return <Bar ref={ref}/>;
8
+}
9
+```
10
+
11
+## Code
12
+
13
+```javascript
14
+import { isForgetEnabled_Fixtures } from "ReactForgetFeatureFlag";
15
+import { unstable_useMemoCache as useMemoCache } from "react";
16
+const Foo = React.forwardRef(Foo_withRef);
17
+const Foo_withRef = isForgetEnabled_Fixtures()
18
+ ? function Foo_withRef(_$$empty_props_placeholder$$, ref) {
19
+ const $ = useMemoCache(2);
20
+ let t0;
21
+ if ($[0] !== ref) {
22
+ t0 = <Bar ref={ref} />;
23
+ $[0] = ref;
24
+ $[1] = t0;
25
+ } else {
26
+ t0 = $[1];
27
+ }
28
+ return t0;
29
+ }
30
+ : function Foo_withRef(
31
+ _$$empty_props_placeholder$$: $ReadOnly<{ ... }>,
32
+ ref: React.RefSetter<Controls>
33
+ ) {
34
+ return <Bar ref={ref} />;
35
+ };
36
+
37
+```
38
+
\ No newline at end of file
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/component-syntax-ref-gating.flow.js
new
+4
@@ -0,0 +1,4 @@
1
+// @flow @gating
2
+component Foo(ref: React.RefSetter<Controls>) {
3
+ return <Bar ref={ref}/>;
4
+}
\ No newline at end of file
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.gating-hoisting.expect.md
new
+20
@@ -0,0 +1,20 @@
1
+
2
+## Input
3
+
4
+```javascript
5
+// @gating
6
+const Foo = React.forwardRef(Foo_withRef);
7
+function Foo_withRef(props, ref) {
8
+ return <Bar ref={ref} {...props}></Bar>;
9
+}
10
+
11
+```
12
+
13
+
14
+## Error
15
+
16
+```
17
+[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)
18
+```
19
+
20
+
\ No newline at end of file
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.gating-hoisting.js
new
+5
@@ -0,0 +1,5 @@
1
+// @gating
2
+const Foo = React.forwardRef(Foo_withRef);
3
+function Foo_withRef(props, ref) {
4
+ return <Bar ref={ref} {...props}></Bar>;
5
+}
compiler/packages/sprout/src/SproutTodoFilter.ts
+1
@@ -514,6 +514,7 @@ const skipFilter = new Set([
514
// bug
515
"bug-jsx-memberexpr-tag-in-lambda",
516
"bug-invalid-code-when-bailout",
517
+ "component-syntax-ref-gating.flow",
518
]);
519
520
export default skipFilter;