[hir] Failing test for adding ref as dep incorrectly
Sathya Gunasekaran committed
May 31, 2023 at 13:55 UTC
2c8f6888e68b0f8d0d83c6563efbdd3dd25c8feb
2 files changed
+71
compiler/forget/src/__tests__/fixtures/compiler/_bug.use-ref-added-to-dep-without-type-info.expect.md
new
+61
@@ -0,0 +1,61 @@
1
+
2
+## Input
3
+
4
+```javascript
5
+function Foo({ a }) {
6
+ const ref = useRef();
7
+ // type information is lost here as we don't track types of fields
8
+ const val = { ref };
9
+ // without type info, we don't know that val.ref.current is a ref value so we
10
+ // end up depending on val.ref.current
11
+ const x = { a, val: val.ref.current };
12
+
13
+ return <VideoList videos={x} />;
14
+}
15
+
16
+```
17
+
18
+## Code
19
+
20
+```javascript
21
+import { unstable_useMemoCache as useMemoCache } from "react";
22
+function Foo(t23) {
23
+ const $ = useMemoCache(7);
24
+ const { a } = t23;
25
+ const ref = useRef();
26
+ const c_0 = $[0] !== ref;
27
+ let t0;
28
+ if (c_0) {
29
+ t0 = { ref };
30
+ $[0] = ref;
31
+ $[1] = t0;
32
+ } else {
33
+ t0 = $[1];
34
+ }
35
+ const val = t0;
36
+ const c_2 = $[2] !== a;
37
+ const c_3 = $[3] !== val.ref.current;
38
+ let t1;
39
+ if (c_2 || c_3) {
40
+ t1 = { a, val: val.ref.current };
41
+ $[2] = a;
42
+ $[3] = val.ref.current;
43
+ $[4] = t1;
44
+ } else {
45
+ t1 = $[4];
46
+ }
47
+ const x = t1;
48
+ const c_5 = $[5] !== x;
49
+ let t2;
50
+ if (c_5) {
51
+ t2 = <VideoList videos={x} />;
52
+ $[5] = x;
53
+ $[6] = t2;
54
+ } else {
55
+ t2 = $[6];
56
+ }
57
+ return t2;
58
+}
59
+
60
+```
61
+
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/compiler/_bug.use-ref-added-to-dep-without-type-info.js
new
+10
@@ -0,0 +1,10 @@
1
+function Foo({ a }) {
2
+ const ref = useRef();
3
+ // type information is lost here as we don't track types of fields
4
+ const val = { ref };
5
+ // without type info, we don't know that val.ref.current is a ref value so we
6
+ // end up depending on val.ref.current
7
+ const x = { a, val: val.ref.current };
8
+
9
+ return <VideoList videos={x} />;
10
+}