2
## Input
3
4
```javascript
5
-// @Out DefUseGraph
5
function Component(props) {
6
const items = props.items;
7
const maxItems = props.maxItems;
9
const renderedItems = [];
10
const seen = new Set();
11
const max = Math.max(0, maxItems);
13
- for (const item of items) {
12
+ for (let i = 0; i < items.length; i += 1) {
13
+ const item = items.at(i);
14
if (item == null || seen.has(item)) {
15
continue;
16
}
35
36
```
37
bb0:
38
- [1] Const mutate items$27_@0 = read props$26.items
39
- [2] Const mutate maxItems$28_@1 = read props$26.maxItems
40
- [3] Const mutate renderedItems$29_@2[3:22] = Array []
41
- [4] Const mutate seen$30_@3[0:19] = New mutate Set$6_@3()
42
- [5] Const mutate $31_@4 = 0
43
- [6] Const mutate max$32_@5[0:7] = Call mutate Math$8_@5.max(read $31_@4, read maxItems$28_@1)
44
- [7] Goto bb1
45
-bb1:
46
- predecessor blocks: bb0 bb5 bb10
47
- [8] If (read items$27_@0) then:bb3 else:bb2 fallthrough=bb2
38
+ [1] Const mutate items$30_@0 = read props$29.items
39
+ [2] Const mutate maxItems$31_@1 = read props$29.maxItems
40
+ [3] Const mutate renderedItems$32_@2[3:33] = Array []
41
+ [4] Const mutate seen$33_@2[3:33] = New mutate Set$6()
42
+ [5] Const mutate $34_@4 = 0
43
+ [6] Const mutate max$35_@5 = Call mutate Math$8.max(read $34_@4, read maxItems$31_@1)
44
+ [7] For init=bb3 test=bb1 loop=bb5 update=bb4 fallthrough=bb2
45
bb3:
46
+ predecessor blocks: bb0
47
+ [8] Let mutate i$36_@2[3:33] = 0
48
+ [9] Goto bb1
49
+bb1:
50
+ predecessor blocks: bb3 bb4
51
+ [10] Const mutate $39_@2[3:33] = Binary read i$36_@2 < read items$30_@0.length
52
+ [11] If (read $39_@2) then:bb5 else:bb2 fallthrough=bb2
53
+bb5:
54
predecessor blocks: bb1
50
- [9] Const mutate $34_@6 = null
51
- [10] Const mutate $36_@3[0:19] = Binary read item$10_@3 == read $34_@6
52
- [11] Let mutate $37_@3[0:19] = undefined
53
- [11] If (read $36_@3) then:bb8 else:bb9 fallthrough=bb7
54
-bb8:
55
- predecessor blocks: bb3
56
- [12] Const mutate $37_@3[0:19] = read $36_@3
57
- [13] Goto bb7
55
+ [12] Const mutate item$40_@2[3:33] = Call read items$30_@0.at(read i$36_@2)
56
+ [13] Const mutate $41_@6 = null
57
+ [14] Const mutate $42_@2[3:33] = Binary read item$40_@2 == read $41_@6
58
+ [15] Let mutate $43_@2[3:33] = undefined
59
+ [15] If (read $42_@2) then:bb10 else:bb11 fallthrough=bb9
60
+bb10:
61
+ predecessor blocks: bb5
62
+ [16] Const mutate $43_@2[3:33] = read $42_@2
63
+ [17] Goto bb9
64
+bb11:
65
+ predecessor blocks: bb5
66
+ [18] Const mutate $43_@2[3:33] = Call mutate seen$33_@2.has(mutate item$40_@2)
67
+ [19] Goto bb9
68
bb9:
59
- predecessor blocks: bb3
60
- [14] Const mutate $37_@3[0:19] = Call mutate seen$30_@3.has(mutate item$10_@3)
61
- [15] Goto bb7
69
+ predecessor blocks: bb10 bb11
70
+ [20] If (read $43_@2) then:bb7 else:bb6 fallthrough=bb6
71
bb7:
63
- predecessor blocks: bb8 bb9
64
- [16] If (read $37_@3) then:bb5 else:bb4 fallthrough=bb4
65
-bb5:
66
- predecessor blocks: bb7
67
- [17] Goto(Continue) bb1
72
+ predecessor blocks: bb9
73
+ [21] Goto(Continue) bb4
74
+bb6:
75
+ predecessor blocks: bb9
76
+ [22] Call mutate seen$33_@2.add(mutate item$40_@2)
77
+ [23] Const mutate $49_@7 = "div"
78
+ [24] Const mutate $50_@8 = JSX <read $49_@7>{freeze item$40_@2}</read $49_@7>
79
+ [25] Call mutate renderedItems$32_@2.push(read $50_@8)
80
+ [26] Const mutate $55_@9 = Binary read renderedItems$32_@2.length >= read max$35_@5
81
+ [27] If (read $55_@9) then:bb2 else:bb12 fallthrough=bb12
82
+bb12:
83
+ predecessor blocks: bb6
84
+ [28] Goto(Continue) bb4
85
bb4:
69
- predecessor blocks: bb7
70
- [18] Call mutate seen$30_@3.add(mutate item$10_@3)
71
- [19] Const mutate $43_@7 = "div"
72
- [20] Const mutate $44_@8 = JSX <read $43_@7>{read item$10_@3}</read $43_@7>
73
- [21] Call mutate renderedItems$29_@2.push(read $44_@8)
74
- [22] Const mutate $49_@9 = Binary read renderedItems$29_@2.length >= read max$32_@5
75
- [23] If (read $49_@9) then:bb2 else:bb10 fallthrough=bb10
76
-bb10:
77
- predecessor blocks: bb4
78
- [24] Goto(Continue) bb1
86
+ predecessor blocks: bb7 bb12
87
+ [29] Const mutate $56_@2[3:33] = 1
88
+ [30] Reassign mutate i$36_@2[3:33] = Binary read i$36_@2 + read $56_@2
89
+ [31] read i$36_@2
90
+ [32] Goto bb1
91
bb2:
80
- predecessor blocks: bb4 bb1
81
- [25] Const mutate count$52_@10 = read renderedItems$29_@2.length
82
- [26] Const mutate $53_@11 = "div"
83
- [27] Const mutate $54_@12 = "\n "
84
- [28] Const mutate $55_@13 = "h1"
85
- [29] Const mutate $56_@14 = " Items"
86
- [30] Const mutate $57_@15 = JSX <read $55_@13>{freeze count$52_@10}{read $56_@14}</read $55_@13>
87
- [31] Const mutate $58_@16 = "\n "
88
- [32] Const mutate $59_@17 = "\n "
89
- [33] Const mutate $60_@18 = JSX <read $53_@11>{read $54_@12}{read $57_@15}{read $58_@16}{freeze renderedItems$29_@2}{read $59_@17}</read $53_@11>
90
- [34] Return read $60_@18
92
+ predecessor blocks: bb6 bb1
93
+ [33] Const mutate count$66_@11 = read renderedItems$32_@2.length
94
+ [34] Const mutate $67_@12 = "div"
95
+ [35] Const mutate $68_@13 = "\n "
96
+ [36] Const mutate $69_@14 = "h1"
97
+ [37] Const mutate $70_@15 = " Items"
98
+ [38] Const mutate $71_@16 = JSX <read $69_@14>{freeze count$66_@11}{read $70_@15}</read $69_@14>
99
+ [39] Const mutate $72_@17 = "\n "
100
+ [40] Const mutate $73_@18 = "\n "
101
+ [41] Const mutate $74_@19 = JSX <read $67_@12>{read $68_@13}{read $71_@16}{read $72_@17}{freeze renderedItems$32_@2}{read $73_@18}</read $67_@12>
102
+ [42] Return read $74_@19
103
scope0 [1:2]:
92
- - dependency: read props$26.items
104
+ - dependency: read props$29.items
105
scope1 [2:3]:
94
- - dependency: read props$26.maxItems
106
+ - dependency: read props$29.maxItems
107
+scope5 [6:7]:
108
+ - dependency: read $34_@4
109
+ - dependency: read maxItems$31_@1
110
+scope8 [24:25]:
111
+ - dependency: read $49_@7
112
+scope9 [26:27]:
113
+ - dependency: read max$35_@5
114
+scope11 [33:34]:
115
+ - dependency: read renderedItems$32_@2.length
116
+scope16 [38:39]:
117
+ - dependency: read $69_@14
118
+ - dependency: freeze count$66_@11
119
+ - dependency: read $70_@15
120
+scope19 [41:42]:
121
+ - dependency: read $67_@12
122
+ - dependency: read $68_@13
123
+ - dependency: read $71_@16
124
+ - dependency: read $72_@17
125
+ - dependency: freeze renderedItems$32_@2
126
+ - dependency: read $73_@18
127
+```
128
+
129
+## Reactive Scopes
130
+
131
+```
132
+function Component(
133
+ props,
134
+) {
135
+ [1] Const mutate items$30_@0 = read props$29.items
136
+ [2] Const mutate maxItems$31_@1 = read props$29.maxItems
137
+ scope @2 [3:33] deps=[] {
138
+ [3] Const mutate renderedItems$32_@2[3:33] = Array []
139
+ [4] Const mutate seen$33_@2[3:33] = New mutate Set$6()
140
+ [5] Const mutate $34_@4 = 0
141
+ scope @5 [6:7] deps=[read $34_@4, read maxItems$31_@1] {
142
+ [6] Const mutate max$35_@5 = Call mutate Math$8.max(read $34_@4, read maxItems$31_@1)
143
+ }
144
+ for (
145
+ [8] Let mutate i$36_@2[3:33] = 0
146
+ ;
147
+ [10] Const mutate $39_@2[3:33] = Binary read i$36_@2 < read items$30_@0.length
148
+ read $39_@2
149
+ ;
150
+ [29] Const mutate $56_@2[3:33] = 1
151
+ [30] Reassign mutate i$36_@2[3:33] = Binary read i$36_@2 + read $56_@2
152
+ read i$36_@2
153
+ ) {
154
+ [12] Const mutate item$40_@2[3:33] = Call read items$30_@0.at(read i$36_@2)
155
+ [13] Const mutate $41_@6 = null
156
+ [14] Const mutate $42_@2[3:33] = Binary read item$40_@2 == read $41_@6
157
+ [15] Let mutate $43_@2[3:33] = undefined
158
+ if (read $42_@2) {
159
+ [16] Const mutate $43_@2[3:33] = read $42_@2
160
+ } else {
161
+ [18] Const mutate $43_@2[3:33] = Call mutate seen$33_@2.has(mutate item$40_@2)
162
+ }
163
+ if (read $43_@2) {
164
+ continue
165
+ }
166
+ [22] Call mutate seen$33_@2.add(mutate item$40_@2)
167
+ [23] Const mutate $49_@7 = "div"
168
+ scope @8 [24:25] deps=[read $49_@7] {
169
+ [24] Const mutate $50_@8 = JSX <read $49_@7>{freeze item$40_@2}</read $49_@7>
170
+ }
171
+ [25] Call mutate renderedItems$32_@2.push(read $50_@8)
172
+ [26] Const mutate $55_@9 = Binary read renderedItems$32_@2.length >= read max$35_@5
173
+ if (read $55_@9) {
174
+ break
175
+ }
176
+ }
177
+ }
178
+ [33] Const mutate count$66_@11 = read renderedItems$32_@2.length
179
+ [34] Const mutate $67_@12 = "div"
180
+ [35] Const mutate $68_@13 = "\n "
181
+ [36] Const mutate $69_@14 = "h1"
182
+ [37] Const mutate $70_@15 = " Items"
183
+ scope @16 [38:39] deps=[read $69_@14, freeze count$66_@11, read $70_@15] {
184
+ [38] Const mutate $71_@16 = JSX <read $69_@14>{freeze count$66_@11}{read $70_@15}</read $69_@14>
185
+ }
186
+ [39] Const mutate $72_@17 = "\n "
187
+ [40] Const mutate $73_@18 = "\n "
188
+ scope @19 [41:42] deps=[read $67_@12, read $68_@13, read $71_@16, read $72_@17, freeze renderedItems$32_@2, read $73_@18] {
189
+ [41] Const mutate $74_@19 = JSX <read $67_@12>{read $68_@13}{read $71_@16}{read $72_@17}{freeze renderedItems$32_@2}{read $73_@18}</read $67_@12>
190
+ }
191
+ return read $74_@19
192
+}
193
+
194
```
195
196
### CFG
200
%% Basic Blocks
201
subgraph bb0
202
bb0_instrs["
104
- [1] Const mutate items$27_@0 = read props$26.items
105
- [2] Const mutate maxItems$28_@1 = read props$26.maxItems
106
- [3] Const mutate renderedItems$29_@2[3:22] = Array []
107
- [4] Const mutate seen$30_@3[0:19] = New mutate Set$6_@3()
108
- [5] Const mutate $31_@4 = 0
109
- [6] Const mutate max$32_@5[0:7] = Call mutate Math$8_@5.max(read $31_@4, read maxItems$28_@1)
203
+ [1] Const mutate items$30_@0 = read props$29.items
204
+ [2] Const mutate maxItems$31_@1 = read props$29.maxItems
205
+ [3] Const mutate renderedItems$32_@2[3:33] = Array []
206
+ [4] Const mutate seen$33_@2[3:33] = New mutate Set$6()
207
+ [5] Const mutate $34_@4 = 0
208
+ [6] Const mutate max$35_@5 = Call mutate Math$8.max(read $34_@4, read maxItems$31_@1)
209
"]
111
- bb0_instrs --> bb0_terminal(["Goto"])
112
- end
113
- subgraph bb1
114
- bb1_terminal(["If (read items$27_@0)"])
210
+ bb0_instrs --> bb0_terminal(["For"])
211
end
212
subgraph bb3
213
bb3_instrs["
118
- [9] Const mutate $34_@6 = null
119
- [10] Const mutate $36_@3[0:19] = Binary read item$10_@3 == read $34_@6
120
- [11] Let mutate $37_@3[0:19] = undefined
214
+ [8] Let mutate i$36_@2[3:33] = 0
215
"]
122
- bb3_instrs --> bb3_terminal(["If (read $36_@3)"])
216
+ bb3_instrs --> bb3_terminal(["Goto"])
217
end
124
- subgraph bb8
125
- bb8_instrs["
126
- [12] Const mutate $37_@3[0:19] = read $36_@3
218
+ subgraph bb1
219
+ bb1_instrs["
220
+ [10] Const mutate $39_@2[3:33] = Binary read i$36_@2 < read items$30_@0.length
221
"]
128
- bb8_instrs --> bb8_terminal(["Goto"])
222
+ bb1_instrs --> bb1_terminal(["If (read $39_@2)"])
223
end
130
- subgraph bb9
131
- bb9_instrs["
132
- [14] Const mutate $37_@3[0:19] = Call mutate seen$30_@3.has(mutate item$10_@3)
224
+ subgraph bb5
225
+ bb5_instrs["
226
+ [12] Const mutate item$40_@2[3:33] = Call read items$30_@0.at(read i$36_@2)
227
+ [13] Const mutate $41_@6 = null
228
+ [14] Const mutate $42_@2[3:33] = Binary read item$40_@2 == read $41_@6
229
+ [15] Let mutate $43_@2[3:33] = undefined
230
+ "]
231
+ bb5_instrs --> bb5_terminal(["If (read $42_@2)"])
232
+ end
233
+ subgraph bb10
234
+ bb10_instrs["
235
+ [16] Const mutate $43_@2[3:33] = read $42_@2
236
"]
134
- bb9_instrs --> bb9_terminal(["Goto"])
237
+ bb10_instrs --> bb10_terminal(["Goto"])
238
+ end
239
+ subgraph bb11
240
+ bb11_instrs["
241
+ [18] Const mutate $43_@2[3:33] = Call mutate seen$33_@2.has(mutate item$40_@2)
242
+ "]
243
+ bb11_instrs --> bb11_terminal(["Goto"])
244
+ end
245
+ subgraph bb9
246
+ bb9_terminal(["If (read $43_@2)"])
247
end
248
subgraph bb7
137
- bb7_terminal(["If (read $37_@3)"])
249
+ bb7_terminal(["Goto"])
250
end
139
- subgraph bb5
140
- bb5_terminal(["Goto"])
251
+ subgraph bb6
252
+ bb6_instrs["
253
+ [22] Call mutate seen$33_@2.add(mutate item$40_@2)
254
+ [23] Const mutate $49_@7 = 'div'
255
+ [24] Const mutate $50_@8 = JSX <read $49_@7>{freeze item$40_@2}</read $49_@7>
256
+ [25] Call mutate renderedItems$32_@2.push(read $50_@8)
257
+ [26] Const mutate $55_@9 = Binary read renderedItems$32_@2.length >= read max$35_@5
258
+ "]
259
+ bb6_instrs --> bb6_terminal(["If (read $55_@9)"])
260
+ end
261
+ subgraph bb12
262
+ bb12_terminal(["Goto"])
263
end
264
subgraph bb4
265
bb4_instrs["
144
- [18] Call mutate seen$30_@3.add(mutate item$10_@3)
145
- [19] Const mutate $43_@7 = 'div'
146
- [20] Const mutate $44_@8 = JSX <read $43_@7>{read item$10_@3}</read $43_@7>
147
- [21] Call mutate renderedItems$29_@2.push(read $44_@8)
148
- [22] Const mutate $49_@9 = Binary read renderedItems$29_@2.length >= read max$32_@5
266
+ [29] Const mutate $56_@2[3:33] = 1
267
+ [30] Reassign mutate i$36_@2[3:33] = Binary read i$36_@2 + read $56_@2
268
+ [31] read i$36_@2
269
"]
150
- bb4_instrs --> bb4_terminal(["If (read $49_@9)"])
151
- end
152
- subgraph bb10
153
- bb10_terminal(["Goto"])
270
+ bb4_instrs --> bb4_terminal(["Goto"])
271
end
272
subgraph bb2
273
bb2_instrs["
157
- [25] Const mutate count$52_@10 = read renderedItems$29_@2.length
158
- [26] Const mutate $53_@11 = 'div'
159
- [27] Const mutate $54_@12 = '\n '
160
- [28] Const mutate $55_@13 = 'h1'
161
- [29] Const mutate $56_@14 = ' Items'
162
- [30] Const mutate $57_@15 = JSX <read $55_@13>{freeze count$52_@10}{read $56_@14}</read $55_@13>
163
- [31] Const mutate $58_@16 = '\n '
164
- [32] Const mutate $59_@17 = '\n '
165
- [33] Const mutate $60_@18 = JSX <read $53_@11>{read $54_@12}{read $57_@15}{read $58_@16}{freeze renderedItems$29_@2}{read $59_@17}</read $53_@11>
274
+ [33] Const mutate count$66_@11 = read renderedItems$32_@2.length
275
+ [34] Const mutate $67_@12 = 'div'
276
+ [35] Const mutate $68_@13 = '\n '
277
+ [36] Const mutate $69_@14 = 'h1'
278
+ [37] Const mutate $70_@15 = ' Items'
279
+ [38] Const mutate $71_@16 = JSX <read $69_@14>{freeze count$66_@11}{read $70_@15}</read $69_@14>
280
+ [39] Const mutate $72_@17 = '\n '
281
+ [40] Const mutate $73_@18 = '\n '
282
+ [41] Const mutate $74_@19 = JSX <read $67_@12>{read $68_@13}{read $71_@16}{read $72_@17}{freeze renderedItems$32_@2}{read $73_@18}</read $67_@12>
283
"]
167
- bb2_instrs --> bb2_terminal(["Return read $60_@18"])
284
+ bb2_instrs --> bb2_terminal(["Return read $74_@19"])
285
end
286
287
%% Jumps
171
- bb0_terminal --> bb1
172
- bb1_terminal -- "then" --> bb3
288
+ bb0_terminal -- "init" --> bb3
289
+ bb0_terminal -- "test" --> bb1
290
+ bb0_terminal -- "update" --> bb4
291
+ bb0_terminal -- "loop" --> bb5
292
+ bb0_terminal -- "fallthrough" --> bb2
293
+ bb3_terminal --> bb1
294
+ bb1_terminal -- "then" --> bb5
295
bb1_terminal -- "else" --> bb2
174
- bb3_terminal -- "then" --> bb8
175
- bb3_terminal -- "else" --> bb9
176
- bb3_terminal -- "fallthrough" --> bb7
177
- bb8_terminal --> bb7
178
- bb9_terminal --> bb7
179
- bb7_terminal -- "then" --> bb5
180
- bb7_terminal -- "else" --> bb4
181
- bb5_terminal --> bb1
182
- bb4_terminal -- "then" --> bb2
183
- bb4_terminal -- "else" --> bb10
184
- bb10_terminal --> bb1
296
+ bb5_terminal -- "then" --> bb10
297
+ bb5_terminal -- "else" --> bb11
298
+ bb5_terminal -- "fallthrough" --> bb9
299
+ bb10_terminal --> bb9
300
+ bb11_terminal --> bb9
301
+ bb9_terminal -- "then" --> bb7
302
+ bb9_terminal -- "else" --> bb6
303
+ bb7_terminal --> bb4
304
+ bb6_terminal -- "then" --> bb2
305
+ bb6_terminal -- "else" --> bb12
306
+ bb12_terminal --> bb4
307
+ bb4_terminal --> bb1
308
309
```
310
311
## Code
312
313
```javascript
191
-function Component$0(props$26) {
192
- const items$27 = props$26.items;
193
- const maxItems$28 = props$26.maxItems;
194
- const renderedItems$29 = [];
195
- const seen$30 = new Set$6();
196
- const max$32 = Math$8.max(0, maxItems$28);
314
+function Component$0(props$29) {
315
+ const items$30 = props$29.items;
316
+ const maxItems$31 = props$29.maxItems;
317
+ const renderedItems$32 = [];
318
+ const seen$33 = new Set$6();
319
+ const max$35 = Math$8.max(0, maxItems$31);
320
+ bb2: for (let i$36 = 0; i$36 < items$30.length; i$36 = i$36 + 1, i$36) {
321
+ const item$40 = items$30.at(i$36);
322
+
323
+ bb9: if (item$40 == null) {
324
+ } else {
325
+ }
326
+
327
+ bb6: if (seen$33.has(item$40)) {
328
+ continue;
329
+ }
330
+
331
+ seen$33.add(item$40);
332
+ renderedItems$32.push(<div>{item$40}</div>);
333
+
334
+ bb12: if (renderedItems$32.length >= max$35) {
335
+ break;
336
+ }
337
+ }
338
+
339
+ const count$66 = renderedItems$32.length;
340
+ return (
341
+ <div>
342
+ {<h1>{count$66} Items</h1>}
343
+ {renderedItems$32}
344
+ </div>
345
+ );
346
}
347
348
```