1
+
2
+## Input
3
+
4
+```javascript
5
+import invariant from "invariant";
6
+import { useState } from "react";
7
+
8
+function Component(props) {
9
+ const [x, setX] = useState(false);
10
+ const [y, setY] = useState(false);
11
+ let setState;
12
+ if (props.cond) {
13
+ setState = setX;
14
+ } else {
15
+ setState = setY;
16
+ }
17
+ const setState2 = setState;
18
+ const stateObject = { setState: setState2 };
19
+ return (
20
+ <Foo
21
+ cond={props.cond}
22
+ setX={setX}
23
+ setY={setY}
24
+ setState={stateObject.setState}
25
+ />
26
+ );
27
+}
28
+
29
+function Foo({ cond, setX, setY, setState }) {
30
+ if (cond) {
31
+ invariant(setState === setX, "Expected the correct setState function");
32
+ } else {
33
+ invariant(setState === setY, "Expected the correct setState function");
34
+ }
35
+ return "ok";
36
+}
37
+
38
+export const FIXTURE_ENTRYPOINT = {
39
+ fn: Component,
40
+ // TODO: run this function with {cond:true}, {cond: false}
41
+ params: [{ cond: true }],
42
+};
43
+
44
+```
45
+
46
+## Code
47
+
48
+```javascript
49
+import invariant from "invariant";
50
+import { useState, unstable_useMemoCache as useMemoCache } from "react";
51
+
52
+function Component(props) {
53
+ const $ = useMemoCache(5);
54
+ const [x, setX] = useState(false);
55
+ const [y, setY] = useState(false);
56
+ let setState;
57
+ if (props.cond) {
58
+ setState = setX;
59
+ } else {
60
+ setState = setY;
61
+ }
62
+
63
+ const setState2 = setState;
64
+ let t0;
65
+ if ($[0] !== setState2) {
66
+ t0 = { setState: setState2 };
67
+ $[0] = setState2;
68
+ $[1] = t0;
69
+ } else {
70
+ t0 = $[1];
71
+ }
72
+ const stateObject = t0;
73
+ let t1;
74
+ if ($[2] !== props.cond || $[3] !== stateObject.setState) {
75
+ t1 = (
76
+ <Foo
77
+ cond={props.cond}
78
+ setX={setX}
79
+ setY={setY}
80
+ setState={stateObject.setState}
81
+ />
82
+ );
83
+ $[2] = props.cond;
84
+ $[3] = stateObject.setState;
85
+ $[4] = t1;
86
+ } else {
87
+ t1 = $[4];
88
+ }
89
+ return t1;
90
+}
91
+
92
+function Foo(t21) {
93
+ const { cond, setX, setY, setState } = t21;
94
+ if (cond) {
95
+ invariant(setState === setX, "Expected the correct setState function");
96
+ } else {
97
+ invariant(setState === setY, "Expected the correct setState function");
98
+ }
99
+ return "ok";
100
+}
101
+
102
+export const FIXTURE_ENTRYPOINT = {
103
+ fn: Component,
104
+ // TODO: run this function with {cond:true}, {cond: false}
105
+ params: [{ cond: true }],
106
+};
107
+
108
+```
109
+
110
+### Eval output
111
+(kind: ok) ok
\ No newline at end of file