@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,317 @@
1
+ import { effect, getContext, isComponentCreator, popStack, printRenderStack, pushStack, root, untrack } from "@alloy-js/core/jsx-runtime";
2
+ import { isRef } from "@vue/reactivity";
3
+ import { Indent } from "./components/Indent.js";
4
+ import { useContext } from "./context.js";
5
+ import { IndentContext } from "./context/indent.js";
6
+ import { SourceFileContext } from "./context/source-file.js";
7
+ import { isRefkey } from "./refkey.js";
8
+
9
+ /**
10
+ * The component tree is constructed as the result of transforming JSX with
11
+ * `@alloy-js/babel-preset`. Elements in the component tree (represented by the type
12
+ * Children) are three distinct types of things:
13
+ *
14
+ * 1. Primitive data types, which are either literal JSX or substitutions
15
+ * 2. Components, which are created via `createComponent`
16
+ * 3. Memos, which are created via `memo`, and represent substitutions like
17
+ * property accesses and function calls that might be reactive.
18
+ *
19
+ * This tree is then compiled into a render tree, which is a normalized form of
20
+ * the component tree. The render tree is constructed by traversing the
21
+ * component tree, invoking components, wrapping memos, doing whitespace
22
+ * normalization, and other activities. There are four types of nodes in the
23
+ * render tree.
24
+ *
25
+ * 1. Strings, which are either literal JSX or substitutions. Other primitive
26
+ * types are either converted to the empty string or stringified as
27
+ * appropriate.
28
+ * 2. Components, which are possibly wrapped if they are indented.
29
+ * 3. Memos, which are wrapped in a reactive effect which updates its render
30
+ * tree nodes when its value changes.
31
+ * 4. Arrays of these things.
32
+ *
33
+ * The render tree is whitespace normalized and indentation preserving. When the
34
+ * component increases the literal indent level and then embeds a component,
35
+ * memo, or array, the contents of that substitution are indented appropriately.
36
+ * This is accomplished by wrapping those substitutions in an indent component.
37
+ *
38
+ * So the high level process for rendering while normalizing whitespace is as
39
+ * follows:
40
+ *
41
+ * 1. For an array of elements in the render tree (which may be a component or
42
+ * array of elements):
43
+ * 1. Normalize all primitive values other than strings to strings.
44
+ * Recursively normalize nested array elements.
45
+ * 2. Use the first text node to determine the literal indent level of the
46
+ * children. Remove all preceding whitespace - any indent of the first
47
+ * line is provided in the text nodes preceding the reference to this
48
+ * component. If the first element is not a literal string, then no
49
+ * literal indent is applied, and all indentation within the component
50
+ * becomes significant.
51
+ * 3. For each child of the component, render it:
52
+ * 1. If it is a string, reindent it by splitting on lines and replacing
53
+ * the detected literal whitespace with the current indent level,
54
+ * skipping the first line. If the string ends with a larger literal
55
+ * indent than the detected literal indent, then a subsequent child
56
+ * will be indented.
57
+ * 2. If it's a component, if the next child should be indented, create an
58
+ * Indent component and wrap the component's children in it.
59
+ * 3. If it's a function, if the next child should be indented, wrap it in
60
+ * an indent component. Any elements processed as a result of executing
61
+ * the memo are treated as first elements in a child array are with
62
+ * respect to establishing literal indent level and whitespace trimming
63
+ * behavior.
64
+ * 4. If it's an array, if the next child should be indented, create an
65
+ * Indent component and wrap it the array in it.
66
+ *
67
+ * Let's look at a few examples of each of these phases:
68
+ *
69
+ * ## Explicit indentation
70
+ *
71
+ * ### Input
72
+ * ```
73
+ * <Indent>
74
+ * <Foo />
75
+ * <Foo />
76
+ * </Indent>
77
+ * ```
78
+ *
79
+ * ### Compiled tree
80
+ * ```
81
+ * [
82
+ * createComponent(Indent, {
83
+ * get children() {
84
+ * return [
85
+ * "\n ",
86
+ * createComponent(Foo, {}),
87
+ * "\n ",
88
+ * createComponent(Foo, {}),
89
+ * "\n"
90
+ * ]
91
+ * }
92
+ * })
93
+ * ]
94
+ * ```
95
+ *
96
+ * ### Render tree
97
+ * ```
98
+ * [ // node for Indent
99
+ * [ // node for Context Provider
100
+ * " ", // indent from the children of Indent
101
+ * [ // component for Foo
102
+ * "Foo" // result of calling Foo
103
+ * ],
104
+ * "\n ", // indent and line break from the children of Ident
105
+ * [ "Foo" ] // second foo component
106
+ * ]
107
+ * ]
108
+ * ```
109
+ * ### Rendered text
110
+ * ```
111
+ * FooFoo
112
+ * ```
113
+ *
114
+ * ## Implicit indentation
115
+ *
116
+ * ### Input
117
+ * ```
118
+ * <>
119
+ * base
120
+ * <Foo /> <Foo />
121
+ * </>
122
+ * ```
123
+ *
124
+ * ### Render tree
125
+ * ```
126
+ * [ // node for top-level fragment
127
+ * "base\n ", // contents of fragment, including trailing indent
128
+ * [ // node for implicitly created Indent component
129
+ * [ // node for its context provider [ "Foo" ], // contents of Foo "\n"
130
+ * ]
131
+ * ```
132
+ * ## Rendered text
133
+ * ```
134
+ * base
135
+ * Foo Foo
136
+ * ```
137
+ */
138
+
139
+ //
140
+
141
+ const nodesToContext = new WeakMap();
142
+ export function getContextForRenderNode(node) {
143
+ return nodesToContext.get(node);
144
+ }
145
+ function traceRender(phase, message) {
146
+ return false;
147
+ // console.log(`[\x1b[34m${phase}\x1b[0m]: ${message}`);
148
+ }
149
+ export function render(children) {
150
+ const tree = renderTree(children);
151
+ let rootDirectory = undefined;
152
+ collectSourceFiles(undefined, tree);
153
+ if (!rootDirectory) {
154
+ throw new Error("No root directory found. Make sure you are using the Output component.");
155
+ }
156
+ return rootDirectory;
157
+ function collectSourceFiles(currentDirectory, root) {
158
+ if (!Array.isArray(root)) {
159
+ return;
160
+ }
161
+ const context = getContextForRenderNode(root);
162
+ if (!context) {
163
+ return recurse(currentDirectory);
164
+ }
165
+ if (context.meta?.directory) {
166
+ const directory = {
167
+ kind: "directory",
168
+ path: context.meta?.directory.path,
169
+ contents: []
170
+ };
171
+ if (currentDirectory) {
172
+ currentDirectory.contents.push(directory);
173
+ } else {
174
+ rootDirectory = directory;
175
+ }
176
+ recurse(directory);
177
+ } else if (context.meta?.sourceFile) {
178
+ if (!currentDirectory) {
179
+ // This shouldn't happen if you're using the Output component.
180
+ throw new Error("Source file doesn't have parent directory. Make sure you have used the Output component.");
181
+ }
182
+ const sourceFile = {
183
+ kind: "file",
184
+ path: context.meta?.sourceFile.path,
185
+ filetype: context.meta?.sourceFile.filetype,
186
+ contents: root.flat(Infinity).join("")
187
+ };
188
+ currentDirectory.contents.push(sourceFile);
189
+ } else {
190
+ recurse(currentDirectory);
191
+ }
192
+ function recurse(cwd) {
193
+ for (const child of root) {
194
+ collectSourceFiles(cwd, child);
195
+ }
196
+ }
197
+ }
198
+ }
199
+ export function renderTree(children) {
200
+ const rootElem = [];
201
+ const state = {
202
+ newline: false
203
+ };
204
+ try {
205
+ root(() => {
206
+ renderWorker(rootElem, children, state);
207
+ }, "render worker");
208
+ } catch (e) {
209
+ printRenderStack();
210
+ throw e;
211
+ }
212
+ return rootElem;
213
+ }
214
+ function renderWorker(node, children, state) {
215
+ traceRender("render", dumpChildren(children));
216
+ if (Array.isArray(node)) {
217
+ nodesToContext.set(node, getContext());
218
+ }
219
+ const indent = useContext(IndentContext);
220
+ if (Array.isArray(children)) {
221
+ for (const child of children) {
222
+ appendChild(node, child, indent, state);
223
+ }
224
+ } else {
225
+ appendChild(node, children, indent, state);
226
+ }
227
+ }
228
+ function appendChild(node, rawChild, indentState, state) {
229
+ traceRender("appendChild", printChild(rawChild));
230
+ const child = normalizeChild(rawChild);
231
+ if (typeof child === "string") {
232
+ if (child.match(/\n\s*$/)) {
233
+ state.newline = true;
234
+ } else {
235
+ state.newline = false;
236
+ }
237
+ const reindented = reindent(child, indentState.indentString);
238
+ traceRender("appendChild:string", JSON.stringify(reindented));
239
+ node.push(reindented);
240
+ } else if (isComponentCreator(child)) {
241
+ root(() => {
242
+ traceRender("appendChild:component", printChild(child));
243
+ if (child.component === Indent && state.newline) {
244
+ node.push(indentState.indent);
245
+ }
246
+ const componentRoot = [];
247
+ pushStack(child.component, child.props);
248
+ renderWorker(componentRoot, untrack(child), state);
249
+ popStack();
250
+ node.push(componentRoot);
251
+ traceRender("appendChild:component-done", printChild(child));
252
+ }, child.component.name);
253
+ } else if (typeof child === "function") {
254
+ traceRender("appendChild:memo", child.toString());
255
+ const index = node.length;
256
+ effect(prev => {
257
+ traceRender("memoEffect:run", "");
258
+ let res = child();
259
+ while (typeof res === "function" && !isComponentCreator(res)) {
260
+ res = res();
261
+ }
262
+ const newNodes = [];
263
+ renderWorker(newNodes, res, state);
264
+ //node.splice(index, prev ? prev.length : 0, ...newNodes);
265
+ node[index] = newNodes;
266
+ return newNodes;
267
+ });
268
+ traceRender("appendChild:memo-done", "");
269
+ } else {
270
+ traceRender("appendChild:array", dumpChildren(child));
271
+ renderWorker(node, child, state);
272
+ traceRender("appendChild:array-done", dumpChildren(child));
273
+ }
274
+ }
275
+ function reindent(str, indent) {
276
+ const lines = str.split("\n");
277
+ return [lines[0], ...lines.slice(1).map(line => indent + line)].join("\n");
278
+ }
279
+ function normalizeChild(child) {
280
+ if (Array.isArray(child)) {
281
+ return child.map(normalizeChild);
282
+ } else if (typeof child === "string" || typeof child === "function") {
283
+ return child;
284
+ } else if (typeof child === "undefined" || child === null || typeof child === "boolean") {
285
+ return "";
286
+ } else if (isRef(child)) {
287
+ return () => child.value;
288
+ } else if (isRefkey(child)) {
289
+ return () => {
290
+ const sfContext = useContext(SourceFileContext);
291
+ if (!sfContext || !sfContext.reference) {
292
+ throw new Error("Can only emit references inside of source files");
293
+ }
294
+ return sfContext.reference({
295
+ refkey: child
296
+ });
297
+ };
298
+ } else {
299
+ return String(child);
300
+ }
301
+ }
302
+ function dumpChildren(children) {
303
+ if (Array.isArray(children)) {
304
+ return `[ ${children.map(printChild).join(", ")} ]`;
305
+ }
306
+ return printChild(children);
307
+ }
308
+ function printChild(child) {
309
+ if (isComponentCreator(child)) {
310
+ return "<" + child.component.name + ">";
311
+ } else if (typeof child === "function") {
312
+ return "$memo";
313
+ } else {
314
+ return JSON.stringify(child);
315
+ }
316
+ }
317
+ //# sourceMappingURL=render.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"render.js","names":["effect","getContext","isComponentCreator","popStack","printRenderStack","pushStack","root","untrack","isRef","Indent","useContext","IndentContext","SourceFileContext","isRefkey","nodesToContext","WeakMap","getContextForRenderNode","node","get","traceRender","phase","message","render","children","tree","renderTree","rootDirectory","undefined","collectSourceFiles","Error","currentDirectory","Array","isArray","context","recurse","meta","directory","kind","path","contents","push","sourceFile","filetype","flat","Infinity","join","cwd","child","rootElem","state","newline","renderWorker","e","dumpChildren","set","indent","appendChild","rawChild","indentState","printChild","normalizeChild","match","reindented","reindent","indentString","JSON","stringify","component","componentRoot","props","name","toString","index","length","prev","res","newNodes","str","lines","split","slice","map","line","value","sfContext","reference","refkey","String"],"sources":["../../src/render.ts"],"sourcesContent":[null],"mappings":"AAAA,SAIEA,MAAM,EACNC,UAAU,EACVC,kBAAkB,EAClBC,QAAQ,EACRC,gBAAgB,EAChBC,SAAS,EACTC,IAAI,EACJC,OAAO,QACF,4BAA4B;AACnC,SAASC,KAAK,QAAQ,iBAAiB;AACvC,SAASC,MAAM,QAAqB,wBAAwB;AAC5D,SAASC,UAAU,QAAQ,cAAc;AACzC,SAASC,aAAa,QAAQ,qBAAqB;AACnD,SAASC,iBAAiB,QAAQ,0BAA0B;AAC5D,SAASC,QAAQ,QAAQ,aAAa;;AAEtC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAcA,MAAMC,cAAc,GAAG,IAAIC,OAAO,CAA0B,CAAC;AAE7D,OAAO,SAASC,uBAAuBA,CAACC,IAAoB,EAAE;EAC5D,OAAOH,cAAc,CAACI,GAAG,CAACD,IAAI,CAAC;AACjC;AAKA,SAASE,WAAWA,CAACC,KAAa,EAAEC,OAAe,EAAE;EACnD,OAAO,KAAK;EACZ;AACF;AAEA,OAAO,SAASC,MAAMA,CAACC,QAAkB,EAAmB;EAC1D,MAAMC,IAAI,GAAGC,UAAU,CAACF,QAAQ,CAAC;EACjC,IAAIG,aAA0C,GAAGC,SAAS;EAC1DC,kBAAkB,CAACD,SAAS,EAAEH,IAAI,CAAC;EAEnC,IAAI,CAACE,aAAa,EAAE;IAClB,MAAM,IAAIG,KAAK,CACb,wEACF,CAAC;EACH;EAEA,OAAOH,aAAa;EAEpB,SAASE,kBAAkBA,CACzBE,gBAA6C,EAC7CxB,IAAoB,EACpB;IACA,IAAI,CAACyB,KAAK,CAACC,OAAO,CAAC1B,IAAI,CA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C;EAC9B;AACF","ignoreList":[]}
@@ -0,0 +1,11 @@
1
+ // This file is read by tools that parse documentation comments conforming to the TSDoc standard.
2
+ // It should be published with your NPM package. It should not be tracked by Git.
3
+ {
4
+ "tsdocVersion": "0.12",
5
+ "toolPackages": [
6
+ {
7
+ "packageName": "@microsoft/api-extractor",
8
+ "packageVersion": "7.47.7"
9
+ }
10
+ ]
11
+ }
@@ -0,0 +1,80 @@
1
+ import { Child, Children, ComponentCreator, ComponentDefinition } from "@alloy-js/core/jsx-runtime";
2
+ import { OutputDirectory, OutputFile } from "./render.js";
3
+ export interface JoinOptions {
4
+ /**
5
+ * The string to place between each element.
6
+ */
7
+ joiner?: string;
8
+ /**
9
+ * When true, the joiner is placed at the end of the array. When a string,
10
+ * that string is placed at the end of the array. The ender is only emitted
11
+ * when the array has at least one element.
12
+ */
13
+ ender?: string | boolean;
14
+ }
15
+ /**
16
+ * Map a Map to an array using a mapper and place a joiner between each element.
17
+ * Defaults to joining with a newline.
18
+ *
19
+ * @see {@link join} for joining without mapping.
20
+ * @param src - Source map.
21
+ * @param cb - Mapper function.
22
+ * @param options - Join options.
23
+ * @returns The mapped and joined array.
24
+ *
25
+ */
26
+ export declare function mapJoin<T, U, V>(src: Map<T, U>, cb: (key: T, value: U) => V, options?: JoinOptions): (V | string)[];
27
+ /**
28
+ * Map a array or iterator to another array using a mapper and place a joiner
29
+ * between each element. Defaults to joining with a newline.
30
+ *
31
+ * @see {@link join} for joining without mapping.
32
+ * @param src - Source array.
33
+ * @param cb - Mapper function.
34
+ * @param options - Join options.
35
+ * @returns The mapped and joined array.
36
+ */
37
+ export declare function mapJoin<T, V>(src: T[] | IterableIterator<T>, cb: (value: T) => V, options?: JoinOptions): (V | string)[];
38
+ /**
39
+ * Place a joiner between each element of an array or iterator. Defaults to
40
+ * joining with a newline.
41
+ *
42
+ * @see mapJoin for mapping before joining.
43
+ * @returns The joined array
44
+ */
45
+ export declare function join<T>(src: T[] | Iterator<T>, options?: JoinOptions): (T | string)[];
46
+ /**
47
+ * Returns a memo which is a list of all the provided children.
48
+ * If you want this as an array, see {@link childrenArray}.
49
+ */
50
+ export declare function children(fn: () => Children): () => Children;
51
+ export declare function childrenArray(fn: () => Children): Child[];
52
+ export declare function findKeyedChild(children: Child[], tag: symbol): ComponentCreator<import("@alloy-js/core/jsx-runtime").Props> | null;
53
+ export declare function findUnkeyedChildren(children: Child[]): Child[];
54
+ export declare function isKeyedChild(child: Child): child is ComponentCreator;
55
+ export declare function stc<T extends {}>(Component: ComponentDefinition<T>): (...args: unknown extends T ? [] : {} extends Omit<T, "children"> ? [props?: T] : [props: T]) => ComponentCreator<T> & {
56
+ code(template: TemplateStringsArray, ...substitutions: Children[]): ComponentCreator<T>;
57
+ children(...children: Children[]): ComponentCreator<T>;
58
+ };
59
+ /**
60
+ * A visitor to collect the output from {@link render}. Used by
61
+ * {@link traverseOutput}.
62
+ */
63
+ export interface OutputVisitor {
64
+ visitDirectory(directory: OutputDirectory): void;
65
+ visitFile(file: OutputFile): void;
66
+ }
67
+ /**
68
+ * Traverse the output from {@link render} and call the visitor for each
69
+ * file and directory within it.
70
+ *
71
+ * @param sourceDirectory - The root directory to traverse.
72
+ * @param visitor - The visitor to call for each file and directory.
73
+ */
74
+ export declare function traverseOutput(sourceDirectory: OutputDirectory, visitor: OutputVisitor): void;
75
+ /**
76
+ * Write the output from {@link render} to the file system.
77
+ *
78
+ */
79
+ export declare function writeOutput(output: OutputDirectory, basePath?: string): void;
80
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,QAAQ,EACR,gBAAgB,EAChB,mBAAmB,EAGpB,MAAM,4BAA4B,CAAC;AAKpC,OAAO,EAAE,eAAe,EAAE,UAAU,EAAU,MAAM,aAAa,CAAC;AAElE,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,MAAM,CA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GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,mBAAmB,CAAC,CAAC,CAAC,aAEtD,OAAO,SAAS,CAAC,GAAG,EAAE,GAC7B,EAAE,SAAS,IAAI,CAAC,CAAC,EAAE,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,GAC5C,CAAC,KAAK,EAAE,CAAC,CAAC;mBAIE,oBAAoB,oBACZ,QAAQ,EAAE,GAC3B,gBAAgB,CAAC,CAAC,CAAC;0BACA,QAAQ,EAAE,GAAG,gBAAgB,CAAC,CAAC,CAAC;EAiC3D;AAED;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,cAAc,CAAC,SAAS,EAAE,eAAe,GAAG,IAAI,CAAC;IACjD,SAAS,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI,CAAC;CACnC;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAC5B,eAAe,EAAE,eAAe,EAChC,OAAO,EAAE,aAAa,QAUvB;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,eAAe,EAAE,QAAQ,GAAE,MAAW,QAwBzE"}
@@ -0,0 +1,219 @@
1
+ import { isComponentCreator, memo } from "@alloy-js/core/jsx-runtime";
2
+ import { mkdirSync, statSync, writeFileSync } from "node:fs";
3
+ import { relative, resolve } from "pathe";
4
+ import { code } from "./code.js";
5
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
6
+
7
+ const defaultJoinOptions = {
8
+ joiner: "\n",
9
+ ender: false
10
+ };
11
+
12
+ /**
13
+ * Map a Map to an array using a mapper and place a joiner between each element.
14
+ * Defaults to joining with a newline.
15
+ *
16
+ * @see {@link join} for joining without mapping.
17
+ * @param src - Source map.
18
+ * @param cb - Mapper function.
19
+ * @param options - Join options.
20
+ * @returns The mapped and joined array.
21
+ *
22
+ */
23
+
24
+ /**
25
+ * Map a array or iterator to another array using a mapper and place a joiner
26
+ * between each element. Defaults to joining with a newline.
27
+ *
28
+ * @see {@link join} for joining without mapping.
29
+ * @param src - Source array.
30
+ * @param cb - Mapper function.
31
+ * @param options - Join options.
32
+ * @returns The mapped and joined array.
33
+ */
34
+
35
+ export function mapJoin(src, cb, rawOptions = {}) {
36
+ const options = {
37
+ ...defaultJoinOptions,
38
+ ...rawOptions
39
+ };
40
+ const ender = options.ender === true ? options.joiner : options.ender;
41
+ const mapped = [];
42
+ if (typeof src.next === "function") {
43
+ src = Array.from(src);
44
+ }
45
+ if (Array.isArray(src)) {
46
+ for (const [index, item] of src.entries()) {
47
+ mapped.push(cb(item));
48
+ if (index !== src.length - 1) {
49
+ mapped.push(options.joiner);
50
+ }
51
+ }
52
+ if (src.length > 0 && ender) {
53
+ mapped.push(ender);
54
+ }
55
+ } else {
56
+ const entries = [...src.entries()];
57
+ for (const [index, [key, value]] of entries.entries()) {
58
+ mapped.push(cb(key, value));
59
+ if (index !== entries.length - 1) {
60
+ mapped.push(options.joiner);
61
+ }
62
+ }
63
+ if (entries.length > 0 && ender) {
64
+ mapped.push(ender);
65
+ }
66
+ }
67
+ return mapped;
68
+ }
69
+
70
+ /**
71
+ * Place a joiner between each element of an array or iterator. Defaults to
72
+ * joining with a newline.
73
+ *
74
+ * @see mapJoin for mapping before joining.
75
+ * @returns The joined array
76
+ */
77
+ export function join(src, options = {}) {
78
+ const mergedOptions = {
79
+ ...defaultJoinOptions,
80
+ ...options
81
+ };
82
+ const joined = [];
83
+ const ender = mergedOptions.ender === true ? mergedOptions.joiner : mergedOptions.ender;
84
+ src = Array.from(src);
85
+ for (const [index, item] of src.entries()) {
86
+ joined.push(item);
87
+ if (index !== src.length - 1) {
88
+ joined.push(mergedOptions.joiner);
89
+ }
90
+ }
91
+ if (src.length > 0 && ender) {
92
+ joined.push(ender);
93
+ }
94
+ return joined;
95
+ }
96
+
97
+ /**
98
+ * Returns a memo which is a list of all the provided children.
99
+ * If you want this as an array, see {@link childrenArray}.
100
+ */
101
+ export function children(fn) {
102
+ return memo(() => collectChildren(fn()));
103
+ function collectChildren(children) {
104
+ if (Array.isArray(children)) {
105
+ return children.map(collectChildren).flat();
106
+ } else if (typeof children === "function" && !isComponentCreator(children)) {
107
+ return collectChildren(children());
108
+ } else {
109
+ return children;
110
+ }
111
+ }
112
+ }
113
+ export function childrenArray(fn) {
114
+ const c = children(fn)();
115
+ if (Array.isArray(c)) {
116
+ return c;
117
+ } else if (c === undefined) {
118
+ return [];
119
+ } else {
120
+ return [c];
121
+ }
122
+ }
123
+ export function findKeyedChild(children, tag) {
124
+ for (const child of children) {
125
+ if (isKeyedChild(child) && child.tag === tag) {
126
+ return child;
127
+ }
128
+ }
129
+ return null;
130
+ }
131
+ export function findUnkeyedChildren(children) {
132
+ return children.filter(child => !isKeyedChild(child));
133
+ }
134
+ export function isKeyedChild(child) {
135
+ return isComponentCreator(child) && !!child.tag;
136
+ }
137
+ export function stc(Component) {
138
+ return (...args) => {
139
+ const fn = () => Component(args[0]);
140
+ fn.component = Component;
141
+ fn.props = args[0];
142
+ fn.code = (template, ...substitutions) => {
143
+ const propsWithChildren = {
144
+ ...(args[0] ?? {}),
145
+ children: code(template, ...substitutions)
146
+ };
147
+ const fn = () => Component(propsWithChildren);
148
+ fn.component = Component;
149
+ fn.props = args[0];
150
+ return fn;
151
+ };
152
+ fn.children = (...children) => {
153
+ const propsWithChildren = {
154
+ ...(args[0] ?? {}),
155
+ children
156
+ };
157
+ const fn = () => Component(propsWithChildren);
158
+ fn.component = Component;
159
+ fn.props = args[0];
160
+ return fn;
161
+ };
162
+ return fn;
163
+ };
164
+ }
165
+
166
+ /**
167
+ * A visitor to collect the output from {@link render}. Used by
168
+ * {@link traverseOutput}.
169
+ */
170
+
171
+ /**
172
+ * Traverse the output from {@link render} and call the visitor for each
173
+ * file and directory within it.
174
+ *
175
+ * @param sourceDirectory - The root directory to traverse.
176
+ * @param visitor - The visitor to call for each file and directory.
177
+ */
178
+ export function traverseOutput(sourceDirectory, visitor) {
179
+ visitor.visitDirectory(sourceDirectory);
180
+ for (const item of sourceDirectory.contents) {
181
+ if (item.kind === "directory") {
182
+ traverseOutput(item, visitor);
183
+ } else {
184
+ visitor.visitFile(item);
185
+ }
186
+ }
187
+ }
188
+
189
+ /**
190
+ * Write the output from {@link render} to the file system.
191
+ *
192
+ */
193
+ export function writeOutput(output, basePath = "") {
194
+ traverseOutput(output, {
195
+ visitDirectory(directory) {
196
+ const path = resolve(basePath, directory.path);
197
+ if (statSync(path)) {
198
+ return;
199
+ }
200
+ // eslint-disable-next-line no-console
201
+ console.log("create", relative(process.cwd(), path));
202
+ mkdirSync(path, {
203
+ recursive: true
204
+ });
205
+ },
206
+ visitFile(file) {
207
+ const path = resolve(basePath, file.path);
208
+ if (statSync(path)) {
209
+ // eslint-disable-next-line no-console
210
+ console.log("overwrite", relative(process.cwd(), path));
211
+ } else {
212
+ // eslint-disable-next-line no-console
213
+ console.log("create", relative(process.cwd(), path));
214
+ }
215
+ writeFileSync(path, file.contents);
216
+ }
217
+ });
218
+ }
219
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","names":["isComponentCreator","memo","mkdirSync","statSync","writeFileSync","relative","resolve","code","defaultJoinOptions","joiner","ender","mapJoin","src","cb","rawOptions","options","mapped","next","Array","from","isArray","index","item","entries","push","length","key","value","join","mergedOptions","joined","children","fn","collectChildren","map","flat","childrenArray","c","undefined","findKeyedChild","tag","child","isKeyedChild","findUnkeyedChildren","filter","stc","Component","args","component","props","template","substitutions","propsWithChildren","traverseOutput","sourceDirectory","visitor","visitDirectory","contents","kind","visitFile","writeOutput","output","basePath","directory","path","console","log","process","cwd","recursive","file"],"sources":["../../src/utils.ts"],"sourcesContent":[null],"mappings":"AAAA,SAKEA,kBAAkB,EAClBC,IAAI,QACC,4BAA4B;AACnC,SAASC,SAAS,EAAEC,QAAQ,EAAEC,aAAa,QAAQ,SAAS;AAC5D,SAASC,QAAQ,EAAEC,OAAO,QAAQ,OAAO;AACzC,SAASC,IAAI,QAAQ,W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GAAG,CAAC,CAAC,EAAEJ,IAAI,CAAC,CAAC;MACtD;MAEA5D,aAAa,CAAC4D,IAAI,EAAEM,IAAI,CAACb,QAAQ,CAAC;IACpC;EACF,CAAC,CAAC;AACJ","ignoreList":[]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=children.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"children.test.d.ts","sourceRoot":"","sources":["../../test/children.test.tsx"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ import "../../testing/extend-expect.js";
2
+ //# sourceMappingURL=source-file.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"source-file.test.d.ts","sourceRoot":"","sources":["../../../test/components/source-file.test.tsx"],"names":[],"mappings":"AAUA,OAAO,gCAAgC,CAAC"}