1
+
2
+## Input
3
+
4
+```javascript
5
+// @flow @compilationMode:"infer"
6
+'use strict';
7
+
8
+function getWeekendDays(user) {
9
+ return [0, 6];
10
+}
11
+
12
+function getConfig(weekendDays) {
13
+ return [1, 5];
14
+}
15
+
16
+component Calendar(user, defaultFirstDay, currentDate, view) {
17
+ const weekendDays = getWeekendDays(user);
18
+ let firstDay = defaultFirstDay;
19
+ let daysToDisplay = 7;
20
+ if (view === 'week') {
21
+ let lastDay;
22
+ // this assignment produces invalid code
23
+ [firstDay, lastDay] = getConfig(weekendDays);
24
+ daysToDisplay = ((7 + lastDay - firstDay) % 7) + 1;
25
+ } else if (view === 'day') {
26
+ firstDay = currentDate.getDayOfWeek();
27
+ daysToDisplay = 1;
28
+ }
29
+
30
+ return [currentDate, firstDay, daysToDisplay];
31
+}
32
+
33
+export const FIXTURE_ENTRYPOINT = {
34
+ fn: Calendar,
35
+ params: [
36
+ {
37
+ user: {},
38
+ defaultFirstDay: 1,
39
+ currentDate: {getDayOfWeek: () => 3},
40
+ view: 'week',
41
+ },
42
+ ],
43
+ sequentialRenders: [
44
+ {
45
+ user: {},
46
+ defaultFirstDay: 1,
47
+ currentDate: {getDayOfWeek: () => 3},
48
+ view: 'week',
49
+ },
50
+ {
51
+ user: {},
52
+ defaultFirstDay: 1,
53
+ currentDate: {getDayOfWeek: () => 3},
54
+ view: 'day',
55
+ },
56
+ ],
57
+};
58
+
59
+```
60
+
61
+## Code
62
+
63
+```javascript
64
+"use strict";
65
+import { c as _c } from "react/compiler-runtime";
66
+
67
+function getWeekendDays(user) {
68
+ return [0, 6];
69
+}
70
+
71
+function getConfig(weekendDays) {
72
+ return [1, 5];
73
+}
74
+
75
+function Calendar(t0) {
76
+ const $ = _c(12);
77
+ const { user, defaultFirstDay, currentDate, view } = t0;
78
+ let daysToDisplay;
79
+ let firstDay;
80
+ if (
81
+ $[0] !== currentDate ||
82
+ $[1] !== defaultFirstDay ||
83
+ $[2] !== user ||
84
+ $[3] !== view
85
+ ) {
86
+ const weekendDays = getWeekendDays(user);
87
+ firstDay = defaultFirstDay;
88
+ daysToDisplay = 7;
89
+ if (view === "week") {
90
+ let lastDay;
91
+
92
+ [firstDay, lastDay] = getConfig(weekendDays);
93
+ daysToDisplay = ((7 + lastDay - firstDay) % 7) + 1;
94
+ } else {
95
+ if (view === "day") {
96
+ let t1;
97
+ if ($[6] !== currentDate) {
98
+ t1 = currentDate.getDayOfWeek();
99
+ $[6] = currentDate;
100
+ $[7] = t1;
101
+ } else {
102
+ t1 = $[7];
103
+ }
104
+ firstDay = t1;
105
+ daysToDisplay = 1;
106
+ }
107
+ }
108
+ $[0] = currentDate;
109
+ $[1] = defaultFirstDay;
110
+ $[2] = user;
111
+ $[3] = view;
112
+ $[4] = daysToDisplay;
113
+ $[5] = firstDay;
114
+ } else {
115
+ daysToDisplay = $[4];
116
+ firstDay = $[5];
117
+ }
118
+ let t1;
119
+ if ($[8] !== currentDate || $[9] !== daysToDisplay || $[10] !== firstDay) {
120
+ t1 = [currentDate, firstDay, daysToDisplay];
121
+ $[8] = currentDate;
122
+ $[9] = daysToDisplay;
123
+ $[10] = firstDay;
124
+ $[11] = t1;
125
+ } else {
126
+ t1 = $[11];
127
+ }
128
+ return t1;
129
+}
130
+
131
+export const FIXTURE_ENTRYPOINT = {
132
+ fn: Calendar,
133
+ params: [
134
+ {
135
+ user: {},
136
+ defaultFirstDay: 1,
137
+ currentDate: { getDayOfWeek: () => 3 },
138
+ view: "week",
139
+ },
140
+ ],
141
+
142
+ sequentialRenders: [
143
+ {
144
+ user: {},
145
+ defaultFirstDay: 1,
146
+ currentDate: { getDayOfWeek: () => 3 },
147
+ view: "week",
148
+ },
149
+ {
150
+ user: {},
151
+ defaultFirstDay: 1,
152
+ currentDate: { getDayOfWeek: () => 3 },
153
+ view: "day",
154
+ },
155
+ ],
156
+};
157
+
158
+```
159
+
160
+### Eval output
161
+(kind: ok) [{"getDayOfWeek":"[[ function params=0 ]]"},1,5]
162
+[{"getDayOfWeek":"[[ function params=0 ]]"},3,1]
\ No newline at end of file