More fixtures for reactivity and mutable aliasing (property load case)
Joe Savona committed
Jan 19, 2024 at 19:12 UTC
0894e35d94fa84136e68403c7135c276a5f7898a
2 files changed
+115
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/reactivity-via-aliased-mutation-through-property-load.expect.md
new
+87
@@ -0,0 +1,87 @@
1
+
2
+## Input
3
+
4
+```javascript
5
+function Component(props) {
6
+ const x = {};
7
+ const y = [];
8
+ x.y = y;
9
+ x.y.push(props.input);
10
+
11
+ let z = 0;
12
+ if (x.y[0]) {
13
+ z = 1;
14
+ }
15
+
16
+ return [z];
17
+}
18
+
19
+export const FIXTURE_ENTRYPOINT = {
20
+ fn: Component,
21
+ params: [],
22
+ sequentialRenders: [
23
+ { input: true },
24
+ { input: true },
25
+ { input: false },
26
+ { input: false },
27
+ { input: true },
28
+ { input: false },
29
+ { input: true },
30
+ { input: false },
31
+ ],
32
+};
33
+
34
+```
35
+
36
+## Code
37
+
38
+```javascript
39
+import { unstable_useMemoCache as useMemoCache } from "react";
40
+function Component(props) {
41
+ const $ = useMemoCache(2);
42
+ const x = {};
43
+ const y = [];
44
+ x.y = y;
45
+ x.y.push(props.input);
46
+
47
+ let z = 0;
48
+ if (x.y[0]) {
49
+ z = 1;
50
+ }
51
+ let t0;
52
+ if ($[0] !== z) {
53
+ t0 = [z];
54
+ $[0] = z;
55
+ $[1] = t0;
56
+ } else {
57
+ t0 = $[1];
58
+ }
59
+ return t0;
60
+}
61
+
62
+export const FIXTURE_ENTRYPOINT = {
63
+ fn: Component,
64
+ params: [],
65
+ sequentialRenders: [
66
+ { input: true },
67
+ { input: true },
68
+ { input: false },
69
+ { input: false },
70
+ { input: true },
71
+ { input: false },
72
+ { input: true },
73
+ { input: false },
74
+ ],
75
+};
76
+
77
+```
78
+
79
+### Eval output
80
+(kind: ok) [1]
81
+[1]
82
+[0]
83
+[0]
84
+[1]
85
+[0]
86
+[1]
87
+[0]
\ No newline at end of file
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/reactivity-via-aliased-mutation-through-property-load.js
new
+28
@@ -0,0 +1,28 @@
1
+function Component(props) {
2
+ const x = {};
3
+ const y = [];
4
+ x.y = y;
5
+ x.y.push(props.input);
6
+
7
+ let z = 0;
8
+ if (x.y[0]) {
9
+ z = 1;
10
+ }
11
+
12
+ return [z];
13
+}
14
+
15
+export const FIXTURE_ENTRYPOINT = {
16
+ fn: Component,
17
+ params: [],
18
+ sequentialRenders: [
19
+ { input: true },
20
+ { input: true },
21
+ { input: false },
22
+ { input: false },
23
+ { input: true },
24
+ { input: false },
25
+ { input: true },
26
+ { input: false },
27
+ ],
28
+};