@alloy-js/core 0.10.0 → 0.12.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 (183) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/dist/src/binder.d.ts.map +1 -1
  3. package/dist/src/binder.js +100 -19
  4. package/dist/src/code.js +1 -2
  5. package/dist/src/components/Block.js +2 -5
  6. package/dist/src/components/Declaration.js +2 -4
  7. package/dist/src/components/For.d.ts +2 -2
  8. package/dist/src/components/For.d.ts.map +1 -1
  9. package/dist/src/components/For.js +1 -2
  10. package/dist/src/components/Indent.js +2 -4
  11. package/dist/src/components/List.js +2 -5
  12. package/dist/src/components/MemberDeclaration.js +2 -4
  13. package/dist/src/components/MemberName.js +1 -2
  14. package/dist/src/components/MemberScope.js +2 -4
  15. package/dist/src/components/Name.js +1 -2
  16. package/dist/src/components/Output.js +2 -4
  17. package/dist/src/components/Prose.js +1 -2
  18. package/dist/src/components/ReferenceOrContent.d.ts +8 -0
  19. package/dist/src/components/ReferenceOrContent.d.ts.map +1 -0
  20. package/dist/src/components/ReferenceOrContent.js +11 -0
  21. package/dist/src/components/Scope.js +2 -4
  22. package/dist/src/components/Show.js +1 -2
  23. package/dist/src/components/SourceDirectory.js +2 -4
  24. package/dist/src/components/SourceFile.js +2 -5
  25. package/dist/src/components/StatementList.js +2 -4
  26. package/dist/src/components/Switch.d.ts +1 -1
  27. package/dist/src/components/Switch.d.ts.map +1 -1
  28. package/dist/src/components/Switch.js +1 -2
  29. package/dist/src/components/Wrap.js +2 -4
  30. package/dist/src/components/index.d.ts +1 -0
  31. package/dist/src/components/index.d.ts.map +1 -1
  32. package/dist/src/components/index.js +2 -2
  33. package/dist/src/components/stc/index.d.ts +1 -0
  34. package/dist/src/components/stc/index.d.ts.map +1 -1
  35. package/dist/src/components/stc/index.js +2 -2
  36. package/dist/src/components/stc/sti.js +1 -2
  37. package/dist/src/context/assignment.js +1 -2
  38. package/dist/src/context/binder.js +1 -2
  39. package/dist/src/context/declaration.js +1 -2
  40. package/dist/src/context/index.js +1 -2
  41. package/dist/src/context/member-declaration.js +1 -2
  42. package/dist/src/context/member-scope.js +1 -2
  43. package/dist/src/context/name-policy.js +1 -2
  44. package/dist/src/context/scope.js +1 -2
  45. package/dist/src/context/source-directory.js +1 -2
  46. package/dist/src/context/source-file.js +1 -2
  47. package/dist/src/context.js +1 -2
  48. package/dist/src/debug.js +13 -15
  49. package/dist/src/index.browser.js +1 -2
  50. package/dist/src/index.js +1 -2
  51. package/dist/src/jsx-runtime.d.ts +1 -1
  52. package/dist/src/jsx-runtime.d.ts.map +1 -1
  53. package/dist/src/jsx-runtime.js +10 -5
  54. package/dist/src/name-policy.js +1 -2
  55. package/dist/src/refkey.js +1 -2
  56. package/dist/src/render.d.ts.map +1 -1
  57. package/dist/src/render.js +6 -2
  58. package/dist/src/scheduler.d.ts +8 -0
  59. package/dist/src/scheduler.d.ts.map +1 -0
  60. package/dist/src/scheduler.js +17 -0
  61. package/dist/src/slot.js +1 -2
  62. package/dist/src/stc.js +1 -2
  63. package/dist/src/sti.js +1 -2
  64. package/dist/src/tap.js +1 -2
  65. package/dist/src/tsdoc-metadata.json +1 -1
  66. package/dist/src/utils.js +2 -4
  67. package/dist/src/write-output.browser.js +1 -2
  68. package/dist/src/write-output.js +1 -2
  69. package/dist/test/browser-build.test.js +85 -0
  70. package/dist/test/children.test.js +27 -0
  71. package/dist/test/components/block.test.js +45 -0
  72. package/dist/test/components/declaration.test.js +32 -0
  73. package/dist/test/components/list.test.js +86 -0
  74. package/dist/test/components/prose.test.js +25 -0
  75. package/dist/test/components/reference-or-content.test.d.ts +2 -0
  76. package/dist/test/components/reference-or-content.test.d.ts.map +1 -0
  77. package/dist/test/components/reference-or-content.test.js +149 -0
  78. package/dist/test/components/slot.test.js +134 -0
  79. package/dist/test/components/source-file.test.js +64 -0
  80. package/dist/test/components/wrap.test.js +35 -0
  81. package/dist/test/control-flow/for.test.js +219 -0
  82. package/dist/test/control-flow/match.test.js +67 -0
  83. package/dist/test/control-flow/show.test.js +29 -0
  84. package/dist/test/name-policy.test.js +19 -0
  85. package/dist/test/props-with-defaults.test.js +93 -0
  86. package/dist/test/reactivity/circular-reactives.test.d.ts +2 -0
  87. package/dist/test/reactivity/circular-reactives.test.d.ts.map +1 -0
  88. package/dist/test/reactivity/circular-reactives.test.js +31 -0
  89. package/dist/test/reactivity/cleanup.test.js +82 -0
  90. package/dist/test/reactivity/memo.test.js +16 -0
  91. package/dist/test/reactivity/ref-rendering.test.js +37 -0
  92. package/dist/test/reactivity/test.test.js +61 -0
  93. package/dist/test/reactivity/untrack.test.js +26 -0
  94. package/dist/test/refkey.test.js +25 -0
  95. package/dist/test/rendering/basic.test.js +96 -0
  96. package/dist/test/rendering/code.test.js +55 -0
  97. package/dist/test/rendering/formatting.test.js +402 -0
  98. package/dist/test/rendering/indent.test.js +90 -0
  99. package/dist/test/rendering/memoization.test.js +27 -0
  100. package/dist/test/rendering/refkeys.test.js +32 -0
  101. package/dist/test/split-props.test.js +77 -0
  102. package/dist/test/stc.test.js +34 -0
  103. package/dist/test/symbols.test.js +877 -0
  104. package/dist/test/utils.test.d.ts.map +1 -1
  105. package/dist/test/utils.test.js +223 -0
  106. package/dist/testing/extend-expect.js +1 -2
  107. package/dist/testing/index.js +1 -2
  108. package/dist/testing/render.js +1 -2
  109. package/dist/tsconfig.tsbuildinfo +1 -1
  110. package/package.json +14 -22
  111. package/src/binder.ts +100 -17
  112. package/src/components/For.tsx +6 -6
  113. package/src/components/ReferenceOrContent.tsx +22 -0
  114. package/src/components/index.tsx +1 -0
  115. package/src/components/stc/index.ts +1 -0
  116. package/src/debug.ts +12 -13
  117. package/src/jsx-runtime.ts +24 -14
  118. package/src/render.ts +5 -0
  119. package/src/scheduler.ts +24 -0
  120. package/temp/api.json +216 -15
  121. package/test/components/declaration.test.tsx +2 -0
  122. package/test/components/list.test.tsx +0 -1
  123. package/test/components/reference-or-content.test.tsx +138 -0
  124. package/test/control-flow/for.test.tsx +34 -4
  125. package/test/reactivity/circular-reactives.test.tsx +32 -0
  126. package/test/reactivity/cleanup.test.tsx +5 -0
  127. package/test/reactivity/untrack.test.ts +3 -0
  128. package/test/rendering/memoization.test.tsx +2 -0
  129. package/test/symbols.test.ts +392 -13
  130. package/test/utils.test.tsx +2 -0
  131. package/babel.config.cjs +0 -4
  132. package/dist/src/binder.js.map +0 -1
  133. package/dist/src/code.js.map +0 -1
  134. package/dist/src/components/Block.js.map +0 -1
  135. package/dist/src/components/Declaration.js.map +0 -1
  136. package/dist/src/components/For.js.map +0 -1
  137. package/dist/src/components/Indent.js.map +0 -1
  138. package/dist/src/components/List.js.map +0 -1
  139. package/dist/src/components/MemberDeclaration.js.map +0 -1
  140. package/dist/src/components/MemberName.js.map +0 -1
  141. package/dist/src/components/MemberScope.js.map +0 -1
  142. package/dist/src/components/Name.js.map +0 -1
  143. package/dist/src/components/Output.js.map +0 -1
  144. package/dist/src/components/Prose.js.map +0 -1
  145. package/dist/src/components/Scope.js.map +0 -1
  146. package/dist/src/components/Show.js.map +0 -1
  147. package/dist/src/components/SourceDirectory.js.map +0 -1
  148. package/dist/src/components/SourceFile.js.map +0 -1
  149. package/dist/src/components/StatementList.js.map +0 -1
  150. package/dist/src/components/Switch.js.map +0 -1
  151. package/dist/src/components/Wrap.js.map +0 -1
  152. package/dist/src/components/index.js.map +0 -1
  153. package/dist/src/components/stc/index.js.map +0 -1
  154. package/dist/src/components/stc/sti.js.map +0 -1
  155. package/dist/src/context/assignment.js.map +0 -1
  156. package/dist/src/context/binder.js.map +0 -1
  157. package/dist/src/context/declaration.js.map +0 -1
  158. package/dist/src/context/index.js.map +0 -1
  159. package/dist/src/context/member-declaration.js.map +0 -1
  160. package/dist/src/context/member-scope.js.map +0 -1
  161. package/dist/src/context/name-policy.js.map +0 -1
  162. package/dist/src/context/scope.js.map +0 -1
  163. package/dist/src/context/source-directory.js.map +0 -1
  164. package/dist/src/context/source-file.js.map +0 -1
  165. package/dist/src/context.js.map +0 -1
  166. package/dist/src/debug.js.map +0 -1
  167. package/dist/src/index.browser.js.map +0 -1
  168. package/dist/src/index.js.map +0 -1
  169. package/dist/src/jsx-runtime.js.map +0 -1
  170. package/dist/src/name-policy.js.map +0 -1
  171. package/dist/src/refkey.js.map +0 -1
  172. package/dist/src/render.js.map +0 -1
  173. package/dist/src/slot.js.map +0 -1
  174. package/dist/src/stc.js.map +0 -1
  175. package/dist/src/sti.js.map +0 -1
  176. package/dist/src/tap.js.map +0 -1
  177. package/dist/src/utils.js.map +0 -1
  178. package/dist/src/write-output.browser.js.map +0 -1
  179. package/dist/src/write-output.js.map +0 -1
  180. package/dist/testing/extend-expect.js.map +0 -1
  181. package/dist/testing/index.js.map +0 -1
  182. package/dist/testing/render.js.map +0 -1
  183. package/dist/testing/vitest.d.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"utils.test.d.ts","sourceRoot":"","sources":["../../test/utils.test.tsx"],"names":[],"mappings":"AAKA,OAAO,6BAA6B,CAAC"}
1
+ {"version":3,"file":"utils.test.d.ts","sourceRoot":"","sources":["../../test/utils.test.tsx"],"names":[],"mappings":"AAMA,OAAO,6BAA6B,CAAC"}
@@ -0,0 +1,223 @@
1
+ import { memo as _$memo, createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
2
+ import { computed, ref, triggerRef } from "@vue/reactivity";
3
+ import { describe, expect, it } from "vitest";
4
+ import { renderTree } from "../src/render.js";
5
+ import { flushJobs } from "../src/scheduler.js";
6
+ import { children, join, mapJoin } from "../src/utils.js";
7
+ import "../testing/extend-expect.js";
8
+ describe("mapJoin", () => {
9
+ it("can map a map", () => {
10
+ const map = new Map([["a", 1], ["b", 2]]);
11
+ function Foo(props) {
12
+ return ["Key: ", _$memo(() => props.key), ", Value: ", _$memo(() => props.value)];
13
+ }
14
+ const joined = mapJoin(() => map, (key, value) => _$createComponent(Foo, {
15
+ key: key,
16
+ value: value
17
+ }));
18
+ expect(joined()).toRenderTo(`
19
+ Key: a, Value: 1
20
+ Key: b, Value: 2
21
+ `);
22
+ });
23
+ it("can map an array", () => {
24
+ const arr = [1, 2];
25
+ function Foo(props) {
26
+ return ["Value: ", _$memo(() => props.value)];
27
+ }
28
+ const joined = mapJoin(() => arr, value => _$createComponent(Foo, {
29
+ value: value
30
+ }));
31
+ expect(joined()).toRenderTo(`
32
+ Value: 1
33
+ Value: 2
34
+ `);
35
+ });
36
+ it("can map an array reactively (without render)", () => {
37
+ const arr = ref([1, 2]);
38
+ function Foo(props) {
39
+ return ["Value: ", _$memo(() => props.value)];
40
+ }
41
+ const joined = mapJoin(() => arr.value, value => {
42
+ return _$createComponent(Foo, {
43
+ value: value
44
+ });
45
+ });
46
+ const len = computed(() => {
47
+ return joined().length;
48
+ });
49
+ expect(len.value).toBe(4);
50
+ arr.value.push(3);
51
+ triggerRef(arr);
52
+ expect(len.value).toBe(6);
53
+ });
54
+ it("can map an array reactively (with render)", () => {
55
+ let callCount = 0;
56
+ const arr = ref([1, 2]);
57
+ function Foo(props) {
58
+ callCount++;
59
+ return ["Value: ", _$memo(() => props.value)];
60
+ }
61
+ const joined = mapJoin(() => arr.value, value => {
62
+ return _$createComponent(Foo, {
63
+ value: value
64
+ });
65
+ });
66
+ renderTree(joined);
67
+ expect(callCount).toBe(2);
68
+ arr.value.push(3);
69
+ triggerRef(arr);
70
+ flushJobs();
71
+ expect(callCount).toBe(3);
72
+ });
73
+ it("can map a joiner", () => {
74
+ const arr = [1, 2];
75
+ function Foo(props) {
76
+ return ["Value: ", _$memo(() => props.value)];
77
+ }
78
+ const joined = mapJoin(() => arr, value => _$createComponent(Foo, {
79
+ value: value
80
+ }), {
81
+ joiner: "-"
82
+ });
83
+ expect(joined).toRenderTo(`
84
+ Value: 1-Value: 2
85
+ `);
86
+ });
87
+ it("can map an ender", () => {
88
+ const arr = [1, 2];
89
+ function Foo(props) {
90
+ return ["Value: ", _$memo(() => props.value)];
91
+ }
92
+ const joined = mapJoin(() => arr, value => _$createComponent(Foo, {
93
+ value: value
94
+ }), {
95
+ joiner: "-",
96
+ ender: ";"
97
+ });
98
+ expect(joined).toRenderTo(`
99
+ Value: 1-Value: 2;
100
+ `);
101
+ });
102
+ it("can map using an iterator", () => {
103
+ const arr = [1, 2].values();
104
+ function Foo(props) {
105
+ return ["Value: ", _$memo(() => props.value)];
106
+ }
107
+ const joined = mapJoin(() => arr, value => _$createComponent(Foo, {
108
+ value: value
109
+ }), {
110
+ joiner: "-",
111
+ ender: ";"
112
+ });
113
+ expect(joined).toRenderTo(`
114
+ Value: 1-Value: 2;
115
+ `);
116
+ });
117
+ });
118
+ describe("join", () => {
119
+ it("can join an array", () => {
120
+ const arr = [_$createComponent(Foo, {
121
+ value: 1
122
+ }), _$createComponent(Foo, {
123
+ value: 2
124
+ })];
125
+ function Foo(props) {
126
+ return ["Value: ", _$memo(() => props.value)];
127
+ }
128
+ const joined = join(arr);
129
+ expect(joined).toRenderTo(`
130
+ Value: 1
131
+ Value: 2
132
+ `);
133
+ });
134
+ it("can join an array with a joiner", () => {
135
+ const arr = [_$createComponent(Foo, {
136
+ value: 1
137
+ }), _$createComponent(Foo, {
138
+ value: 2
139
+ })];
140
+ function Foo(props) {
141
+ return ["Value: ", _$memo(() => props.value)];
142
+ }
143
+ const joined = join(arr, {
144
+ joiner: "-"
145
+ });
146
+ expect(joined).toRenderTo(`
147
+ Value: 1-Value: 2
148
+ `);
149
+ });
150
+ it("can join an array with an ender", () => {
151
+ const arr = [_$createComponent(Foo, {
152
+ value: 1
153
+ }), _$createComponent(Foo, {
154
+ value: 2
155
+ })];
156
+ function Foo(props) {
157
+ return ["Value: ", _$memo(() => props.value)];
158
+ }
159
+ const joined = join(arr, {
160
+ joiner: "-",
161
+ ender: ";"
162
+ });
163
+ expect(joined).toRenderTo(`
164
+ Value: 1-Value: 2;
165
+ `);
166
+ });
167
+ it("can join using an iterator", () => {
168
+ const arrIter = [_$createComponent(Foo, {
169
+ value: 1
170
+ }), _$createComponent(Foo, {
171
+ value: 2
172
+ })].values();
173
+ function Foo(props) {
174
+ return ["Value: ", _$memo(() => props.value)];
175
+ }
176
+ const joined = join(arrIter, {
177
+ joiner: "-",
178
+ ender: ";"
179
+ });
180
+ expect(joined).toRenderTo(`
181
+ Value: 1-Value: 2;
182
+ `);
183
+ });
184
+ });
185
+ describe("children", () => {
186
+ let resolvedChildren;
187
+ function ResolveChildren(props) {
188
+ resolvedChildren = children(() => props.children, {
189
+ preserveFragments: props.preserveFragments
190
+ })();
191
+ }
192
+ it("resolves a single child", () => {
193
+ renderTree(_$createComponent(ResolveChildren, {
194
+ children: "1"
195
+ }));
196
+ expect(resolvedChildren).toEqual("1");
197
+ });
198
+ it("resolves multiple children", () => {
199
+ renderTree(_$createComponent(ResolveChildren, {
200
+ get children() {
201
+ return ["1", "2", "3"];
202
+ }
203
+ }));
204
+ expect(resolvedChildren).toEqual(["1", "2", "3"]);
205
+ });
206
+ it("resolves fragments by default", () => {
207
+ renderTree(_$createComponent(ResolveChildren, {
208
+ get children() {
209
+ return [["1"], ["2"], ["3"]];
210
+ }
211
+ }));
212
+ expect(resolvedChildren).toEqual(["1", "2", "3"]);
213
+ });
214
+ it("preserves fragments if asked", () => {
215
+ renderTree(_$createComponent(ResolveChildren, {
216
+ preserveFragments: true,
217
+ get children() {
218
+ return [["1"], ["2"], ["3"]];
219
+ }
220
+ }));
221
+ expect(resolvedChildren).toEqual([["1"], ["2"], ["3"]]);
222
+ });
223
+ });
@@ -18,5 +18,4 @@ expect.extend({
18
18
  expected
19
19
  };
20
20
  }
21
- });
22
- //# sourceMappingURL=extend-expect.js.map
21
+ });
@@ -1,3 +1,2 @@
1
1
  import "./extend-expect.js";
2
- export * from "./render.js";
3
- //# sourceMappingURL=index.js.map
2
+ export * from "./render.js";
@@ -19,5 +19,4 @@ export function dedent(str) {
19
19
  // Remove the indent from each line
20
20
  const dedented = str.split("\n").map(line => line.startsWith(indent) ? line.slice(indent.length) : line).join("\n");
21
21
  return dedented;
22
- }
23
- //# sourceMappingURL=render.js.map
22
+ }