@alloy-js/core 0.4.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (228) hide show
  1. package/CHANGELOG.md +53 -0
  2. package/babel.config.cjs +4 -1
  3. package/dist/src/binder.d.ts +20 -13
  4. package/dist/src/binder.d.ts.map +1 -1
  5. package/dist/src/binder.js +33 -15
  6. package/dist/src/binder.js.map +1 -1
  7. package/dist/src/code.d.ts +2 -2
  8. package/dist/src/code.d.ts.map +1 -1
  9. package/dist/src/code.js +4 -4
  10. package/dist/src/code.js.map +1 -1
  11. package/dist/src/components/Block.d.ts +25 -0
  12. package/dist/src/components/Block.d.ts.map +1 -0
  13. package/dist/src/components/Block.js +25 -0
  14. package/dist/src/components/Block.js.map +1 -0
  15. package/dist/src/components/Declaration.d.ts +1 -1
  16. package/dist/src/components/Declaration.d.ts.map +1 -1
  17. package/dist/src/components/Declaration.js +4 -0
  18. package/dist/src/components/Declaration.js.map +1 -1
  19. package/dist/src/components/For.d.ts +44 -0
  20. package/dist/src/components/For.d.ts.map +1 -0
  21. package/dist/src/components/For.js +41 -0
  22. package/dist/src/components/For.js.map +1 -0
  23. package/dist/src/components/Indent.d.ts +6 -10
  24. package/dist/src/components/Indent.d.ts.map +1 -1
  25. package/dist/src/components/Indent.js +7 -18
  26. package/dist/src/components/Indent.js.map +1 -1
  27. package/dist/src/components/List.d.ts +38 -0
  28. package/dist/src/components/List.d.ts.map +1 -0
  29. package/dist/src/components/List.js +40 -0
  30. package/dist/src/components/List.js.map +1 -0
  31. package/dist/src/components/MemberDeclaration.d.ts +1 -1
  32. package/dist/src/components/MemberDeclaration.d.ts.map +1 -1
  33. package/dist/src/components/MemberDeclaration.js.map +1 -1
  34. package/dist/src/components/MemberName.d.ts +1 -1
  35. package/dist/src/components/MemberName.d.ts.map +1 -1
  36. package/dist/src/components/MemberName.js +1 -1
  37. package/dist/src/components/MemberName.js.map +1 -1
  38. package/dist/src/components/MemberScope.d.ts +1 -1
  39. package/dist/src/components/MemberScope.d.ts.map +1 -1
  40. package/dist/src/components/MemberScope.js.map +1 -1
  41. package/dist/src/components/Name.d.ts +1 -1
  42. package/dist/src/components/Name.d.ts.map +1 -1
  43. package/dist/src/components/Name.js +1 -1
  44. package/dist/src/components/Name.js.map +1 -1
  45. package/dist/src/components/Output.d.ts +3 -2
  46. package/dist/src/components/Output.d.ts.map +1 -1
  47. package/dist/src/components/Output.js +12 -2
  48. package/dist/src/components/Output.js.map +1 -1
  49. package/dist/src/components/Scope.d.ts +1 -1
  50. package/dist/src/components/Scope.d.ts.map +1 -1
  51. package/dist/src/components/Scope.js.map +1 -1
  52. package/dist/src/components/Show.d.ts +8 -0
  53. package/dist/src/components/Show.d.ts.map +1 -0
  54. package/dist/src/components/Show.js +4 -0
  55. package/dist/src/components/Show.js.map +1 -0
  56. package/dist/src/components/SourceDirectory.d.ts +2 -2
  57. package/dist/src/components/SourceDirectory.d.ts.map +1 -1
  58. package/dist/src/components/SourceDirectory.js +1 -0
  59. package/dist/src/components/SourceDirectory.js.map +1 -1
  60. package/dist/src/components/SourceFile.d.ts +4 -8
  61. package/dist/src/components/SourceFile.d.ts.map +1 -1
  62. package/dist/src/components/SourceFile.js +6 -13
  63. package/dist/src/components/SourceFile.js.map +1 -1
  64. package/dist/src/components/StatementList.d.ts +9 -0
  65. package/dist/src/components/StatementList.d.ts.map +1 -0
  66. package/dist/src/components/StatementList.js +17 -0
  67. package/dist/src/components/StatementList.js.map +1 -0
  68. package/dist/src/components/Switch.d.ts +41 -0
  69. package/dist/src/components/Switch.d.ts.map +1 -0
  70. package/dist/src/components/Switch.js +41 -0
  71. package/dist/src/components/Switch.js.map +1 -0
  72. package/dist/src/components/Wrap.d.ts +20 -0
  73. package/dist/src/components/Wrap.d.ts.map +1 -0
  74. package/dist/src/components/Wrap.js +15 -0
  75. package/dist/src/components/Wrap.js.map +1 -0
  76. package/dist/src/components/index.d.ts +8 -1
  77. package/dist/src/components/index.d.ts.map +1 -1
  78. package/dist/src/components/index.js +7 -0
  79. package/dist/src/components/index.js.map +1 -1
  80. package/dist/src/components/stc/index.d.ts +89 -18
  81. package/dist/src/components/stc/index.d.ts.map +1 -1
  82. package/dist/src/components/stc/index.js +17 -1
  83. package/dist/src/components/stc/index.js.map +1 -1
  84. package/dist/src/context/index.d.ts +0 -1
  85. package/dist/src/context/index.d.ts.map +1 -1
  86. package/dist/src/context/index.js +0 -1
  87. package/dist/src/context/index.js.map +1 -1
  88. package/dist/src/context/member-declaration.d.ts +1 -0
  89. package/dist/src/context/member-declaration.d.ts.map +1 -1
  90. package/dist/src/context/member-declaration.js +4 -1
  91. package/dist/src/context/member-declaration.js.map +1 -1
  92. package/dist/src/context.d.ts.map +1 -1
  93. package/dist/src/context.js +3 -3
  94. package/dist/src/context.js.map +1 -1
  95. package/dist/src/index.browser.d.ts +3 -0
  96. package/dist/src/index.browser.d.ts.map +1 -0
  97. package/dist/src/index.browser.js +3 -0
  98. package/dist/src/index.browser.js.map +1 -0
  99. package/dist/src/index.d.ts +2 -0
  100. package/dist/src/index.d.ts.map +1 -1
  101. package/dist/src/index.js +2 -0
  102. package/dist/src/index.js.map +1 -1
  103. package/dist/src/jsx-runtime.d.ts +151 -7
  104. package/dist/src/jsx-runtime.d.ts.map +1 -1
  105. package/dist/src/jsx-runtime.js +113 -12
  106. package/dist/src/jsx-runtime.js.map +1 -1
  107. package/dist/src/render.d.ts +107 -132
  108. package/dist/src/render.d.ts.map +1 -1
  109. package/dist/src/render.js +272 -178
  110. package/dist/src/render.js.map +1 -1
  111. package/dist/src/stc.d.ts +14 -0
  112. package/dist/src/stc.d.ts.map +1 -0
  113. package/dist/src/stc.js +52 -0
  114. package/dist/src/stc.js.map +1 -0
  115. package/dist/src/tap.d.ts +19 -0
  116. package/dist/src/tap.d.ts.map +1 -0
  117. package/dist/src/tap.js +39 -0
  118. package/dist/src/tap.js.map +1 -0
  119. package/dist/src/utils.d.ts +22 -15
  120. package/dist/src/utils.d.ts.map +1 -1
  121. package/dist/src/utils.js +95 -59
  122. package/dist/src/utils.js.map +1 -1
  123. package/dist/test/browser-build.test.d.ts +2 -0
  124. package/dist/test/browser-build.test.d.ts.map +1 -0
  125. package/dist/test/components/block.test.d.ts +2 -0
  126. package/dist/test/components/block.test.d.ts.map +1 -0
  127. package/dist/test/components/declaration.test.d.ts +2 -0
  128. package/dist/test/components/declaration.test.d.ts.map +1 -0
  129. package/dist/test/components/list.test.d.ts +2 -0
  130. package/dist/test/components/list.test.d.ts.map +1 -0
  131. package/dist/test/components/wrap.test.d.ts +2 -0
  132. package/dist/test/components/wrap.test.d.ts.map +1 -0
  133. package/dist/test/control-flow/for.test.d.ts +2 -0
  134. package/dist/test/control-flow/for.test.d.ts.map +1 -0
  135. package/dist/test/control-flow/match.test.d.ts +2 -0
  136. package/dist/test/control-flow/match.test.d.ts.map +1 -0
  137. package/dist/test/control-flow/show.test.d.ts +2 -0
  138. package/dist/test/control-flow/show.test.d.ts.map +1 -0
  139. package/dist/test/reactivity/cleanup.test.d.ts +2 -0
  140. package/dist/test/reactivity/cleanup.test.d.ts.map +1 -0
  141. package/dist/test/reactivity/memo.test.d.ts +2 -0
  142. package/dist/test/reactivity/memo.test.d.ts.map +1 -0
  143. package/dist/test/reactivity/untrack.test.d.ts +2 -0
  144. package/dist/test/reactivity/untrack.test.d.ts.map +1 -0
  145. package/dist/test/rendering/formatting.test.d.ts +2 -0
  146. package/dist/test/rendering/formatting.test.d.ts.map +1 -0
  147. package/dist/test/rendering/memoization.test.d.ts +2 -0
  148. package/dist/test/rendering/memoization.test.d.ts.map +1 -0
  149. package/dist/test/split-props.test.d.ts +2 -0
  150. package/dist/test/split-props.test.d.ts.map +1 -0
  151. package/dist/test/stc.test.d.ts.map +1 -1
  152. package/dist/test/utils.test.d.ts.map +1 -1
  153. package/dist/testing/extend-expect.js +4 -4
  154. package/dist/testing/extend-expect.js.map +1 -1
  155. package/dist/testing/render.d.ts +2 -3
  156. package/dist/testing/render.d.ts.map +1 -1
  157. package/dist/testing/render.js +2 -4
  158. package/dist/testing/render.js.map +1 -1
  159. package/dist/tsconfig.tsbuildinfo +1 -1
  160. package/package.json +8 -9
  161. package/src/binder.ts +60 -50
  162. package/src/code.ts +17 -12
  163. package/src/components/Block.tsx +44 -0
  164. package/src/components/Declaration.tsx +10 -4
  165. package/src/components/For.tsx +81 -0
  166. package/src/components/Indent.tsx +20 -27
  167. package/src/components/List.tsx +94 -0
  168. package/src/components/MemberDeclaration.tsx +9 -6
  169. package/src/components/MemberScope.tsx +4 -2
  170. package/src/components/Output.tsx +27 -14
  171. package/src/components/Scope.tsx +4 -2
  172. package/src/components/Show.tsx +11 -0
  173. package/src/components/SourceDirectory.tsx +6 -2
  174. package/src/components/SourceFile.tsx +13 -17
  175. package/src/components/StatementList.tsx +16 -0
  176. package/src/components/Switch.tsx +62 -0
  177. package/src/components/Wrap.tsx +29 -0
  178. package/src/components/index.tsx +8 -1
  179. package/src/components/stc/index.ts +18 -1
  180. package/src/context/index.ts +0 -1
  181. package/src/context/member-declaration.ts +9 -1
  182. package/src/context.ts +2 -3
  183. package/src/index.browser.ts +2 -0
  184. package/src/index.ts +2 -0
  185. package/src/jsx-runtime.ts +265 -23
  186. package/src/render.ts +382 -200
  187. package/src/stc.ts +95 -0
  188. package/src/tap.ts +69 -0
  189. package/src/utils.ts +162 -95
  190. package/temp/api.json +8042 -1886
  191. package/test/browser-build.test.ts +91 -0
  192. package/test/children.test.tsx +8 -10
  193. package/test/components/block.test.tsx +48 -0
  194. package/test/components/declaration.test.tsx +37 -0
  195. package/test/components/list.test.tsx +91 -0
  196. package/test/components/slot.test.tsx +31 -25
  197. package/test/components/source-file.test.tsx +11 -31
  198. package/test/components/wrap.test.tsx +42 -0
  199. package/test/control-flow/for.test.tsx +194 -0
  200. package/test/control-flow/match.test.tsx +49 -0
  201. package/test/control-flow/show.test.tsx +25 -0
  202. package/test/name-policy.test.tsx +5 -5
  203. package/test/reactivity/cleanup.test.tsx +91 -0
  204. package/test/reactivity/memo.test.tsx +17 -0
  205. package/test/reactivity/ref-rendering.test.tsx +3 -8
  206. package/test/reactivity/test.test.tsx +7 -6
  207. package/test/reactivity/untrack.test.ts +33 -0
  208. package/test/rendering/basic.test.tsx +25 -47
  209. package/test/rendering/code.test.tsx +3 -3
  210. package/test/rendering/formatting.test.tsx +487 -0
  211. package/test/rendering/indent.test.tsx +42 -529
  212. package/test/rendering/memoization.test.tsx +30 -0
  213. package/test/split-props.test.ts +87 -0
  214. package/test/stc.test.tsx +29 -8
  215. package/test/symbols.test.ts +132 -3
  216. package/test/utils.test.tsx +129 -20
  217. package/testing/extend-expect.ts +14 -4
  218. package/testing/render.ts +2 -4
  219. package/testing/vitest.d.ts +6 -1
  220. package/vitest.config.ts +1 -1
  221. package/dist/src/context/indent.d.ts +0 -5
  222. package/dist/src/context/indent.d.ts.map +0 -1
  223. package/dist/src/context/indent.js +0 -8
  224. package/dist/src/context/indent.js.map +0 -1
  225. package/dist/test/rendering/linebreaks.test.d.ts +0 -2
  226. package/dist/test/rendering/linebreaks.test.d.ts.map +0 -1
  227. package/src/context/indent.ts +0 -17
  228. package/test/rendering/linebreaks.test.tsx +0 -72
@@ -4,17 +4,13 @@ import { describe, expect, it } from "vitest";
4
4
  import "../../testing/extend-expect.js";
5
5
 
6
6
  describe("Indent component", () => {
7
- it("indents explicitly indented content on a single line", () => {
8
- expect(<>
9
- one<Indent>hi</Indent>
10
- </>).toRenderTo("onehi");
11
- });
12
-
13
7
  it("indents explicitly indented content on a subsequent line", () => {
14
- expect(<>
15
- one
16
- <Indent>hi</Indent>
17
- </>).toRenderTo("one\n hi");
8
+ expect(
9
+ <>
10
+ one
11
+ <Indent>hi</Indent>
12
+ </>,
13
+ ).toRenderTo("one\n hi");
18
14
  });
19
15
 
20
16
  it("indents explicitly indented content", () => {
@@ -23,6 +19,7 @@ describe("Indent component", () => {
23
19
  one
24
20
  <Indent>
25
21
  hi
22
+ <hbr />
26
23
  bye
27
24
  </Indent>
28
25
  </>,
@@ -40,19 +37,19 @@ describe("Indent component", () => {
40
37
 
41
38
  expect(
42
39
  <>
43
- base
44
- <Indent>
45
- {getValue()}
46
- </Indent>
47
- <Indent>
48
- {getValue()}
49
- bye
50
- </Indent>
51
- <Indent>
52
- bye
53
- {getValue()}
54
- </Indent>
55
- </>,
40
+ base
41
+ <Indent>{getValue()}</Indent>
42
+ <Indent>
43
+ {getValue()}
44
+ <hbr />
45
+ bye
46
+ </Indent>
47
+ <Indent>
48
+ bye
49
+ <hbr />
50
+ {getValue()}
51
+ </Indent>
52
+ </>,
56
53
  ).toRenderTo(`
57
54
  base
58
55
  hi
@@ -70,11 +67,12 @@ describe("Indent component", () => {
70
67
 
71
68
  expect(
72
69
  <>
73
- base
74
- <Indent>
75
- <Foo /><Foo />
76
- </Indent>
77
- </>,
70
+ base
71
+ <Indent>
72
+ <Foo />
73
+ <Foo />
74
+ </Indent>
75
+ </>,
78
76
  ).toRenderTo(`
79
77
  base
80
78
  FooFoo
@@ -84,26 +82,26 @@ describe("Indent component", () => {
84
82
  it("works with nested indents", () => {
85
83
  expect(
86
84
  <>
87
- base
88
- <Indent>
89
- 1
90
- 2
85
+ base
91
86
  <Indent>
92
- 3
93
- 4
87
+ 1<hbr />2
94
88
  <Indent>
95
- 5
96
- 6
89
+ 3<hbr />4
90
+ <Indent>
91
+ 5<hbr />6
92
+ </Indent>
93
+ <hbr />
94
+ 7<hbr />8
97
95
  </Indent>
98
- 7
99
- 8
96
+ <hbr />
97
+ 9<hbr />
98
+ 10
100
99
  </Indent>
101
- 9
102
- 10
103
- </Indent>
104
- 11
105
- 12
106
- </>,
100
+ <hbr />
101
+ 11
102
+ <hbr />
103
+ 12
104
+ </>,
107
105
  ).toRenderTo(`
108
106
  base
109
107
  1
@@ -121,488 +119,3 @@ describe("Indent component", () => {
121
119
  `);
122
120
  });
123
121
  });
124
-
125
- describe("implicit indenting", () => {
126
- it("indents implicitly indented components", () => {
127
- function Foo() {
128
- return <>
129
- hi
130
- bye
131
- </>;
132
- }
133
-
134
- expect(<>
135
- one
136
- <Foo />
137
- </>).toRenderTo(`
138
- one
139
- hi
140
- bye
141
- `);
142
- });
143
-
144
- it("indents memo substitutions with line breaks properly", () => {
145
- function getStr() {
146
- return "a\nb";
147
- }
148
- expect(<>
149
- base
150
- {getStr()}
151
- </>).toRenderTo(`
152
- base
153
- a
154
- b
155
- `);
156
- });
157
-
158
- it("indents multiple implicitly indented components", () => {
159
- function Foo() {
160
- return <>
161
- hi
162
- bye
163
- </>;
164
- }
165
-
166
- expect(
167
- <>
168
- one
169
- <Foo />
170
- <Foo />
171
-
172
- two
173
- <Foo />
174
- <Foo />
175
- </>,
176
- ).toRenderTo(`
177
- one
178
- hi
179
- bye
180
- hi
181
- bye
182
-
183
- two
184
- hi
185
- bye
186
- hi
187
- bye
188
- `);
189
- });
190
-
191
- it("implictly indents memos", () => {
192
- function Foo() {
193
- return "Foo";
194
- }
195
- const hi = "const hi";
196
- function getHi() {
197
- return "getHi";
198
- }
199
-
200
- expect(
201
- <>
202
- base
203
- {getHi()}
204
- base {hi}
205
- {getHi()}
206
- base {getHi()}
207
- {getHi()}
208
- base <Foo />
209
- {getHi()}
210
- </>,
211
- ).toRenderTo(`
212
- base
213
- getHi
214
- base const hi
215
- getHi
216
- base getHi
217
- getHi
218
- base Foo
219
- getHi
220
- `);
221
- });
222
-
223
- it("implictly indents consts", () => {
224
- function Foo() {
225
- return "Foo";
226
- }
227
- const hi = "const hi";
228
- function getHi() {
229
- return "getHi";
230
- }
231
-
232
- function ArrComponent() {
233
- return [<Foo />, <Foo />];
234
- }
235
-
236
- const arr = [<Foo />, <Foo />];
237
-
238
- expect(
239
- <>
240
- base
241
- {hi}
242
- base {hi}
243
- {hi}
244
- base {getHi()}
245
- {hi}
246
- base <Foo />
247
- {hi}
248
- base <ArrComponent />
249
- {hi}
250
- base {arr}
251
- {hi}
252
- </>,
253
- ).toRenderTo(`
254
- base
255
- const hi
256
- base const hi
257
- const hi
258
- base getHi
259
- const hi
260
- base Foo
261
- const hi
262
- base FooFoo
263
- const hi
264
- base FooFoo
265
- const hi
266
- `);
267
- });
268
-
269
- it("indents children", () => {
270
- function Foo(props: any) {
271
- return <>
272
- a
273
- {props.children}
274
- b
275
- </>;
276
- }
277
-
278
- function getChild() {
279
- return "hi";
280
- }
281
- expect(
282
- <>
283
- base
284
- <Foo>
285
- child
286
- {getChild()}
287
- </Foo>
288
- </>,
289
- ).toRenderTo(`
290
- base
291
- a
292
- child
293
- hi
294
- b
295
- `);
296
- });
297
-
298
- it("implicity indents within children", () => {
299
- function Foo(props: any) {
300
- return <>
301
- a
302
- {props.children}
303
- b
304
- </>;
305
- }
306
-
307
- function getChild() {
308
- return "hi";
309
- }
310
- expect(
311
- <>
312
- base
313
- <Foo>
314
- child
315
- {getChild()}
316
- </Foo>
317
- </>,
318
- ).toRenderTo(`
319
- base
320
- a
321
- child
322
- hi
323
- b
324
- `);
325
- });
326
-
327
- it("doesn't indent things on the same line", () => {
328
- const str = "str";
329
- function getStr() {
330
- return "getstr";
331
- }
332
- function Foo() {
333
- return "Foo";
334
- }
335
- expect(
336
- <>
337
- base
338
- {str} {getStr()}
339
- item <Foo /> <Foo />
340
- {str} {getStr()}
341
- item <Foo /> <Foo />
342
- </>,
343
- ).toRenderTo(`
344
- base
345
- str getstr
346
- item Foo Foo
347
- str getstr
348
- item Foo Foo
349
- `);
350
- });
351
- });
352
-
353
- describe("array handling", () => {
354
- it("handles a simple array", () => {
355
- const simpleArray = [<>hi</>];
356
- expect(<>
357
- a
358
- {simpleArray}
359
- b
360
- </>).toRenderTo(`
361
- a
362
- hi
363
- b
364
- `);
365
- });
366
-
367
- it("handles indented simple array", () => {
368
- const simpleArray = [<>hi</>];
369
- expect(<>
370
- a
371
- {simpleArray}
372
- b
373
- </>).toRenderTo(`
374
- a
375
- hi
376
- b
377
- `);
378
- });
379
-
380
- it("handles indented simple array with line breaks", () => {
381
- const val = "hi";
382
- function getHi() {
383
- return "getHi";
384
- }
385
- const arr = [<>{val}</>, "\n", <>{getHi()}</>];
386
- expect(<>
387
- a
388
- {arr}
389
- b
390
- </>).toRenderTo(`
391
- a
392
- hi
393
- getHi
394
- b
395
- `);
396
- });
397
-
398
- it("handles indented component array", () => {
399
- function Foo() {
400
- return "Foo";
401
- }
402
- const arr = [<Foo />, <Foo />];
403
- expect(<>
404
- a
405
- {arr}
406
- b
407
- </>).toRenderTo(`
408
- a
409
- FooFoo
410
- b
411
- `);
412
- });
413
-
414
- it("handles indented component array with line breaks", () => {
415
- function Foo() {
416
- return "Foo";
417
- }
418
- const arr = [<Foo />, "\n", <Foo />];
419
- expect(<>
420
- a
421
- {arr}
422
- b
423
- </>).toRenderTo(`
424
- a
425
- Foo
426
- Foo
427
- b
428
- `);
429
- });
430
-
431
- it("indents arrays of components (map scenario)", () => {
432
- function Foo() {
433
- return <>
434
- a
435
- b
436
- </>;
437
- }
438
-
439
- function Bar() {
440
- return <>
441
- c
442
- d
443
- </>;
444
- }
445
-
446
- const foos = [<Foo />, "\n", <Bar />];
447
-
448
- expect(<>
449
- base
450
- {foos}
451
- </>).toRenderTo(`
452
- base
453
- a
454
- b
455
- c
456
- d
457
- `);
458
- });
459
-
460
- it("handles arrays of components with children", () => {
461
- function Foo(props: any) {
462
- return <>
463
- hi
464
- {props.children}
465
- {props.children}
466
- </>;
467
- }
468
-
469
- const arr = [
470
- <Foo>
471
- a
472
- b
473
- </Foo>,
474
- "\n",
475
- <Foo>
476
- c
477
- d
478
- </Foo>,
479
- ];
480
-
481
- expect(<>
482
- base
483
- {arr}
484
- {arr}
485
- </>).toRenderTo(`
486
- base
487
- hi
488
- a
489
- b
490
- a
491
- b
492
- hi
493
- c
494
- d
495
- c
496
- d
497
- hi
498
- a
499
- b
500
- a
501
- b
502
- hi
503
- c
504
- d
505
- c
506
- d
507
- `);
508
- });
509
- });
510
-
511
- it("doesn't indent things on the same line simple", () => {
512
- const str = "str";
513
- function getStr() {
514
- return "getstr";
515
- }
516
- function Foo() {
517
- return "Foo";
518
- }
519
- const array = [<>{getStr()} {getStr()}</>];
520
- expect(
521
- <>
522
- base
523
- <Indent>
524
- {str} {getStr()}
525
- {array}
526
- <Foo /> {str} {getStr()}
527
- </Indent>
528
- </>,
529
- ).toRenderTo(`
530
- base
531
- str getstr
532
- getstr getstr
533
- Foo str getstr
534
- `);
535
- });
536
-
537
- describe("Children rendering", () => {
538
- it("handles children via props.children", () => {
539
- function Foo(props: any) {
540
- return <>
541
- a
542
- {props.children}
543
- d
544
- </>;
545
- }
546
-
547
- expect(<>
548
- base
549
- <Foo>
550
- b
551
- c
552
- </Foo>
553
- </>)
554
- .toRenderTo(`
555
- base
556
- a
557
- b
558
- c
559
- d
560
- `);
561
- });
562
-
563
- it("handles children via destructured children", () => {
564
- function Foo({ children }: any) {
565
- return <>
566
- a
567
- {children}
568
- d
569
- </>;
570
- }
571
-
572
- expect(<>
573
- base
574
- <Foo>
575
- b
576
- c
577
- </Foo>
578
- </>)
579
- .toRenderTo(`
580
- base
581
- a
582
- b
583
- c
584
- d
585
- `);
586
- });
587
-
588
- it("handles children via returning children", () => {
589
- function Foo({ children }: any) {
590
- return children;
591
- }
592
-
593
- expect(<>
594
- base
595
- <Foo>
596
- b
597
- c
598
- </Foo>
599
- </>)
600
- .toRenderTo(`
601
- base
602
- b
603
- c
604
- `);
605
- });
606
-
607
- it("can place children on a single line", () => {});
608
- });
@@ -0,0 +1,30 @@
1
+ import { memo } from "@alloy-js/core/jsx-runtime";
2
+ import { ref } from "@vue/reactivity";
3
+ import { expect, it } from "vitest";
4
+ import { renderTree } from "../../src/render.js";
5
+
6
+ it("memoizes child components", () => {
7
+ let renderCount = 0;
8
+ function Child() {
9
+ renderCount++;
10
+ return "hi " + String(Math.random());
11
+ }
12
+
13
+ const doThing = ref();
14
+ const child1 = <Child />;
15
+ const child2 = <Child />;
16
+ const items = memo(() => {
17
+ const list = [child1];
18
+ if (doThing.value) {
19
+ list.push(child2);
20
+ }
21
+
22
+ return list;
23
+ });
24
+
25
+ const template = <>{items}</>;
26
+
27
+ renderTree(template);
28
+ doThing.value = true;
29
+ expect(renderCount).toBe(2);
30
+ });
@@ -0,0 +1,87 @@
1
+ import { effect, reactive } from "@vue/reactivity";
2
+ import { expect, it, vi } from "vitest";
3
+ import { splitProps } from "../src/jsx-runtime.js";
4
+
5
+ it("splits regular object props", () => {
6
+ const props = {
7
+ a: 1,
8
+ b: 2,
9
+ c: 3,
10
+ };
11
+
12
+ const [ab, rest] = splitProps(props, ["a", "b"]);
13
+
14
+ expect(ab).toEqual({ a: 1, b: 2 });
15
+ expect(rest).toEqual({ c: 3 });
16
+ });
17
+
18
+ it("splits props with getters without invoking them", () => {
19
+ const getterA = vi.fn(() => 1);
20
+ const getterB = vi.fn(() => 2);
21
+ const props = {
22
+ get a() {
23
+ return getterA();
24
+ },
25
+ get b() {
26
+ return getterB();
27
+ },
28
+ c: 3,
29
+ };
30
+
31
+ const [ab, rest] = splitProps(props, ["a", "b"]);
32
+
33
+ expect(getterA).not.toHaveBeenCalled();
34
+ expect(getterB).not.toHaveBeenCalled();
35
+
36
+ expect(ab.a).toBe(1);
37
+ expect(getterA).toHaveBeenCalledTimes(1);
38
+ expect(ab.b).toBe(2);
39
+ expect(getterB).toHaveBeenCalledTimes(1);
40
+
41
+ expect(rest).toEqual({ c: 3 });
42
+ });
43
+
44
+ it("splits reactive props without observing them initially", () => {
45
+ const props = reactive({
46
+ a: 1,
47
+ b: 2,
48
+ c: 3,
49
+ });
50
+
51
+ const [ab, rest] = splitProps(props, ["a", "b"]);
52
+
53
+ expect(ab.a).toBe(1);
54
+ expect(ab.b).toBe(2);
55
+ expect(rest.c).toBe(3);
56
+ });
57
+
58
+ it("ensures effect is not triggered by splitProps but by accessing reactive props", () => {
59
+ const props = reactive({
60
+ a: 1,
61
+ b: 2,
62
+ c: 3,
63
+ });
64
+
65
+ let splits: any;
66
+ const splitEffect = vi.fn(() => {
67
+ splits = splitProps(props, ["a", "b"]);
68
+ });
69
+
70
+ effect(splitEffect);
71
+ expect(splitEffect).toHaveBeenCalledTimes(1);
72
+
73
+ const observeEffect = vi.fn(() => {
74
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
75
+ splits[0].a;
76
+ });
77
+ effect(observeEffect);
78
+ expect(observeEffect).toHaveBeenCalledTimes(1);
79
+
80
+ props.a = 2;
81
+ expect(splitEffect).toHaveBeenCalledTimes(1);
82
+ expect(observeEffect).toHaveBeenCalledTimes(2);
83
+
84
+ splits[0].a = 3;
85
+ expect(splitEffect).toHaveBeenCalledTimes(1);
86
+ expect(observeEffect).toHaveBeenCalledTimes(3);
87
+ });