@alloy-js/core 0.1.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 (229) hide show
  1. package/LICENSE.txt +7 -0
  2. package/api-extractor.json +11 -0
  3. package/babel.config.cjs +4 -0
  4. package/dist/src/binder.d.ts +333 -0
  5. package/dist/src/binder.d.ts.map +1 -0
  6. package/dist/src/binder.js +444 -0
  7. package/dist/src/binder.js.map +1 -0
  8. package/dist/src/code.d.ts +3 -0
  9. package/dist/src/code.d.ts.map +1 -0
  10. package/dist/src/code.js +156 -0
  11. package/dist/src/code.js.map +1 -0
  12. package/dist/src/components/Declaration.d.ts +29 -0
  13. package/dist/src/components/Declaration.d.ts.map +1 -0
  14. package/dist/src/components/Declaration.js +47 -0
  15. package/dist/src/components/Declaration.js.map +1 -0
  16. package/dist/src/components/Indent.d.ts +13 -0
  17. package/dist/src/components/Indent.d.ts.map +1 -0
  18. package/dist/src/components/Indent.js +23 -0
  19. package/dist/src/components/Indent.js.map +1 -0
  20. package/dist/src/components/MemberDeclaration.d.ts +30 -0
  21. package/dist/src/components/MemberDeclaration.d.ts.map +1 -0
  22. package/dist/src/components/MemberDeclaration.js +52 -0
  23. package/dist/src/components/MemberDeclaration.js.map +1 -0
  24. package/dist/src/components/MemberName.d.ts +2 -0
  25. package/dist/src/components/MemberName.d.ts.map +1 -0
  26. package/dist/src/components/MemberName.js +11 -0
  27. package/dist/src/components/MemberName.js.map +1 -0
  28. package/dist/src/components/MemberScope.d.ts +27 -0
  29. package/dist/src/components/MemberScope.d.ts.map +1 -0
  30. package/dist/src/components/MemberScope.js +28 -0
  31. package/dist/src/components/MemberScope.js.map +1 -0
  32. package/dist/src/components/Name.d.ts +2 -0
  33. package/dist/src/components/Name.d.ts.map +1 -0
  34. package/dist/src/components/Name.js +11 -0
  35. package/dist/src/components/Name.js.map +1 -0
  36. package/dist/src/components/Output.d.ts +31 -0
  37. package/dist/src/components/Output.d.ts.map +1 -0
  38. package/dist/src/components/Output.js +44 -0
  39. package/dist/src/components/Output.js.map +1 -0
  40. package/dist/src/components/Scope.d.ts +10 -0
  41. package/dist/src/components/Scope.d.ts.map +1 -0
  42. package/dist/src/components/Scope.js +25 -0
  43. package/dist/src/components/Scope.js.map +1 -0
  44. package/dist/src/components/SourceDirectory.d.ts +7 -0
  45. package/dist/src/components/SourceDirectory.d.ts.map +1 -0
  46. package/dist/src/components/SourceDirectory.js +38 -0
  47. package/dist/src/components/SourceDirectory.js.map +1 -0
  48. package/dist/src/components/SourceFile.d.ts +12 -0
  49. package/dist/src/components/SourceFile.d.ts.map +1 -0
  50. package/dist/src/components/SourceFile.js +26 -0
  51. package/dist/src/components/SourceFile.js.map +1 -0
  52. package/dist/src/components/index.d.ts +11 -0
  53. package/dist/src/components/index.d.ts.map +1 -0
  54. package/dist/src/components/index.js +11 -0
  55. package/dist/src/components/index.js.map +1 -0
  56. package/dist/src/components/stc/index.d.ts +26 -0
  57. package/dist/src/components/stc/index.d.ts.map +1 -0
  58. package/dist/src/components/stc/index.js +9 -0
  59. package/dist/src/components/stc/index.js.map +1 -0
  60. package/dist/src/context/assignment.d.ts +39 -0
  61. package/dist/src/context/assignment.d.ts.map +1 -0
  62. package/dist/src/context/assignment.js +39 -0
  63. package/dist/src/context/assignment.js.map +1 -0
  64. package/dist/src/context/binder.d.ts +9 -0
  65. package/dist/src/context/binder.d.ts.map +1 -0
  66. package/dist/src/context/binder.js +12 -0
  67. package/dist/src/context/binder.js.map +1 -0
  68. package/dist/src/context/declaration.d.ts +4 -0
  69. package/dist/src/context/declaration.d.ts.map +1 -0
  70. package/dist/src/context/declaration.js +3 -0
  71. package/dist/src/context/declaration.js.map +1 -0
  72. package/dist/src/context/indent.d.ts +5 -0
  73. package/dist/src/context/indent.d.ts.map +1 -0
  74. package/dist/src/context/indent.js +8 -0
  75. package/dist/src/context/indent.js.map +1 -0
  76. package/dist/src/context/index.d.ts +11 -0
  77. package/dist/src/context/index.d.ts.map +1 -0
  78. package/dist/src/context/index.js +11 -0
  79. package/dist/src/context/index.js.map +1 -0
  80. package/dist/src/context/member-declaration.d.ts +9 -0
  81. package/dist/src/context/member-declaration.d.ts.map +1 -0
  82. package/dist/src/context/member-declaration.js +9 -0
  83. package/dist/src/context/member-declaration.js.map +1 -0
  84. package/dist/src/context/member-scope.d.ts +13 -0
  85. package/dist/src/context/member-scope.d.ts.map +1 -0
  86. package/dist/src/context/member-scope.js +12 -0
  87. package/dist/src/context/member-scope.js.map +1 -0
  88. package/dist/src/context/name-policy.d.ts +5 -0
  89. package/dist/src/context/name-policy.d.ts.map +1 -0
  90. package/dist/src/context/name-policy.js +10 -0
  91. package/dist/src/context/name-policy.js.map +1 -0
  92. package/dist/src/context/scope.d.ts +5 -0
  93. package/dist/src/context/scope.d.ts.map +1 -0
  94. package/dist/src/context/scope.js +6 -0
  95. package/dist/src/context/scope.js.map +1 -0
  96. package/dist/src/context/source-directory.d.ts +9 -0
  97. package/dist/src/context/source-directory.d.ts.map +1 -0
  98. package/dist/src/context/source-directory.js +3 -0
  99. package/dist/src/context/source-directory.js.map +1 -0
  100. package/dist/src/context/source-file.d.ts +12 -0
  101. package/dist/src/context/source-file.d.ts.map +1 -0
  102. package/dist/src/context/source-file.js +3 -0
  103. package/dist/src/context/source-file.js.map +1 -0
  104. package/dist/src/context.d.ts +13 -0
  105. package/dist/src/context.d.ts.map +1 -0
  106. package/dist/src/context.js +30 -0
  107. package/dist/src/context.js.map +1 -0
  108. package/dist/src/index.d.ts +13 -0
  109. package/dist/src/index.d.ts.map +1 -0
  110. package/dist/src/index.js +13 -0
  111. package/dist/src/index.js.map +1 -0
  112. package/dist/src/jsx-runtime.d.ts +43 -0
  113. package/dist/src/jsx-runtime.d.ts.map +1 -0
  114. package/dist/src/jsx-runtime.js +172 -0
  115. package/dist/src/jsx-runtime.js.map +1 -0
  116. package/dist/src/name-policy.d.ts +5 -0
  117. package/dist/src/name-policy.d.ts.map +1 -0
  118. package/dist/src/name-policy.js +8 -0
  119. package/dist/src/name-policy.js.map +1 -0
  120. package/dist/src/refkey.d.ts +9 -0
  121. package/dist/src/refkey.d.ts.map +1 -0
  122. package/dist/src/refkey.js +44 -0
  123. package/dist/src/refkey.js.map +1 -0
  124. package/dist/src/render.d.ts +147 -0
  125. package/dist/src/render.d.ts.map +1 -0
  126. package/dist/src/render.js +317 -0
  127. package/dist/src/render.js.map +1 -0
  128. package/dist/src/tsdoc-metadata.json +11 -0
  129. package/dist/src/utils.d.ts +80 -0
  130. package/dist/src/utils.d.ts.map +1 -0
  131. package/dist/src/utils.js +219 -0
  132. package/dist/src/utils.js.map +1 -0
  133. package/dist/test/children.test.d.ts +2 -0
  134. package/dist/test/children.test.d.ts.map +1 -0
  135. package/dist/test/components/source-file.test.d.ts +2 -0
  136. package/dist/test/components/source-file.test.d.ts.map +1 -0
  137. package/dist/test/name-policy.test.d.ts +2 -0
  138. package/dist/test/name-policy.test.d.ts.map +1 -0
  139. package/dist/test/reactivity/ref-rendering.test.d.ts +2 -0
  140. package/dist/test/reactivity/ref-rendering.test.d.ts.map +1 -0
  141. package/dist/test/reactivity/test.test.d.ts +2 -0
  142. package/dist/test/reactivity/test.test.d.ts.map +1 -0
  143. package/dist/test/refkey.test.d.ts +2 -0
  144. package/dist/test/refkey.test.d.ts.map +1 -0
  145. package/dist/test/rendering/basic.test.d.ts +2 -0
  146. package/dist/test/rendering/basic.test.d.ts.map +1 -0
  147. package/dist/test/rendering/code.test.d.ts +2 -0
  148. package/dist/test/rendering/code.test.d.ts.map +1 -0
  149. package/dist/test/rendering/indent.test.d.ts +2 -0
  150. package/dist/test/rendering/indent.test.d.ts.map +1 -0
  151. package/dist/test/rendering/linebreaks.test.d.ts +2 -0
  152. package/dist/test/rendering/linebreaks.test.d.ts.map +1 -0
  153. package/dist/test/rendering/refkeys.test.d.ts +2 -0
  154. package/dist/test/rendering/refkeys.test.d.ts.map +1 -0
  155. package/dist/test/stc.test.d.ts +2 -0
  156. package/dist/test/stc.test.d.ts.map +1 -0
  157. package/dist/test/symbols.test.d.ts +2 -0
  158. package/dist/test/symbols.test.d.ts.map +1 -0
  159. package/dist/test/utils.test.d.ts +2 -0
  160. package/dist/test/utils.test.d.ts.map +1 -0
  161. package/dist/testing/extend-expect.d.ts +2 -0
  162. package/dist/testing/extend-expect.d.ts.map +1 -0
  163. package/dist/testing/extend-expect.js +22 -0
  164. package/dist/testing/extend-expect.js.map +1 -0
  165. package/dist/testing/index.d.ts +3 -0
  166. package/dist/testing/index.d.ts.map +1 -0
  167. package/dist/testing/index.js +3 -0
  168. package/dist/testing/index.js.map +1 -0
  169. package/dist/testing/render.d.ts +7 -0
  170. package/dist/testing/render.d.ts.map +1 -0
  171. package/dist/testing/render.js +25 -0
  172. package/dist/testing/render.js.map +1 -0
  173. package/dist/testing/vitest.d.js +1 -0
  174. package/dist/testing/vitest.d.js.map +1 -0
  175. package/dist/tsconfig.tsbuildinfo +1 -0
  176. package/package.json +64 -0
  177. package/src/binder.ts +838 -0
  178. package/src/code.ts +220 -0
  179. package/src/components/Declaration.tsx +53 -0
  180. package/src/components/Indent.tsx +33 -0
  181. package/src/components/MemberDeclaration.tsx +62 -0
  182. package/src/components/MemberName.tsx +11 -0
  183. package/src/components/MemberScope.tsx +40 -0
  184. package/src/components/Name.tsx +11 -0
  185. package/src/components/Output.tsx +69 -0
  186. package/src/components/Scope.tsx +27 -0
  187. package/src/components/SourceDirectory.tsx +43 -0
  188. package/src/components/SourceFile.tsx +33 -0
  189. package/src/components/index.tsx +10 -0
  190. package/src/components/stc/index.ts +9 -0
  191. package/src/context/assignment.ts +57 -0
  192. package/src/context/binder.ts +14 -0
  193. package/src/context/declaration.ts +5 -0
  194. package/src/context/indent.ts +10 -0
  195. package/src/context/index.ts +10 -0
  196. package/src/context/member-declaration.ts +10 -0
  197. package/src/context/member-scope.ts +17 -0
  198. package/src/context/name-policy.ts +13 -0
  199. package/src/context/scope.ts +8 -0
  200. package/src/context/source-directory.ts +11 -0
  201. package/src/context/source-file.ts +12 -0
  202. package/src/context.ts +53 -0
  203. package/src/index.ts +21 -0
  204. package/src/jsx-runtime.ts +266 -0
  205. package/src/name-policy.ts +13 -0
  206. package/src/refkey.ts +62 -0
  207. package/src/render.ts +389 -0
  208. package/src/utils.ts +288 -0
  209. package/temp/api.json +8840 -0
  210. package/test/children.test.tsx +33 -0
  211. package/test/components/source-file.test.tsx +45 -0
  212. package/test/name-policy.test.tsx +19 -0
  213. package/test/reactivity/ref-rendering.test.tsx +50 -0
  214. package/test/reactivity/test.test.tsx +83 -0
  215. package/test/refkey.test.ts +32 -0
  216. package/test/rendering/basic.test.tsx +156 -0
  217. package/test/rendering/code.test.tsx +62 -0
  218. package/test/rendering/indent.test.tsx +608 -0
  219. package/test/rendering/linebreaks.test.tsx +72 -0
  220. package/test/rendering/refkeys.test.tsx +35 -0
  221. package/test/stc.test.tsx +21 -0
  222. package/test/symbols.test.ts +406 -0
  223. package/test/utils.test.tsx +150 -0
  224. package/testing/extend-expect.ts +20 -0
  225. package/testing/index.ts +2 -0
  226. package/testing/render.ts +37 -0
  227. package/testing/vitest.d.ts +10 -0
  228. package/tsconfig.json +17 -0
  229. package/vitest.config.ts +18 -0
@@ -0,0 +1,608 @@
1
+ // prettier-ignore
2
+ import { Indent } from "@alloy-js/core";
3
+ import { describe, expect, it } from "vitest";
4
+ import "../../testing/extend-expect.js";
5
+
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
+ it("indents explicitly indented content on a subsequent line", () => {
14
+ expect(<>
15
+ one
16
+ <Indent>hi</Indent>
17
+ </>).toRenderTo("one\n hi");
18
+ });
19
+
20
+ it("indents explicitly indented content", () => {
21
+ expect(
22
+ <>
23
+ one
24
+ <Indent>
25
+ hi
26
+ bye
27
+ </Indent>
28
+ </>,
29
+ ).toRenderTo(`
30
+ one
31
+ hi
32
+ bye
33
+ `);
34
+ });
35
+
36
+ it("indents memos", () => {
37
+ function getValue() {
38
+ return "hi";
39
+ }
40
+
41
+ expect(
42
+ <>
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
+ </>,
56
+ ).toRenderTo(`
57
+ base
58
+ hi
59
+ hi
60
+ bye
61
+ bye
62
+ hi
63
+ `);
64
+ });
65
+
66
+ it("doesn't indent components on the same line with explicit indent", () => {
67
+ function Foo() {
68
+ return "Foo";
69
+ }
70
+
71
+ expect(
72
+ <>
73
+ base
74
+ <Indent>
75
+ <Foo /><Foo />
76
+ </Indent>
77
+ </>,
78
+ ).toRenderTo(`
79
+ base
80
+ FooFoo
81
+ `);
82
+ });
83
+
84
+ it("works with nested indents", () => {
85
+ expect(
86
+ <>
87
+ base
88
+ <Indent>
89
+ 1
90
+ 2
91
+ <Indent>
92
+ 3
93
+ 4
94
+ <Indent>
95
+ 5
96
+ 6
97
+ </Indent>
98
+ 7
99
+ 8
100
+ </Indent>
101
+ 9
102
+ 10
103
+ </Indent>
104
+ 11
105
+ 12
106
+ </>,
107
+ ).toRenderTo(`
108
+ base
109
+ 1
110
+ 2
111
+ 3
112
+ 4
113
+ 5
114
+ 6
115
+ 7
116
+ 8
117
+ 9
118
+ 10
119
+ 11
120
+ 12
121
+ `);
122
+ });
123
+ });
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,72 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import "../../testing/extend-expect.js";
3
+
4
+ describe("empty lines are preserved", () => {
5
+ it("fragment", () => {
6
+ const frag = <>
7
+ hi
8
+
9
+ </>;
10
+
11
+ expect(<>
12
+ { frag }
13
+ hi
14
+ </>).toRenderTo(`
15
+ hi
16
+
17
+ hi
18
+ `);
19
+ });
20
+
21
+ it("memo for fragment", () => {
22
+ const frag = <>
23
+ hi
24
+
25
+ </>;
26
+ function getTrue() {
27
+ return true;
28
+ }
29
+
30
+ expect(<>
31
+ { getTrue() ? frag : undefined }
32
+ hi
33
+ </>).toRenderTo(`
34
+ hi
35
+
36
+ hi
37
+ `);
38
+ });
39
+
40
+ it("after components", () => {
41
+ function Foo() {
42
+ return "hi";
43
+ }
44
+
45
+ expect(<>
46
+ <Foo />
47
+
48
+ hi
49
+ </>).toRenderTo(`
50
+ hi
51
+
52
+ hi
53
+ `);
54
+ });
55
+ });
56
+
57
+ // this would be a nice feature to have
58
+ describe.skip("empty lines are removed when the only thing on the line is a falsy value", () => {
59
+ it("false", () => {
60
+ expect(<>
61
+ {false}
62
+ hi
63
+ </>).toRenderTo("hi");
64
+ });
65
+
66
+ it("undefined", () => {
67
+ expect(<>
68
+ {undefined}
69
+ hi
70
+ </>).toRenderTo("hi");
71
+ });
72
+ });
@@ -0,0 +1,35 @@
1
+ import { refkey, Refkey } from "@alloy-js/core";
2
+ import { SourceFile } from "@alloy-js/core/stc";
3
+ import { expect, it } from "vitest";
4
+ import "../../testing/extend-expect.js";
5
+
6
+ it("is rendered properly in the tree", () => {
7
+ const key = refkey("foo");
8
+
9
+ function Reference(props: { refkey: Refkey }) {
10
+ expect(props.refkey).toEqual(key);
11
+ return "Reference";
12
+ }
13
+
14
+ expect(
15
+ <SourceFile filetype="typescript" path="foo.ts" reference={Reference}>
16
+ {key}
17
+ </SourceFile>,
18
+ ).toRenderTo("Reference");
19
+ });
20
+
21
+ it("is rendered properly in the tree with code", () => {
22
+ const key = refkey("foo");
23
+
24
+ function Reference(props: { refkey: Refkey }) {
25
+ expect(props.refkey).toEqual(key);
26
+ return "Reference";
27
+ }
28
+
29
+ expect(
30
+ SourceFile({ filetype: "typescript", path: "foo.ts", reference: Reference })
31
+ .code`
32
+ ${key}
33
+ `,
34
+ ).toRenderTo("Reference");
35
+ });
@@ -0,0 +1,21 @@
1
+ import { code, Indent, stc } from "@alloy-js/core";
2
+ import { expect, it } from "vitest";
3
+ import "../testing/extend-expect.js";
4
+
5
+ it("is applied by output", () => {
6
+ function Foo() {
7
+ return "Foo component";
8
+ }
9
+ const FooStc = stc(Foo);
10
+ const IndentStc = stc(Indent);
11
+
12
+ expect(code`
13
+ ${FooStc({ x: "hi" })}
14
+ ${IndentStc().code`
15
+ child!
16
+ `}
17
+ `).toRenderTo(`
18
+ Foo component
19
+ child!
20
+ `);
21
+ });