@alloy-js/core 0.16.0 → 0.18.0-dev.2

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 (249) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/src/binder.d.ts +19 -235
  3. package/dist/src/binder.d.ts.map +1 -1
  4. package/dist/src/binder.js +85 -386
  5. package/dist/src/code.d.ts +1 -1
  6. package/dist/src/code.d.ts.map +1 -1
  7. package/dist/src/components/Block.d.ts +1 -1
  8. package/dist/src/components/Block.d.ts.map +1 -1
  9. package/dist/src/components/Block.js +3 -1
  10. package/dist/src/components/Declaration.d.ts +2 -2
  11. package/dist/src/components/Declaration.d.ts.map +1 -1
  12. package/dist/src/components/Declaration.js +6 -5
  13. package/dist/src/components/For.d.ts +1 -1
  14. package/dist/src/components/For.d.ts.map +1 -1
  15. package/dist/src/components/For.js +1 -1
  16. package/dist/src/components/Indent.d.ts +1 -1
  17. package/dist/src/components/Indent.d.ts.map +1 -1
  18. package/dist/src/components/List.d.ts +1 -1
  19. package/dist/src/components/List.d.ts.map +1 -1
  20. package/dist/src/components/List.js +3 -1
  21. package/dist/src/components/MemberDeclaration.d.ts +3 -3
  22. package/dist/src/components/MemberDeclaration.d.ts.map +1 -1
  23. package/dist/src/components/MemberDeclaration.js +4 -4
  24. package/dist/src/components/MemberScope.d.ts +2 -2
  25. package/dist/src/components/MemberScope.d.ts.map +1 -1
  26. package/dist/src/components/MemberScope.js +0 -2
  27. package/dist/src/components/Output.d.ts +1 -1
  28. package/dist/src/components/Output.d.ts.map +1 -1
  29. package/dist/src/components/Output.js +1 -1
  30. package/dist/src/components/Prose.d.ts +1 -1
  31. package/dist/src/components/Prose.d.ts.map +1 -1
  32. package/dist/src/components/ReferenceOrContent.d.ts +1 -1
  33. package/dist/src/components/ReferenceOrContent.d.ts.map +1 -1
  34. package/dist/src/components/Scope.d.ts +2 -2
  35. package/dist/src/components/Scope.d.ts.map +1 -1
  36. package/dist/src/components/Scope.js +3 -6
  37. package/dist/src/components/Show.d.ts +1 -1
  38. package/dist/src/components/Show.d.ts.map +1 -1
  39. package/dist/src/components/SourceDirectory.d.ts +1 -1
  40. package/dist/src/components/SourceDirectory.d.ts.map +1 -1
  41. package/dist/src/components/SourceDirectory.js +1 -1
  42. package/dist/src/components/SourceFile.d.ts +1 -1
  43. package/dist/src/components/SourceFile.d.ts.map +1 -1
  44. package/dist/src/components/SourceFile.js +1 -1
  45. package/dist/src/components/StatementList.d.ts +1 -1
  46. package/dist/src/components/StatementList.d.ts.map +1 -1
  47. package/dist/src/components/StatementList.js +1 -1
  48. package/dist/src/components/Switch.d.ts +2 -2
  49. package/dist/src/components/Switch.d.ts.map +1 -1
  50. package/dist/src/components/Switch.js +2 -1
  51. package/dist/src/components/Wrap.d.ts +1 -1
  52. package/dist/src/components/Wrap.d.ts.map +1 -1
  53. package/dist/src/context/assignment.d.ts +1 -1
  54. package/dist/src/context/assignment.d.ts.map +1 -1
  55. package/dist/src/context/binder.d.ts +3 -3
  56. package/dist/src/context/binder.d.ts.map +1 -1
  57. package/dist/src/context/declaration.d.ts +1 -1
  58. package/dist/src/context/declaration.d.ts.map +1 -1
  59. package/dist/src/context/member-declaration.d.ts +1 -1
  60. package/dist/src/context/member-declaration.d.ts.map +1 -1
  61. package/dist/src/context/member-declaration.js +0 -1
  62. package/dist/src/context/member-scope.d.ts +1 -1
  63. package/dist/src/context/member-scope.d.ts.map +1 -1
  64. package/dist/src/context/name-policy.d.ts +1 -1
  65. package/dist/src/context/name-policy.d.ts.map +1 -1
  66. package/dist/src/context/scope.d.ts +1 -1
  67. package/dist/src/context/scope.d.ts.map +1 -1
  68. package/dist/src/context/source-directory.d.ts +1 -1
  69. package/dist/src/context/source-directory.d.ts.map +1 -1
  70. package/dist/src/context/source-file.d.ts +2 -2
  71. package/dist/src/context/source-file.d.ts.map +1 -1
  72. package/dist/src/context.d.ts +2 -2
  73. package/dist/src/context.d.ts.map +1 -1
  74. package/dist/src/context.js +1 -1
  75. package/dist/src/debug.d.ts +1 -0
  76. package/dist/src/debug.d.ts.map +1 -1
  77. package/dist/src/debug.js +4 -1
  78. package/dist/src/index.d.ts +8 -2
  79. package/dist/src/index.d.ts.map +1 -1
  80. package/dist/src/index.js +8 -2
  81. package/dist/src/jsx-runtime.d.ts +4 -272
  82. package/dist/src/jsx-runtime.d.ts.map +1 -1
  83. package/dist/src/jsx-runtime.js +3 -315
  84. package/dist/src/props-combinators.d.ts +19 -0
  85. package/dist/src/props-combinators.d.ts.map +1 -0
  86. package/dist/src/props-combinators.js +108 -0
  87. package/dist/src/reactive-union-set.d.ts +29 -0
  88. package/dist/src/reactive-union-set.d.ts.map +1 -0
  89. package/dist/src/reactive-union-set.js +183 -0
  90. package/dist/src/reactivity.d.ts +75 -0
  91. package/dist/src/reactivity.d.ts.map +1 -0
  92. package/dist/src/reactivity.js +141 -0
  93. package/dist/src/refkey.d.ts +36 -0
  94. package/dist/src/refkey.d.ts.map +1 -1
  95. package/dist/src/refkey.js +40 -0
  96. package/dist/src/render.d.ts +5 -1
  97. package/dist/src/render.d.ts.map +1 -1
  98. package/dist/src/render.js +68 -15
  99. package/dist/src/runtime/component.d.ts +24 -0
  100. package/dist/src/runtime/component.d.ts.map +1 -0
  101. package/dist/src/runtime/component.js +19 -0
  102. package/dist/src/runtime/intrinsic.d.ts +168 -0
  103. package/dist/src/runtime/intrinsic.d.ts.map +1 -0
  104. package/dist/src/runtime/intrinsic.js +11 -0
  105. package/dist/src/scheduler.d.ts +2 -2
  106. package/dist/src/scheduler.d.ts.map +1 -1
  107. package/dist/src/scheduler.js +27 -6
  108. package/dist/src/slot.d.ts +2 -2
  109. package/dist/src/slot.d.ts.map +1 -1
  110. package/dist/src/slot.js +1 -1
  111. package/dist/src/stc.d.ts +1 -1
  112. package/dist/src/stc.d.ts.map +1 -1
  113. package/dist/src/sti.d.ts +7 -6
  114. package/dist/src/sti.d.ts.map +1 -1
  115. package/dist/src/sti.js +1 -1
  116. package/dist/src/symbols/flags.d.ts +70 -0
  117. package/dist/src/symbols/flags.d.ts.map +1 -0
  118. package/dist/src/symbols/flags.js +72 -0
  119. package/dist/src/symbols/index.d.ts +7 -0
  120. package/dist/src/symbols/index.d.ts.map +1 -0
  121. package/dist/src/symbols/index.js +6 -0
  122. package/dist/src/symbols/output-scope.d.ts +94 -0
  123. package/dist/src/symbols/output-scope.d.ts.map +1 -0
  124. package/dist/src/symbols/output-scope.js +222 -0
  125. package/dist/src/symbols/output-symbol.d.ts +89 -0
  126. package/dist/src/symbols/output-symbol.d.ts.map +1 -0
  127. package/dist/src/symbols/output-symbol.js +333 -0
  128. package/dist/src/symbols/symbol-flow.d.ts +13 -0
  129. package/dist/src/symbols/symbol-flow.d.ts.map +1 -0
  130. package/dist/src/symbols/symbol-flow.js +74 -0
  131. package/dist/src/symbols/symbol-slot.d.ts +12 -0
  132. package/dist/src/symbols/symbol-slot.d.ts.map +1 -0
  133. package/dist/src/symbols/symbol-slot.js +36 -0
  134. package/dist/src/symbols/symbol-table.d.ts +14 -0
  135. package/dist/src/symbols/symbol-table.d.ts.map +1 -0
  136. package/dist/src/symbols/symbol-table.js +42 -0
  137. package/dist/src/tap.d.ts +3 -2
  138. package/dist/src/tap.d.ts.map +1 -1
  139. package/dist/src/tracer.d.ts +238 -0
  140. package/dist/src/tracer.d.ts.map +1 -0
  141. package/dist/src/tracer.js +496 -0
  142. package/dist/src/tsdoc-metadata.json +1 -1
  143. package/dist/src/utils.d.ts +4 -3
  144. package/dist/src/utils.d.ts.map +1 -1
  145. package/dist/src/utils.js +2 -1
  146. package/dist/test/components/slot.test.js +5 -7
  147. package/dist/test/props-with-defaults.test.js +1 -1
  148. package/dist/test/reactive-union-set.test.d.ts +2 -0
  149. package/dist/test/reactive-union-set.test.d.ts.map +1 -0
  150. package/dist/test/reactive-union-set.test.js +170 -0
  151. package/dist/test/reactivity/cleanup.test.js +2 -1
  152. package/dist/test/reactivity/memo.test.js +1 -1
  153. package/dist/test/reactivity/untrack.test.js +1 -1
  154. package/dist/test/rendering/memoization.test.js +2 -1
  155. package/dist/test/split-props.test.js +1 -1
  156. package/dist/test/symbols/output-scope.test.d.ts +2 -0
  157. package/dist/test/symbols/output-scope.test.d.ts.map +1 -0
  158. package/dist/test/symbols/output-scope.test.js +343 -0
  159. package/dist/test/symbols/output-symbol.test.d.ts +2 -0
  160. package/dist/test/symbols/output-symbol.test.d.ts.map +1 -0
  161. package/dist/test/symbols/output-symbol.test.js +447 -0
  162. package/dist/test/symbols/resolution.test.d.ts +2 -0
  163. package/dist/test/symbols/resolution.test.d.ts.map +1 -0
  164. package/dist/test/symbols/resolution.test.js +141 -0
  165. package/dist/test/symbols/utils.d.ts +25 -0
  166. package/dist/test/symbols/utils.d.ts.map +1 -0
  167. package/dist/test/symbols/utils.js +47 -0
  168. package/dist/testing/extend-expect.d.ts +15 -0
  169. package/dist/testing/extend-expect.d.ts.map +1 -1
  170. package/dist/testing/extend-expect.js +2 -1
  171. package/dist/testing/render.d.ts +1 -1
  172. package/dist/testing/render.d.ts.map +1 -1
  173. package/dist/tsconfig.tsbuildinfo +1 -1
  174. package/package.json +28 -24
  175. package/src/binder.ts +146 -672
  176. package/src/code.ts +1 -1
  177. package/src/components/Block.tsx +4 -1
  178. package/src/components/Declaration.tsx +8 -7
  179. package/src/components/For.tsx +2 -1
  180. package/src/components/Indent.tsx +1 -1
  181. package/src/components/List.tsx +3 -1
  182. package/src/components/MemberDeclaration.tsx +7 -6
  183. package/src/components/MemberScope.tsx +2 -5
  184. package/src/components/Output.tsx +2 -1
  185. package/src/components/Prose.tsx +1 -1
  186. package/src/components/ReferenceOrContent.tsx +1 -1
  187. package/src/components/Scope.tsx +3 -7
  188. package/src/components/Show.tsx +1 -1
  189. package/src/components/SourceDirectory.tsx +2 -1
  190. package/src/components/SourceFile.tsx +2 -1
  191. package/src/components/StatementList.tsx +2 -1
  192. package/src/components/Switch.tsx +2 -1
  193. package/src/components/Wrap.tsx +1 -1
  194. package/src/context/assignment.ts +1 -1
  195. package/src/context/binder.ts +3 -3
  196. package/src/context/declaration.ts +1 -1
  197. package/src/context/member-declaration.ts +1 -1
  198. package/src/context/member-scope.ts +1 -1
  199. package/src/context/name-policy.ts +1 -1
  200. package/src/context/scope.ts +1 -1
  201. package/src/context/source-directory.ts +1 -1
  202. package/src/context/source-file.ts +2 -2
  203. package/src/context.ts +3 -7
  204. package/src/debug.ts +5 -1
  205. package/src/index.ts +15 -1
  206. package/src/jsx-runtime.ts +15 -674
  207. package/src/props-combinators.ts +148 -0
  208. package/src/reactive-union-set.ts +238 -0
  209. package/src/reactivity.ts +230 -0
  210. package/src/refkey.ts +40 -0
  211. package/src/render.ts +97 -26
  212. package/src/runtime/component.ts +67 -0
  213. package/src/runtime/intrinsic.ts +199 -0
  214. package/src/scheduler.ts +31 -6
  215. package/src/slot.ts +3 -4
  216. package/src/stc.ts +2 -2
  217. package/src/sti.ts +11 -11
  218. package/src/symbols/flags.ts +82 -0
  219. package/src/symbols/index.ts +6 -0
  220. package/src/symbols/output-scope.ts +296 -0
  221. package/src/symbols/output-symbol.ts +459 -0
  222. package/src/symbols/symbol-flow.ts +100 -0
  223. package/src/symbols/symbol-slot.tsx +48 -0
  224. package/src/symbols/symbol-table.ts +72 -0
  225. package/src/tap.ts +3 -2
  226. package/src/tracer.ts +474 -0
  227. package/src/utils.tsx +7 -5
  228. package/temp/api.json +7446 -5133
  229. package/test/components/slot.test.tsx +8 -11
  230. package/test/props-with-defaults.test.ts +1 -1
  231. package/test/reactive-union-set.test.tsx +191 -0
  232. package/test/reactivity/cleanup.test.tsx +2 -1
  233. package/test/reactivity/memo.test.tsx +1 -1
  234. package/test/reactivity/untrack.test.ts +1 -1
  235. package/test/rendering/basic.test.tsx +1 -1
  236. package/test/rendering/memoization.test.tsx +1 -1
  237. package/test/split-props.test.ts +1 -1
  238. package/test/symbols/output-scope.test.ts +300 -0
  239. package/test/symbols/output-symbol.test.ts +456 -0
  240. package/test/symbols/resolution.test.ts +170 -0
  241. package/test/symbols/utils.ts +93 -0
  242. package/test/utils.test.tsx +1 -1
  243. package/testing/extend-expect.ts +16 -0
  244. package/testing/render.ts +1 -2
  245. package/LICENSE +0 -7
  246. package/dist/test/symbols.test.d.ts +0 -2
  247. package/dist/test/symbols.test.d.ts.map +0 -1
  248. package/dist/test/symbols.test.js +0 -884
  249. package/test/symbols.test.ts +0 -1006
@@ -0,0 +1,333 @@
1
+ import { reactive, ReactiveFlags, shallowReactive, track, TrackOpTypes, trigger, TriggerOpTypes, watch } from "@vue/reactivity";
2
+ import { useBinder } from "../context/binder.js";
3
+ import { useMemberScope } from "../context/member-scope.js";
4
+ import { useScope } from "../context/scope.js";
5
+ import { isRefkey, refkey } from "../refkey.js";
6
+ import { formatScopeName, formatSymbol, formatSymbolName, trace, traceEffect, TracePhase } from "../tracer.js";
7
+ import { OutputScopeFlags, OutputSymbolFlags } from "./flags.js";
8
+ import { OutputScope } from "./output-scope.js";
9
+ let symbolCount = 0;
10
+
11
+ /**
12
+ * An output symbol is a named entity that can be referenced in your output
13
+ * code.
14
+ *
15
+ * @remarks
16
+ *
17
+ * This class is the base implementation of symbol. Most languages will have
18
+ * subtypes that provide additional metadata. Symbols are reactive values, so
19
+ * you can observe changes to their properties in a reactive context.
20
+ */
21
+ export class OutputSymbol {
22
+ #originalName;
23
+ get originalName() {
24
+ return this.#originalName;
25
+ }
26
+ #name;
27
+ get name() {
28
+ track(this, TrackOpTypes.GET, "name");
29
+ return this.#name;
30
+ }
31
+ set name(name) {
32
+ const old = this.#name;
33
+ if (old === name) {
34
+ return;
35
+ }
36
+ this.#name = name;
37
+ trigger(this, TriggerOpTypes.SET, "name", name, old);
38
+ }
39
+ #id;
40
+ get id() {
41
+ return this.#id;
42
+ }
43
+ #flags;
44
+ get flags() {
45
+ track(this, TrackOpTypes.GET, "flags");
46
+ return this.#flags;
47
+ }
48
+ set flags(flags) {
49
+ const old = this.#flags;
50
+ if (old === flags) {
51
+ return;
52
+ }
53
+ this.#flags = flags;
54
+ trigger(this, TriggerOpTypes.SET, "flags", flags, old);
55
+ this.#createInstanceMemberScope();
56
+ this.#createStaticMemberScope();
57
+ }
58
+ #scope;
59
+ get scope() {
60
+ track(this, TrackOpTypes.GET, "scope");
61
+ return this.#scope;
62
+ }
63
+ set scope(scope) {
64
+ const old = this.#scope;
65
+ if (old === scope) {
66
+ return;
67
+ }
68
+ this.#handleNewScope(scope, old);
69
+ this.#scope = scope;
70
+ trigger(this, TriggerOpTypes.SET, "scope", scope, old);
71
+ }
72
+ #handleNewScope(newScope, oldScope) {
73
+ if (oldScope) {
74
+ // ensure when changing scope that this symbol only belongs to one of them
75
+ oldScope.symbols.delete(this);
76
+ }
77
+ if (!newScope) {
78
+ return;
79
+ }
80
+ newScope.symbols.add(this);
81
+ if (newScope.flags & OutputScopeFlags.InstanceMemberScope) {
82
+ this.flags |= OutputSymbolFlags.InstanceMember;
83
+ }
84
+ if (newScope.flags & OutputScopeFlags.StaticMemberScope) {
85
+ this.flags |= OutputSymbolFlags.StaticMember;
86
+ }
87
+ }
88
+ #binder;
89
+ get binder() {
90
+ return this.#binder;
91
+ }
92
+ #refkeys;
93
+ get refkeys() {
94
+ track(this, TrackOpTypes.GET, "refkeys");
95
+ return this.#refkeys;
96
+ }
97
+ set refkeys(refkeys) {
98
+ const old = this.#refkeys;
99
+ if (old === refkeys) {
100
+ return;
101
+ }
102
+ this.#refkeys = shallowReactive(Array.isArray(refkeys) ? refkeys : [refkeys]);
103
+ trigger(this, TriggerOpTypes.SET, "refkeys", this.#refkeys, old);
104
+ }
105
+ #instanceMemberScope;
106
+ get instanceMemberScope() {
107
+ track(this, TrackOpTypes.GET, "instanceMemberScope");
108
+ return this.#instanceMemberScope;
109
+ }
110
+ #aliasTarget;
111
+ get aliasTarget() {
112
+ return this.#aliasTarget;
113
+ }
114
+ #createInstanceMemberScope() {
115
+ if (this.#instanceMemberScope || !(this.#flags & OutputSymbolFlags.InstanceMemberContainer)) {
116
+ return;
117
+ }
118
+ this.#instanceMemberScope = new OutputScope(`${this.name} instance members`, {
119
+ binder: this.#binder,
120
+ owner: this,
121
+ flags: OutputScopeFlags.InstanceMemberScope
122
+ });
123
+ trigger(this, TriggerOpTypes.SET, "instanceMemberScope", this.#instanceMemberScope, undefined);
124
+ }
125
+
126
+ /**
127
+ * Create an output scope to hold member symbols. By default this just creates
128
+ * an OutputScope, but can be subclassed to build scope subtypes when needed.
129
+ */
130
+ createMemberScope(name, options) {
131
+ return new OutputScope(name, {
132
+ binder: this.#binder,
133
+ owner: options.owner,
134
+ flags: options.flags
135
+ });
136
+ }
137
+ #staticMemberScope;
138
+ get staticMemberScope() {
139
+ track(this, TrackOpTypes.GET, "staticMemberScope");
140
+ return this.#staticMemberScope;
141
+ }
142
+ #createStaticMemberScope() {
143
+ if (this.#staticMemberScope || !(this.#flags & OutputSymbolFlags.StaticMemberContainer)) {
144
+ return;
145
+ }
146
+ this.#staticMemberScope = new OutputScope(`${this.name} static members`, {
147
+ binder: this.#binder,
148
+ owner: this,
149
+ flags: OutputScopeFlags.StaticMemberScope
150
+ });
151
+ trigger(this, TriggerOpTypes.SET, "staticMemberScope", this.#staticMemberScope, undefined);
152
+ }
153
+ #metadata;
154
+ get metadata() {
155
+ return this.#metadata;
156
+ }
157
+
158
+ /**
159
+ * Tell \@vue/reactivity that this symbol should never be wrapped in a reactive
160
+ * proxy.
161
+ */
162
+ [ReactiveFlags.SKIP] = true;
163
+ constructor(name, options = {}) {
164
+ this.#binder = options.binder ?? useBinder();
165
+ this.#name = name;
166
+ this.#originalName = name;
167
+ this.#id = symbolCount++;
168
+ this.#flags = options.flags ?? OutputSymbolFlags.None;
169
+ this.#scope = options.scope ?? this.#defaultScope();
170
+ this.#aliasTarget = options.aliasTarget;
171
+ if (this.#aliasTarget) {
172
+ this.#flags |= OutputSymbolFlags.Alias;
173
+ this.#flags &= ~(OutputSymbolFlags.MemberContainer | OutputSymbolFlags.Member);
174
+ }
175
+ this.#refkeys = shallowReactive(Array.isArray(options.refkeys) ? options.refkeys : isRefkey(options.refkeys) ? [options.refkeys] : []);
176
+ this.#metadata = reactive(options.metadata ?? {});
177
+ this.#createInstanceMemberScope();
178
+ this.#createStaticMemberScope();
179
+ this.#handleNewScope(this.#scope);
180
+ trace(TracePhase.symbol.create, () => `${formatSymbol(this)}`);
181
+ traceEffect(TracePhase.symbol.update, () => {
182
+ return `${formatSymbol(this)}`;
183
+ });
184
+ this.#binder?.notifySymbolCreated(this);
185
+ }
186
+ delete() {
187
+ trace(TracePhase.symbol.delete, () => `${formatSymbolName(this)}`);
188
+ if (this.#scope) {
189
+ this.#scope.symbols.delete(this);
190
+ }
191
+ this.#binder?.notifySymbolDeleted(this);
192
+ }
193
+
194
+ /**
195
+ * Takes the instance members or static members on this symbol and creates
196
+ * corresponding static members on the target symbol. Instance or static
197
+ * members of instantiated symbols are copied. The refkey of any instantiated
198
+ * symbols are set to a composite refkey of the target symbol's refkey and the
199
+ * instantiated symbol's refkey.
200
+ */
201
+ instantiateTo(targetSymbol) {
202
+ if (this.#aliasTarget) {
203
+ return this.#aliasTarget.instantiateTo(targetSymbol);
204
+ }
205
+ trace(TracePhase.symbol.instantiate, () => {
206
+ return `${formatSymbolName(this)} -> ${formatSymbolName(targetSymbol)}`;
207
+ });
208
+ const from = this.#instanceMemberScope ?? this.#staticMemberScope;
209
+ if (from) {
210
+ targetSymbol.flags |= OutputSymbolFlags.StaticMemberContainer;
211
+ targetSymbol.#createStaticMemberScope();
212
+ targetSymbol.#staticMemberScope.copySymbolsFrom(from, {
213
+ onAdd: symbol => {
214
+ const clone = symbol.copyToScope(targetSymbol.#staticMemberScope, targetSymbol);
215
+ clone.#flags &= ~OutputSymbolFlags.InstanceMember;
216
+ clone.#flags |= OutputSymbolFlags.StaticMember;
217
+ return clone;
218
+ }
219
+ });
220
+ }
221
+ }
222
+ #instantiationRk(base, member) {
223
+ const instantiationRks = [];
224
+ for (const baseRk of base.refkeys) {
225
+ for (const targetRk of member.refkeys) {
226
+ instantiationRks.push(refkey(baseRk, targetRk));
227
+ }
228
+ }
229
+ return instantiationRks;
230
+ }
231
+
232
+ /**
233
+ * Copy member symbols from the target symbol into the target symbol. The
234
+ * copied symbols have their refkey set to
235
+ * `refkey(targetSymbol.refkey, this.refkey)`.
236
+ */
237
+ copyTo(targetSymbol) {
238
+ if (this.#aliasTarget) {
239
+ return this.#aliasTarget.copyTo(targetSymbol);
240
+ }
241
+ if (this.staticMemberScope) {
242
+ targetSymbol.flags |= OutputSymbolFlags.StaticMemberContainer;
243
+ targetSymbol.staticMemberScope.copySymbolsFrom(this.staticMemberScope);
244
+ }
245
+ if (this.instanceMemberScope) {
246
+ targetSymbol.flags |= OutputSymbolFlags.InstanceMemberContainer;
247
+ targetSymbol.instanceMemberScope.copySymbolsFrom(this.instanceMemberScope);
248
+ }
249
+ }
250
+
251
+ /**
252
+ * Move member symbols from this transient symbol to the target symbol.
253
+ */
254
+ moveTo(targetSymbol) {
255
+ if (this.#aliasTarget) {
256
+ return this.#aliasTarget.moveTo(targetSymbol);
257
+ }
258
+ if (!(this.flags & OutputSymbolFlags.Transient)) {
259
+ throw new Error("Can only move members from transient symbols");
260
+ }
261
+ if (this.staticMemberScope) {
262
+ targetSymbol.flags |= OutputSymbolFlags.StaticMemberContainer;
263
+ targetSymbol.staticMemberScope.moveSymbolsFrom(this.staticMemberScope);
264
+ }
265
+ if (this.instanceMemberScope) {
266
+ targetSymbol.flags |= OutputSymbolFlags.InstanceMemberContainer;
267
+ targetSymbol.instanceMemberScope.moveSymbolsFrom(this.instanceMemberScope);
268
+ }
269
+ }
270
+
271
+ /**
272
+ * Makes a copy of this symbol which will update the name and flags
273
+ * of the clone when the original symbol is updated.
274
+ *
275
+ * @remarks
276
+ *
277
+ * This is used to create a symbol that is a copy of this symbol, but
278
+ * with a different scope. Changes to the copy will not affect the
279
+ * original symbol, and changes to the original symbol's name and flags
280
+ * will overwrite the copy's name and flags.
281
+ *
282
+ * @param newScope - The scope to use for the copy.
283
+ */
284
+ copyToScope(newScope, baseSymbol) {
285
+ if (this.#aliasTarget) {
286
+ return this.#aliasTarget.copyToScope(newScope, baseSymbol);
287
+ }
288
+ trace(TracePhase.symbol.clone, () => {
289
+ return `${formatSymbolName(this)} -> ${formatScopeName(newScope)}`;
290
+ });
291
+ const clone = new OutputSymbol(this.#name, {
292
+ binder: this.#binder,
293
+ scope: newScope,
294
+ flags: this.#flags,
295
+ refkeys: baseSymbol ? this.#instantiationRk(baseSymbol, this) : [],
296
+ metadata: this.#metadata
297
+ });
298
+ if (this.instanceMemberScope) {
299
+ clone.#instanceMemberScope = this.instanceMemberScope.clone({
300
+ owner: clone
301
+ });
302
+ }
303
+ if (this.staticMemberScope) {
304
+ clone.#staticMemberScope = this.staticMemberScope.clone({
305
+ owner: clone
306
+ });
307
+ }
308
+ watch(() => this.name, newName => clone.name = newName);
309
+ watch(() => this.flags, newFlags => clone.flags = newFlags);
310
+ return clone;
311
+ }
312
+ #defaultScope() {
313
+ if ((this.#flags & OutputSymbolFlags.Member) === 0) {
314
+ return useScope();
315
+ } else {
316
+ const memberScope = useMemberScope();
317
+ if (!memberScope) {
318
+ throw new Error("Cannot declare member symbols without a member scope");
319
+ }
320
+ if (this.#flags & OutputSymbolFlags.InstanceMember) {
321
+ if (!memberScope.instanceMembers) {
322
+ throw new Error("Cannot declare instance member symbols without an instance member scope");
323
+ }
324
+ return memberScope.instanceMembers;
325
+ } else {
326
+ if (!memberScope.staticMembers) {
327
+ throw new Error("Cannot declare static member symbols without a static member scope");
328
+ }
329
+ return memberScope.staticMembers;
330
+ }
331
+ }
332
+ }
333
+ }
@@ -0,0 +1,13 @@
1
+ import { Ref } from "@vue/reactivity";
2
+ import { OutputSymbol } from "./output-symbol.js";
3
+ export interface TakeSymbolCallback {
4
+ (symbol: OutputSymbol): void;
5
+ }
6
+ export interface TakeSymbolsCallback {
7
+ (symbols: Set<OutputSymbol>): void;
8
+ }
9
+ export declare function takeSymbols(cb?: (symbol: OutputSymbol) => void): import("@vue/reactivity").ShallowReactive<Set<OutputSymbol>>;
10
+ export declare function emitSymbol(symbol: OutputSymbol | Ref<OutputSymbol | undefined>): void;
11
+ export declare function moveTakenMembersTo(baseSymbol: OutputSymbol): void;
12
+ export declare function instantiateTakenMembersTo(baseSymbol: OutputSymbol): void;
13
+ //# sourceMappingURL=symbol-flow.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"symbol-flow.d.ts","sourceRoot":"","sources":["../../../src/symbols/symbol-flow.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,GAAG,EAAmB,MAAM,iBAAiB,CAAC;AAM9D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,MAAM,WAAW,kBAAkB;IACjC,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI,CAAC;CAC9B;AAED,MAAM,WAAW,mBAAmB;IAClC,CAAC,OAAO,EAAE,GAAG,CAAC,YAAY,CAAC,GAAG,IAAI,CAAC;CACpC;AAED,wBAAgB,WAAW,CAAC,EAAE,CAAC,EAAE,CAAC,MAAM,EAAE,YAAY,KAAK,IAAI,gEAiB9D;AAED,wBAAgB,UAAU,CACxB,MAAM,EAAE,YAAY,GAAG,GAAG,CAAC,YAAY,GAAG,SAAS,CAAC,QA+CrD;AAED,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,YAAY,QAU1D;AAED,wBAAgB,yBAAyB,CAAC,UAAU,EAAE,YAAY,QAEjE"}
@@ -0,0 +1,74 @@
1
+ import { isRef, shallowReactive } from "@vue/reactivity";
2
+ import { effect, getContext, onCleanup } from "../reactivity.js";
3
+ import { MemberScopeContext } from "../context/member-scope.js";
4
+ import { ScopeContext } from "../context/scope.js";
5
+ import { OutputSymbolFlags } from "./flags.js";
6
+ export function takeSymbols(cb) {
7
+ const context = getContext();
8
+ context.takesSymbols = true;
9
+ context.takenSymbols = shallowReactive(new Set());
10
+ if (cb) {
11
+ effect(oldSymbols => {
12
+ for (const symbol of context.takenSymbols) {
13
+ if (oldSymbols && oldSymbols.has(symbol)) {
14
+ continue;
15
+ }
16
+ cb(symbol);
17
+ }
18
+ return new Set(context.takenSymbols);
19
+ });
20
+ }
21
+ return context.takenSymbols;
22
+ }
23
+ export function emitSymbol(symbol) {
24
+ let symbolTaker;
25
+ let context = getContext().owner;
26
+ while (context) {
27
+ if (context.takesSymbols) {
28
+ symbolTaker = context;
29
+ break;
30
+ }
31
+ if (context.context && (context.context[ScopeContext.id] || context.context[MemberScopeContext.id])) {
32
+ // don't cross scope boundaries.
33
+ break;
34
+ }
35
+ context = context.owner;
36
+ }
37
+ if (!symbolTaker) {
38
+ return;
39
+ }
40
+ if (isRef(symbol)) {
41
+ effect(prevSymbol => {
42
+ onCleanup(() => {
43
+ if (symbol.value) {
44
+ symbolTaker.takenSymbols.delete(symbol.value);
45
+ }
46
+ });
47
+ if (symbol.value === undefined) {
48
+ symbolTaker.takenSymbols.delete(prevSymbol);
49
+ return undefined;
50
+ } else {
51
+ symbolTaker.takenSymbols.add(symbol.value);
52
+ return symbol.value;
53
+ }
54
+ });
55
+ } else {
56
+ symbolTaker.takenSymbols.add(symbol);
57
+ onCleanup(() => {
58
+ context.takenSymbols.delete(symbol);
59
+ });
60
+ }
61
+ }
62
+ export function moveTakenMembersTo(baseSymbol) {
63
+ const taken = takeSymbols();
64
+ effect(() => {
65
+ for (const symbol of taken) {
66
+ if (symbol.flags & OutputSymbolFlags.Transient) {
67
+ symbol.moveTo(baseSymbol);
68
+ }
69
+ }
70
+ });
71
+ }
72
+ export function instantiateTakenMembersTo(baseSymbol) {
73
+ takeSymbols(symbol => symbol.instantiateTo(baseSymbol));
74
+ }
@@ -0,0 +1,12 @@
1
+ import { Ref, ShallowReactive } from "@vue/reactivity";
2
+ import type { Children } from "../runtime/component.js";
3
+ import { OutputSymbol } from "./output-symbol.js";
4
+ export declare function createSymbolSlot(): {
5
+ (props: {
6
+ children: Children;
7
+ }): Children;
8
+ ref: Ref<ShallowReactive<Set<OutputSymbol>> | undefined, ShallowReactive<Set<OutputSymbol>> | undefined>;
9
+ instantiateInto(baseSymbol: OutputSymbol): void;
10
+ copyInto(baseSymbol: OutputSymbol): void;
11
+ };
12
+ //# sourceMappingURL=symbol-slot.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"symbol-slot.d.ts","sourceRoot":"","sources":["../../../src/symbols/symbol-slot.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,eAAe,EAAc,MAAM,iBAAiB,CAAC;AAEnE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGlD,wBAAgB,gBAAgB;YAGH;QAAE,QAAQ,EAAE,QAAQ,CAAA;KAAE;;gCAaP,YAAY;yBAYnB,YAAY;EAahD"}
@@ -0,0 +1,36 @@
1
+ import { shallowRef } from "@vue/reactivity";
2
+ import { effect, onCleanup } from "../reactivity.js";
3
+ import { takeSymbols } from "./symbol-flow.js";
4
+ export function createSymbolSlot() {
5
+ const symbolSlotRef = shallowRef();
6
+ function SymbolSlot(props) {
7
+ const set = takeSymbols();
8
+ symbolSlotRef.value = set;
9
+ onCleanup(() => {
10
+ symbolSlotRef.value = undefined;
11
+ });
12
+ return props.children;
13
+ }
14
+ SymbolSlot.ref = symbolSlotRef;
15
+ SymbolSlot.instantiateInto = baseSymbol => {
16
+ effect(() => {
17
+ if (!symbolSlotRef.value) {
18
+ return;
19
+ }
20
+ for (const symbol of symbolSlotRef.value) {
21
+ symbol.instantiateTo(baseSymbol);
22
+ }
23
+ });
24
+ };
25
+ SymbolSlot.copyInto = baseSymbol => {
26
+ effect(() => {
27
+ if (!symbolSlotRef.value) {
28
+ return;
29
+ }
30
+ for (const symbol of symbolSlotRef.value) {
31
+ symbol.copyTo(baseSymbol);
32
+ }
33
+ });
34
+ };
35
+ return SymbolSlot;
36
+ }
@@ -0,0 +1,14 @@
1
+ import type { NameConflictResolver } from "../binder.js";
2
+ import { ReactiveUnionSet } from "../reactive-union-set.js";
3
+ import type { OutputScope } from "./output-scope.js";
4
+ import type { OutputSymbol } from "./output-symbol.js";
5
+ export declare class SymbolTable extends ReactiveUnionSet<OutputSymbol> {
6
+ private _namesToDeconflict;
7
+ private _nameConflictResolver?;
8
+ private _deconflictNames;
9
+ scope: OutputScope;
10
+ constructor(scope: OutputScope, options?: {
11
+ nameConflictResolver?: NameConflictResolver;
12
+ });
13
+ }
14
+ //# sourceMappingURL=symbol-table.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"symbol-table.d.ts","sourceRoot":"","sources":["../../../src/symbols/symbol-table.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAQ5D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD,qBAAa,WAAY,SAAQ,gBAAgB,CAAC,YAAY,CAAC;IAC7D,OAAO,CAAC,kBAAkB,CAA0B;IACpD,OAAO,CAAC,qBAAqB,CAAC,CAAuB;IACrD,OAAO,CAAC,gBAAgB,CAYtB;IACK,KAAK,cAAC;gBAEX,KAAK,EAAE,WAAW,EAClB,OAAO,GAAE;QACP,oBAAoB,CAAC,EAAE,oBAAoB,CAAC;KACxC;CA2BT"}
@@ -0,0 +1,42 @@
1
+ import { ReactiveUnionSet } from "../reactive-union-set.js";
2
+ import { queueJob } from "../scheduler.js";
3
+ import { formatScopeName, formatSymbolName, trace, TracePhase } from "../tracer.js";
4
+ export class SymbolTable extends ReactiveUnionSet {
5
+ _namesToDeconflict = new Set();
6
+ _deconflictNames = () => {
7
+ for (const name of this._namesToDeconflict) {
8
+ const conflictedSymbols = [...this].filter(sym => sym.originalName === name);
9
+ if (this._nameConflictResolver) {
10
+ this._nameConflictResolver(name, conflictedSymbols);
11
+ } else {
12
+ defaultConflictHandler(name, conflictedSymbols);
13
+ }
14
+ this._namesToDeconflict.delete(name);
15
+ }
16
+ };
17
+ constructor(scope, options = {}) {
18
+ super({
19
+ onAdd: symbol => {
20
+ trace(TracePhase.symbol.addToScope, () => `${formatSymbolName(symbol)} -> ${formatScopeName(scope)}`);
21
+ this._namesToDeconflict.add(symbol.name);
22
+ queueJob(this._deconflictNames);
23
+ return symbol;
24
+ },
25
+ onDelete(symbol) {
26
+ trace(TracePhase.symbol.removeFromScope, () => `${formatSymbolName(symbol)} -> ${formatScopeName(scope)}`);
27
+ }
28
+ });
29
+ this.scope = scope;
30
+ this._nameConflictResolver = options.nameConflictResolver;
31
+ }
32
+ }
33
+
34
+ /**
35
+ * Default conflict handler. This will rename all but the first symbol
36
+ * to have a suffix of _2, _3, etc.
37
+ */
38
+ function defaultConflictHandler(_, conflictedSymbols) {
39
+ for (let i = 1; i < conflictedSymbols.length; i++) {
40
+ conflictedSymbols[i].name = conflictedSymbols[i].originalName + "_" + (i + 1);
41
+ }
42
+ }
package/dist/src/tap.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import { ShallowRef } from "@vue/reactivity";
2
- import { OutputScope, OutputSymbol } from "./binder.js";
3
2
  import { SourceFileContext } from "./context/source-file.js";
4
- import { ComponentDefinition } from "./jsx-runtime.js";
3
+ import type { ComponentDefinition } from "./runtime/component.js";
4
+ import { OutputScope } from "./symbols/output-scope.js";
5
+ import { OutputSymbol } from "./symbols/output-symbol.js";
5
6
  /**
6
7
  * The return value of {@link createTap}, this holds a reference to the tapped
7
8
  * value. It will be undefined until the tapped value is initialized.
@@ -1 +1 @@
1
- {"version":3,"file":"tap.d.ts","sourceRoot":"","sources":["../../src/tap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAc,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAKxD,OAAO,EAAE,iB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