@alloy-js/core 0.20.0-dev.4 → 0.20.0-dev.7

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 (334) hide show
  1. package/dist/src/binder.d.ts +74 -38
  2. package/dist/src/binder.d.ts.map +1 -1
  3. package/dist/src/binder.js +235 -173
  4. package/dist/src/binder.js.map +1 -0
  5. package/dist/src/code.js +2 -1
  6. package/dist/src/code.js.map +1 -0
  7. package/dist/src/components/AppendFile.js +2 -1
  8. package/dist/src/components/AppendFile.js.map +1 -0
  9. package/dist/src/components/Block.js +2 -1
  10. package/dist/src/components/Block.js.map +1 -0
  11. package/dist/src/components/CopyFile.js +2 -1
  12. package/dist/src/components/CopyFile.js.map +1 -0
  13. package/dist/src/components/Declaration.d.ts +2 -2
  14. package/dist/src/components/Declaration.d.ts.map +1 -1
  15. package/dist/src/components/Declaration.js +10 -3
  16. package/dist/src/components/Declaration.js.map +1 -0
  17. package/dist/src/components/For.js +2 -1
  18. package/dist/src/components/For.js.map +1 -0
  19. package/dist/src/components/Indent.js +2 -1
  20. package/dist/src/components/Indent.js.map +1 -0
  21. package/dist/src/components/List.js +2 -1
  22. package/dist/src/components/List.js.map +1 -0
  23. package/dist/src/components/MemberDeclaration.d.ts +2 -2
  24. package/dist/src/components/MemberDeclaration.d.ts.map +1 -1
  25. package/dist/src/components/MemberDeclaration.js +11 -6
  26. package/dist/src/components/MemberDeclaration.js.map +1 -0
  27. package/dist/src/components/MemberName.js +2 -1
  28. package/dist/src/components/MemberName.js.map +1 -0
  29. package/dist/src/components/MemberScope.d.ts +30 -13
  30. package/dist/src/components/MemberScope.d.ts.map +1 -1
  31. package/dist/src/components/MemberScope.js +39 -16
  32. package/dist/src/components/MemberScope.js.map +1 -0
  33. package/dist/src/components/Name.js +2 -1
  34. package/dist/src/components/Name.js.map +1 -0
  35. package/dist/src/components/Output.d.ts.map +1 -1
  36. package/dist/src/components/Output.js +4 -6
  37. package/dist/src/components/Output.js.map +1 -0
  38. package/dist/src/components/Prose.js +2 -1
  39. package/dist/src/components/Prose.js.map +1 -0
  40. package/dist/src/components/ReferenceOrContent.d.ts +1 -1
  41. package/dist/src/components/ReferenceOrContent.d.ts.map +1 -1
  42. package/dist/src/components/ReferenceOrContent.js +2 -1
  43. package/dist/src/components/ReferenceOrContent.js.map +1 -0
  44. package/dist/src/components/Scope.d.ts +5 -5
  45. package/dist/src/components/Scope.d.ts.map +1 -1
  46. package/dist/src/components/Scope.js +11 -6
  47. package/dist/src/components/Scope.js.map +1 -0
  48. package/dist/src/components/Show.js +2 -1
  49. package/dist/src/components/Show.js.map +1 -0
  50. package/dist/src/components/SourceDirectory.js +2 -1
  51. package/dist/src/components/SourceDirectory.js.map +1 -0
  52. package/dist/src/components/SourceFile.js +2 -1
  53. package/dist/src/components/SourceFile.js.map +1 -0
  54. package/dist/src/components/StatementList.js +2 -1
  55. package/dist/src/components/StatementList.js.map +1 -0
  56. package/dist/src/components/Switch.js +2 -1
  57. package/dist/src/components/Switch.js.map +1 -0
  58. package/dist/src/components/TemplateFile.js +2 -1
  59. package/dist/src/components/TemplateFile.js.map +1 -0
  60. package/dist/src/components/UpdateFile.js +2 -1
  61. package/dist/src/components/UpdateFile.js.map +1 -0
  62. package/dist/src/components/Wrap.js +2 -1
  63. package/dist/src/components/Wrap.js.map +1 -0
  64. package/dist/src/components/index.js +2 -1
  65. package/dist/src/components/index.js.map +1 -0
  66. package/dist/src/components/stc/index.js +2 -1
  67. package/dist/src/components/stc/index.js.map +1 -0
  68. package/dist/src/components/stc/sti.js +2 -1
  69. package/dist/src/components/stc/sti.js.map +1 -0
  70. package/dist/src/context/assignment.js +2 -1
  71. package/dist/src/context/assignment.js.map +1 -0
  72. package/dist/src/context/binder.js +2 -1
  73. package/dist/src/context/binder.js.map +1 -0
  74. package/dist/src/context/declaration.js +2 -1
  75. package/dist/src/context/declaration.js.map +1 -0
  76. package/dist/src/context/index.js +2 -1
  77. package/dist/src/context/index.js.map +1 -0
  78. package/dist/src/context/member-declaration.js +2 -1
  79. package/dist/src/context/member-declaration.js.map +1 -0
  80. package/dist/src/context/member-scope.d.ts +7 -8
  81. package/dist/src/context/member-scope.d.ts.map +1 -1
  82. package/dist/src/context/member-scope.js +7 -6
  83. package/dist/src/context/member-scope.js.map +1 -0
  84. package/dist/src/context/name-policy.d.ts.map +1 -1
  85. package/dist/src/context/name-policy.js +5 -1
  86. package/dist/src/context/name-policy.js.map +1 -0
  87. package/dist/src/context/scope.d.ts +1 -0
  88. package/dist/src/context/scope.d.ts.map +1 -1
  89. package/dist/src/context/scope.js +9 -1
  90. package/dist/src/context/scope.js.map +1 -0
  91. package/dist/src/context/source-directory.js +2 -1
  92. package/dist/src/context/source-directory.js.map +1 -0
  93. package/dist/src/context/source-file.js +2 -1
  94. package/dist/src/context/source-file.js.map +1 -0
  95. package/dist/src/context.js +2 -1
  96. package/dist/src/context.js.map +1 -0
  97. package/dist/src/debug.js +2 -1
  98. package/dist/src/debug.js.map +1 -0
  99. package/dist/src/host/alloy-host.browser.js +2 -1
  100. package/dist/src/host/alloy-host.browser.js.map +1 -0
  101. package/dist/src/host/alloy-host.js +2 -1
  102. package/dist/src/host/alloy-host.js.map +1 -0
  103. package/dist/src/host/interface.js +2 -1
  104. package/dist/src/host/interface.js.map +1 -0
  105. package/dist/src/index.browser.js +2 -1
  106. package/dist/src/index.browser.js.map +1 -0
  107. package/dist/src/index.js +2 -1
  108. package/dist/src/index.js.map +1 -0
  109. package/dist/src/inspect.browser.d.ts +5 -0
  110. package/dist/src/inspect.browser.d.ts.map +1 -0
  111. package/dist/src/inspect.browser.js +6 -0
  112. package/dist/src/inspect.browser.js.map +1 -0
  113. package/dist/src/inspect.d.ts +2 -0
  114. package/dist/src/inspect.d.ts.map +1 -0
  115. package/dist/src/inspect.js +2 -0
  116. package/dist/src/inspect.js.map +1 -0
  117. package/dist/src/jsx-runtime.js +2 -1
  118. package/dist/src/jsx-runtime.js.map +1 -0
  119. package/dist/src/name-policy.d.ts +11 -0
  120. package/dist/src/name-policy.d.ts.map +1 -1
  121. package/dist/src/name-policy.js +5 -1
  122. package/dist/src/name-policy.js.map +1 -0
  123. package/dist/src/props-combinators.js +2 -1
  124. package/dist/src/props-combinators.js.map +1 -0
  125. package/dist/src/reactive-union-set.d.ts.map +1 -1
  126. package/dist/src/reactive-union-set.js +14 -9
  127. package/dist/src/reactive-union-set.js.map +1 -0
  128. package/dist/src/reactivity.js +2 -1
  129. package/dist/src/reactivity.js.map +1 -0
  130. package/dist/src/refkey.d.ts +39 -3
  131. package/dist/src/refkey.d.ts.map +1 -1
  132. package/dist/src/refkey.js +65 -10
  133. package/dist/src/refkey.js.map +1 -0
  134. package/dist/src/render.js +2 -1
  135. package/dist/src/render.js.map +1 -0
  136. package/dist/src/resource.js +2 -1
  137. package/dist/src/resource.js.map +1 -0
  138. package/dist/src/runtime/component.js +2 -1
  139. package/dist/src/runtime/component.js.map +1 -0
  140. package/dist/src/runtime/intrinsic.js +2 -1
  141. package/dist/src/runtime/intrinsic.js.map +1 -0
  142. package/dist/src/scheduler.js +2 -1
  143. package/dist/src/scheduler.js.map +1 -0
  144. package/dist/src/stc.js +2 -1
  145. package/dist/src/stc.js.map +1 -0
  146. package/dist/src/sti.js +2 -1
  147. package/dist/src/sti.js.map +1 -0
  148. package/dist/src/symbols/basic-scope.d.ts +14 -0
  149. package/dist/src/symbols/basic-scope.d.ts.map +1 -0
  150. package/dist/src/symbols/basic-scope.js +21 -0
  151. package/dist/src/symbols/basic-scope.js.map +1 -0
  152. package/dist/src/symbols/basic-symbol.d.ts +19 -0
  153. package/dist/src/symbols/basic-symbol.d.ts.map +1 -0
  154. package/dist/src/symbols/basic-symbol.js +29 -0
  155. package/dist/src/symbols/basic-symbol.js.map +1 -0
  156. package/dist/src/symbols/index.d.ts +3 -1
  157. package/dist/src/symbols/index.d.ts.map +1 -1
  158. package/dist/src/symbols/index.js +5 -2
  159. package/dist/src/symbols/index.js.map +1 -0
  160. package/dist/src/symbols/output-scope.d.ts +70 -41
  161. package/dist/src/symbols/output-scope.d.ts.map +1 -1
  162. package/dist/src/symbols/output-scope.js +100 -131
  163. package/dist/src/symbols/output-scope.js.map +1 -0
  164. package/dist/src/symbols/output-space.d.ts +25 -0
  165. package/dist/src/symbols/output-space.d.ts.map +1 -0
  166. package/dist/src/symbols/output-space.js +36 -0
  167. package/dist/src/symbols/output-space.js.map +1 -0
  168. package/dist/src/symbols/output-symbol.d.ts +213 -37
  169. package/dist/src/symbols/output-symbol.d.ts.map +1 -1
  170. package/dist/src/symbols/output-symbol.js +325 -204
  171. package/dist/src/symbols/output-symbol.js.map +1 -0
  172. package/dist/src/symbols/symbol-flow.d.ts +1 -1
  173. package/dist/src/symbols/symbol-flow.d.ts.map +1 -1
  174. package/dist/src/symbols/symbol-flow.js +24 -8
  175. package/dist/src/symbols/symbol-flow.js.map +1 -0
  176. package/dist/src/symbols/symbol-slot.d.ts +27 -9
  177. package/dist/src/symbols/symbol-slot.d.ts.map +1 -1
  178. package/dist/src/symbols/symbol-slot.js +22 -5
  179. package/dist/src/symbols/symbol-slot.js.map +1 -0
  180. package/dist/src/symbols/symbol-table.d.ts +19 -8
  181. package/dist/src/symbols/symbol-table.d.ts.map +1 -1
  182. package/dist/src/symbols/symbol-table.js +67 -17
  183. package/dist/src/symbols/symbol-table.js.map +1 -0
  184. package/dist/src/tap.js +2 -1
  185. package/dist/src/tap.js.map +1 -0
  186. package/dist/src/tracer.d.ts +15 -3
  187. package/dist/src/tracer.d.ts.map +1 -1
  188. package/dist/src/tracer.js +41 -64
  189. package/dist/src/tracer.js.map +1 -0
  190. package/dist/src/utils.js +2 -1
  191. package/dist/src/utils.js.map +1 -0
  192. package/dist/src/write-output.js +2 -1
  193. package/dist/src/write-output.js.map +1 -0
  194. package/dist/test/browser-build.test.js +2 -1
  195. package/dist/test/browser-build.test.js.map +1 -0
  196. package/dist/test/children.test.js +2 -1
  197. package/dist/test/children.test.js.map +1 -0
  198. package/dist/test/components/append-file.test.js +2 -1
  199. package/dist/test/components/append-file.test.js.map +1 -0
  200. package/dist/test/components/block.test.js +2 -1
  201. package/dist/test/components/block.test.js.map +1 -0
  202. package/dist/test/components/copy-file.test.js +2 -1
  203. package/dist/test/components/copy-file.test.js.map +1 -0
  204. package/dist/test/components/declaration.test.js +11 -15
  205. package/dist/test/components/declaration.test.js.map +1 -0
  206. package/dist/test/components/list.test.js +2 -1
  207. package/dist/test/components/list.test.js.map +1 -0
  208. package/dist/test/components/prose.test.js +2 -1
  209. package/dist/test/components/prose.test.js.map +1 -0
  210. package/dist/test/components/reference-or-content.test.js +4 -3
  211. package/dist/test/components/reference-or-content.test.js.map +1 -0
  212. package/dist/test/components/source-file.test.js +2 -1
  213. package/dist/test/components/source-file.test.js.map +1 -0
  214. package/dist/test/components/template-file.test.js +2 -1
  215. package/dist/test/components/template-file.test.js.map +1 -0
  216. package/dist/test/components/update-file.test.js +2 -1
  217. package/dist/test/components/update-file.test.js.map +1 -0
  218. package/dist/test/components/wrap.test.js +2 -1
  219. package/dist/test/components/wrap.test.js.map +1 -0
  220. package/dist/test/control-flow/for.test.js +2 -1
  221. package/dist/test/control-flow/for.test.js.map +1 -0
  222. package/dist/test/control-flow/match.test.js +2 -1
  223. package/dist/test/control-flow/match.test.js.map +1 -0
  224. package/dist/test/control-flow/show.test.js +2 -1
  225. package/dist/test/control-flow/show.test.js.map +1 -0
  226. package/dist/test/name-policy.test.js +2 -1
  227. package/dist/test/name-policy.test.js.map +1 -0
  228. package/dist/test/props-with-defaults.test.js +2 -1
  229. package/dist/test/props-with-defaults.test.js.map +1 -0
  230. package/dist/test/reactive-union-set.test.js +2 -1
  231. package/dist/test/reactive-union-set.test.js.map +1 -0
  232. package/dist/test/reactivity/circular-reactives.test.js +2 -1
  233. package/dist/test/reactivity/circular-reactives.test.js.map +1 -0
  234. package/dist/test/reactivity/cleanup.test.js +2 -1
  235. package/dist/test/reactivity/cleanup.test.js.map +1 -0
  236. package/dist/test/reactivity/memo.test.js +2 -1
  237. package/dist/test/reactivity/memo.test.js.map +1 -0
  238. package/dist/test/reactivity/ref-rendering.test.js +2 -1
  239. package/dist/test/reactivity/ref-rendering.test.js.map +1 -0
  240. package/dist/test/reactivity/test.test.js +2 -1
  241. package/dist/test/reactivity/test.test.js.map +1 -0
  242. package/dist/test/reactivity/untrack.test.js +2 -1
  243. package/dist/test/reactivity/untrack.test.js.map +1 -0
  244. package/dist/test/refkey.test.js +2 -1
  245. package/dist/test/refkey.test.js.map +1 -0
  246. package/dist/test/rendering/basic.test.js +2 -1
  247. package/dist/test/rendering/basic.test.js.map +1 -0
  248. package/dist/test/rendering/code.test.js +2 -1
  249. package/dist/test/rendering/code.test.js.map +1 -0
  250. package/dist/test/rendering/formatting.test.js +2 -1
  251. package/dist/test/rendering/formatting.test.js.map +1 -0
  252. package/dist/test/rendering/indent.test.js +2 -1
  253. package/dist/test/rendering/indent.test.js.map +1 -0
  254. package/dist/test/rendering/memoization.test.js +2 -1
  255. package/dist/test/rendering/memoization.test.js.map +1 -0
  256. package/dist/test/rendering/refkeys.test.js +2 -1
  257. package/dist/test/rendering/refkeys.test.js.map +1 -0
  258. package/dist/test/split-props.test.js +2 -1
  259. package/dist/test/split-props.test.js.map +1 -0
  260. package/dist/test/stc.test.js +2 -1
  261. package/dist/test/stc.test.js.map +1 -0
  262. package/dist/test/symbols/output-scope.test.js +34 -198
  263. package/dist/test/symbols/output-scope.test.js.map +1 -0
  264. package/dist/test/symbols/output-symbol.test.js +141 -386
  265. package/dist/test/symbols/output-symbol.test.js.map +1 -0
  266. package/dist/test/symbols/resolution.test.js +433 -115
  267. package/dist/test/symbols/resolution.test.js.map +1 -0
  268. package/dist/test/symbols/symbol-table.test.d.ts +2 -0
  269. package/dist/test/symbols/symbol-table.test.d.ts.map +1 -0
  270. package/dist/test/symbols/symbol-table.test.js +15 -0
  271. package/dist/test/symbols/symbol-table.test.js.map +1 -0
  272. package/dist/test/symbols/utils.d.ts +10 -24
  273. package/dist/test/symbols/utils.d.ts.map +1 -1
  274. package/dist/test/symbols/utils.js +25 -46
  275. package/dist/test/symbols/utils.js.map +1 -0
  276. package/dist/test/utils.test.js +2 -1
  277. package/dist/test/utils.test.js.map +1 -0
  278. package/dist/testing/extend-expect.js +2 -1
  279. package/dist/testing/extend-expect.js.map +1 -0
  280. package/dist/testing/extend-expect.test.js +2 -1
  281. package/dist/testing/extend-expect.test.js.map +1 -0
  282. package/dist/testing/index.js +2 -1
  283. package/dist/testing/index.js.map +1 -0
  284. package/dist/testing/render.js +2 -1
  285. package/dist/testing/render.js.map +1 -0
  286. package/dist/testing/vitest.d.js +2 -1
  287. package/dist/testing/vitest.d.js.map +1 -0
  288. package/dist/tsconfig.tsbuildinfo +1 -1
  289. package/package.json +5 -3
  290. package/src/binder.ts +368 -273
  291. package/src/components/Declaration.tsx +13 -3
  292. package/src/components/MemberDeclaration.tsx +15 -8
  293. package/src/components/MemberScope.tsx +61 -20
  294. package/src/components/Output.tsx +0 -4
  295. package/src/components/Scope.tsx +16 -9
  296. package/src/context/member-scope.ts +10 -10
  297. package/src/context/name-policy.ts +3 -0
  298. package/src/context/scope.ts +9 -0
  299. package/src/inspect.browser.ts +6 -0
  300. package/src/inspect.ts +1 -0
  301. package/src/name-policy.ts +14 -0
  302. package/src/reactive-union-set.ts +14 -8
  303. package/src/refkey.ts +106 -14
  304. package/src/symbols/basic-scope.ts +23 -0
  305. package/src/symbols/basic-symbol.ts +32 -0
  306. package/src/symbols/index.ts +3 -1
  307. package/src/symbols/output-scope.ts +131 -170
  308. package/src/symbols/output-space.ts +49 -0
  309. package/src/symbols/output-symbol.ts +434 -258
  310. package/src/symbols/symbol-flow.ts +38 -9
  311. package/src/symbols/symbol-slot.tsx +46 -8
  312. package/src/symbols/symbol-table.ts +95 -21
  313. package/src/tracer.ts +53 -83
  314. package/temp/api.json +7009 -4461
  315. package/test/components/declaration.test.tsx +6 -19
  316. package/test/components/reference-or-content.test.tsx +2 -2
  317. package/test/symbols/output-scope.test.ts +33 -125
  318. package/test/symbols/output-symbol.test.ts +128 -348
  319. package/test/symbols/resolution.test.ts +530 -117
  320. package/test/symbols/symbol-table.test.ts +15 -0
  321. package/test/symbols/utils.ts +38 -74
  322. package/tsdoc.json +4 -0
  323. package/dist/src/slot.d.ts +0 -15
  324. package/dist/src/slot.d.ts.map +0 -1
  325. package/dist/src/slot.js +0 -50
  326. package/dist/src/symbols/flags.d.ts +0 -70
  327. package/dist/src/symbols/flags.d.ts.map +0 -1
  328. package/dist/src/symbols/flags.js +0 -72
  329. package/dist/test/components/slot.test.d.ts +0 -2
  330. package/dist/test/components/slot.test.d.ts.map +0 -1
  331. package/dist/test/components/slot.test.js +0 -134
  332. package/src/slot.ts +0 -89
  333. package/src/symbols/flags.ts +0 -82
  334. package/test/components/slot.test.tsx +0 -174
@@ -1,9 +1,9 @@
1
- import { reactive, ReactiveFlags, shallowReactive, track, TrackOpTypes, trigger, TriggerOpTypes, watch } from "@vue/reactivity";
1
+ import { effect, reactive, ReactiveFlags, shallowReactive, track, TrackOpTypes, trigger, TriggerOpTypes } from "@vue/reactivity";
2
2
  import { useBinder } from "../context/binder.js";
3
- import { useScope } from "../context/scope.js";
4
- import { formatScope, formatScopeName, trace, traceEffect, TracePhase } from "../tracer.js";
5
- import { OutputScopeFlags } from "./flags.js";
6
- import { SymbolTable } from "./symbol-table.js";
3
+ import { inspect } from "../inspect.js";
4
+ import { untrack } from "../reactivity.js";
5
+ import { formatScope, trace, traceEffect, TracePhase } from "../tracer.js";
6
+ import { OutputDeclarationSpace } from "./output-space.js";
7
7
  let scopeCount = 0;
8
8
  /**
9
9
  * A container of symbols accessible within some scope in your output code.
@@ -24,10 +24,12 @@ let scopeCount = 0;
24
24
  * within a reactive context.
25
25
  */
26
26
  export class OutputScope {
27
- // my kingdom for decorators
27
+ static declarationSpaces = [];
28
28
  #name;
29
29
  /**
30
30
  * The name of the scope.
31
+ *
32
+ * @reactive
31
33
  */
32
34
  get name() {
33
35
  track(this, TrackOpTypes.GET, "name");
@@ -41,77 +43,59 @@ export class OutputScope {
41
43
  #id;
42
44
  /**
43
45
  * The unique id of this scope.
46
+ *
47
+ * @readonly
44
48
  */
45
49
  get id() {
46
50
  return this.#id;
47
51
  }
48
- #kind;
49
-
50
- /**
51
- * The kind of scope. Subtypes will likely provide a set of known scope kinds.
52
- * The kind is not used by the binder itself.
53
- */
54
- get kind() {
55
- return this.#kind;
56
- }
57
- #flags;
58
- /**
59
- * The flags that describe this scope.
60
- */
61
- get flags() {
62
- track(this, TrackOpTypes.GET, "flags");
63
- return this.#flags;
64
- }
65
- set flags(flags) {
66
- const old = this.#flags;
67
- this.#flags = flags;
68
- trigger(this, TriggerOpTypes.SET, "flags", flags, old);
69
- }
70
52
 
71
53
  // read only
72
54
  #metadata;
55
+ /**
56
+ * Arbitrary metadata associated with this scope. This property is not
57
+ * reactive but the metadata object is a reactive object.
58
+ *
59
+ * @readonly
60
+ */
73
61
  get metadata() {
74
62
  return this.#metadata;
75
63
  }
76
64
  #parent;
65
+
77
66
  /**
78
- * The container of this scope. This is only defined for scopes which don't
79
- * have the {@link OutputScopeFlags.StaticMemberScope} or
80
- * {@link OutputScopeFlags.InstanceMemberScope} flag.
67
+ * The parent scope of this scope. Undefined if this is a root scope.
68
+ *
69
+ * @reactive
81
70
  */
82
71
  get parent() {
72
+ track(this, TrackOpTypes.GET, "parent");
83
73
  return this.#parent;
84
74
  }
85
- #owner;
86
- /**
87
- * The symbol that owns this scope. This is only defined for scopes that have
88
- * the {@link OutputScopeFlags.StaticMemberScope} or
89
- * {@link OutputScopeFlags.InstanceMemberScope} flag.
90
- */
91
- get owner() {
92
- return this.#owner;
93
- }
94
- #symbols;
95
- /**
96
- * The symbols defined within this scope.
97
- */
98
- get symbols() {
99
- return this.#symbols;
75
+ set parent(scope) {
76
+ const old = this.#parent;
77
+ if (old) {
78
+ old.children.delete(this);
79
+ }
80
+ if (scope) {
81
+ scope.children.add(this);
82
+ }
83
+ trigger(this, TriggerOpTypes.SET, "parent", scope, old);
84
+ this.#parent = scope;
100
85
  }
101
- #symbolsByRefkey;
86
+ #spaces;
87
+
102
88
  /**
103
- * The symbols defined within this scope, indexed by refkey.
89
+ * Get the declaration space for the given key.
104
90
  */
105
- get symbolsByRefkey() {
106
- return this.#symbolsByRefkey;
107
- }
108
- #symbolNames;
109
- get symbolNames() {
110
- return this.#symbolNames;
91
+ spaceFor(key) {
92
+ return this.#spaces[key];
111
93
  }
112
94
  #children;
113
95
  /**
114
96
  * The scopes nested within this scope.
97
+ *
98
+ * @readonly
115
99
  */
116
100
  get children() {
117
101
  return this.#children;
@@ -119,104 +103,89 @@ export class OutputScope {
119
103
  #binder;
120
104
  /**
121
105
  * The binder that created this scope.
106
+ *
107
+ * @readonly
122
108
  */
123
109
  get binder() {
124
110
  return this.#binder;
125
111
  }
126
112
  [ReactiveFlags.SKIP] = this;
127
- constructor(name, options = {}) {
113
+ constructor(name, parentScope, options = {}) {
128
114
  this.#name = name;
129
115
  this.#id = scopeCount++;
130
- this.#flags = options.flags ?? OutputScopeFlags.None;
131
- this.#kind = options.kind ?? "scope";
132
116
  this.#metadata = reactive(options.metadata ?? {});
133
117
  this.#binder = options.binder ?? useBinder();
134
- this.#owner = options.owner;
135
118
  this.#children = shallowReactive(new Set());
136
- if (this.#flags & OutputScopeFlags.MemberScope) {
137
- if (!this.#owner) {
138
- throw new Error("Member scopes must have an owner");
139
- }
140
- } else {
141
- if (!this.#parent) {
142
- this.#parent = options.parent ?? useScope() ?? this.#binder?.globalScope;
143
- }
144
- if (this.#parent) {
145
- // not global scope
146
- this.#parent.children.add(this);
147
- }
148
- }
149
- this.#symbols = new SymbolTable(this, {
150
- nameConflictResolver: this.#binder?.nameConflictResolver
151
- });
152
- this.#symbolsByRefkey = this.#symbols.createIndex(s => s.refkeys);
153
- this.#symbolNames = this.#symbols.createDerivedSet(s => {
154
- return s.name;
119
+ this.#parent = parentScope;
120
+ effect(() => {
121
+ this.#setOwnerSymbol(options.ownerSymbol?.movedTo ?? options.ownerSymbol);
155
122
  });
156
123
  if (this.#parent) {
157
124
  this.#parent.children.add(this);
158
125
  }
126
+ const constructor = this.constructor;
127
+ this.#spaces = Object.fromEntries(constructor.declarationSpaces.map(spaceKey => [spaceKey, new OutputDeclarationSpace(this, spaceKey, this.#binder)]));
159
128
  this.#binder?.notifyScopeCreated(this);
160
129
  trace(TracePhase.scope.create, () => `${formatScope(this)}`);
161
130
  traceEffect(TracePhase.scope.update, () => {
162
131
  return `${formatScope(this)}`;
163
132
  });
164
133
  }
165
- moveSymbolsFrom(source, options) {
166
- trace(TracePhase.scope.copySymbols, () => `Moving symbols from ${formatScopeName(source)} to ${formatScopeName(this)}`);
167
- this.#symbols.addSubset(source.#symbols, {
168
- onAdd: symbol => {
169
- if (options?.onAdd) {
170
- return options.onAdd(symbol);
171
- }
172
- symbol.scope = this;
173
- return symbol;
174
- },
175
- onDelete: symbol => {
176
- if (options?.onDelete) {
177
- options.onDelete(symbol);
178
- }
179
- }
180
- });
134
+
135
+ /**
136
+ * Get all the declaration spaces in this scope.
137
+ *
138
+ * @readonly
139
+ */
140
+ get spaces() {
141
+ return Object.values(this.#spaces);
181
142
  }
182
- copySymbolsFrom(source, options) {
183
- trace(TracePhase.scope.copySymbols, () => `Copying symbols from ${formatScopeName(source)} to ${formatScopeName(this)}`);
184
- this.#symbols.addSubset(source.#symbols, {
185
- onAdd: symbol => {
186
- if (options?.onAdd) {
187
- return options.onAdd(symbol);
188
- }
189
- return symbol.copyToScope(this);
190
- },
191
- onDelete: symbol => {
192
- if (options?.onDelete) {
193
- options.onDelete(symbol);
194
- }
195
- }
196
- });
143
+ #ownerSymbol;
144
+ /**
145
+ * The symbol whose members are in scope. When an owner symbol is present,
146
+ * this scope is considered a member scope, and does not provide its own
147
+ * declaration spaces.
148
+ *
149
+ * @readonly
150
+ * @reactive
151
+ */
152
+ get ownerSymbol() {
153
+ track(this, TrackOpTypes.GET, "ownerSymbol");
154
+ return this.#ownerSymbol;
197
155
  }
198
- clone(options = {}) {
199
- if (this.#flags & OutputScopeFlags.MemberScope && !options.owner) {
200
- throw new Error("Member scope clones must specify an owner symbol");
201
- } else if (this.#flags & ~OutputScopeFlags.MemberScope && !options.parent) {
202
- throw new Error("Non-member scope clones must specify a parent scope");
203
- }
204
- const clone = new OutputScope(this.#name, {
205
- binder: this.#binder,
206
- flags: this.#flags,
207
- kind: this.#kind,
208
- metadata: this.#metadata,
209
- parent: options.parent,
210
- owner: options.owner
211
- });
212
- watch(() => this.name, newName => clone.name = newName);
213
- watch(() => this.flags, newFlags => clone.flags = newFlags);
214
- // todo: this should be reactive, but cloning non-member scopes
215
- // seems like a very rare thing.
216
- for (const child of this.#children) {
217
- clone.children.add(child.clone());
156
+ #setOwnerSymbol(value) {
157
+ const old = this.#ownerSymbol;
158
+ this.#ownerSymbol = value;
159
+ trigger(this, TriggerOpTypes.SET, "ownerSymbol", value, old);
160
+ }
161
+
162
+ /**
163
+ * Whether this scope is a transient scope. Transient scopes are used for
164
+ * temporary values that are to be combined with other non-transient symbols.
165
+ * Scopes are transient when their owner symbol is transient.
166
+ *
167
+ * @readonly
168
+ */
169
+ get isTransient() {
170
+ if (!this.ownerSymbol) {
171
+ return false;
218
172
  }
219
- clone.copySymbolsFrom(this);
220
- return clone;
173
+ return this.ownerSymbol.isTransient;
174
+ }
175
+ /**
176
+ * Check if this is scope is a member scope. Member scopes have no member
177
+ * spaces of their own, but instead put members of their owner symbol in
178
+ * scope.
179
+ *
180
+ * @readonly
181
+ * @reactive
182
+ */
183
+ get isMemberScope() {
184
+ return !!this.ownerSymbol;
185
+ }
186
+ [inspect.custom]() {
187
+ const ownerSymbol = this.ownerSymbol ? ` for ${inspect(this.ownerSymbol)}` : "";
188
+ return untrack(() => `${this.constructor.name} ${this.name}[${this.id}]${ownerSymbol}`);
221
189
  }
222
- }
190
+ }
191
+ //# sourceMappingURL=output-scope.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["effect","reactive","ReactiveFlags","shallowReactive","track","TrackOpTypes","trigger","TriggerOpTypes","useBinder","inspect","untrack","formatScope","trace","traceEffect","TracePhase","OutputDeclarationSpace","scopeCount","OutputScope","declarationSpaces","name","GET","old","SET","id","metadata","parent","scope","children","delete","add","spaces","spaceFor","key","binder","SKIP","constructor","parentScope","options","Set","setOwnerSymbol","ownerSymbol","movedTo","Object","fromEntries","map","spaceKey","notifyScopeCreated","create","update","values","#setOwnerSymbol","value","isTransient","isMemberScope","custom"],"sources":["../../../src/symbols/output-scope.ts"],"sourcesContent":[null],"mappings":"AAAA,SACEA,MAAM,EACNC,QAAQ,EACRC,aAAa,EACbC,eAAe,EACfC,KAAK,EACLC,YAAY,EACZC,OAAO,EACPC,cAAc,QACT,iBAAiB;AAExB,SAASC,SAAS,QAAQ,sBAAsB;AAChD,SAASC,OAAO,QAAQ,eAAe;AACvC,SAASC,OAAO,QAAQ,kBAAkB;AAC1C,SAASC,WAAW,EAAEC,KAAK,EAAEC,WAAW,EAAEC,UAAU,QAAQ,cAAc;AAC1E,SAASC,sBAAsB,QAAqB,mBAAmB;AAGvE,IAAIC,UAAU,GAAG,CAAC;AAsBlB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAeC,WAAW,CAAC;EAChC,OAAgBC,iBAAiB,GAAuB,EAAE;EAE1D,CAACC,IAAI;EACL;AACF;AACA;AACA;AACA;EACE,IAAIA,IAAIA,CAAA,EAAG;IACTf,KAAK,CAAC,IAAI,EAAEC,YAAY,CAACe,GAAG,EAAE,MAAM,CAAC;IACrC,OAAO,IAAI,CAAC,CAACD,IAAI;EACnB;EAEA,IAAIA,IAAIA,CAACA,IAAY,EAAE;IACrB,MAAME,GAAG,GAAG,IAAI,CAAC,CAACF,IAAI;IACtB,IAAI,CAAC,CAACA,IAAI,GAAGA,IAAI;IACjBb,OAAO,CAAC,IAAI,EAAEC,cAAc,CAACe,GAAG,EAAE,MAAM,EAAEH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,GAAG,IAAI,CAACyB,WAAW,CAAChB,IAAI,IAAI,IAAI,CAACA,IAAI,IAAI,IAAI,CAACI,EAAE,IAAIiB,WAAW,EACvE,CAAC;EACH;AACF","ignoreList":[]}
@@ -0,0 +1,25 @@
1
+ import { Binder } from "../binder.js";
2
+ import { inspect } from "../inspect.js";
3
+ import { OutputScope } from "./output-scope.js";
4
+ import { OutputSymbol } from "./output-symbol.js";
5
+ import { SymbolTable } from "./symbol-table.js";
6
+ export type OutputSpace = OutputDeclarationSpace | OutputMemberSpace;
7
+ export declare class OutputDeclarationSpace extends SymbolTable {
8
+ #private;
9
+ constructor(scope: OutputScope, key: string, binder?: Binder);
10
+ /**
11
+ * The scope this declaration space belongs to.
12
+ */
13
+ get scope(): OutputScope;
14
+ [inspect.custom](): string;
15
+ }
16
+ export declare class OutputMemberSpace extends SymbolTable {
17
+ #private;
18
+ constructor(symbol: OutputSymbol, key: string, binder?: Binder);
19
+ /**
20
+ * The symbol this member space belongs to.
21
+ */
22
+ get symbol(): OutputSymbol;
23
+ [inspect.custom](): string;
24
+ }
25
+ //# sourceMappingURL=output-space.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"output-space.d.ts","sourceRoot":"","sources":["../../../src/symbols/output-space.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAExC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,MAAM,MAAM,WAAW,GAAG,sBAAsB,GAAG,iBAAiB,CAAC;AACrE,qBAAa,sBAAuB,SAAQ,WAAW;;gBACzC,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM;IAM5D;;OAEG;IACH,IAAI,KAAK,gBAER;IAED,CAAC,OAAO,CAAC,MAAM,CAAC;CAKjB;AAED,qBAAa,iBAAkB,SAAQ,WAAW;;gBACpC,MAAM,EAAE,YAAY,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM;IAM9D;;OAEG;IACH,IAAI,MAAM,iBAET;IAED,CAAC,OAAO,CAAC,MAAM,CAAC;CAKjB"}
@@ -0,0 +1,36 @@
1
+ import { inspect } from "../inspect.js";
2
+ import { untrack } from "../reactivity.js";
3
+ import { SymbolTable } from "./symbol-table.js";
4
+ export class OutputDeclarationSpace extends SymbolTable {
5
+ constructor(scope, key, binder) {
6
+ super(key, binder);
7
+ this.#scope = scope;
8
+ }
9
+ #scope;
10
+ /**
11
+ * The scope this declaration space belongs to.
12
+ */
13
+ get scope() {
14
+ return this.#scope;
15
+ }
16
+ [inspect.custom]() {
17
+ return untrack(() => `OutputDeclarationSpace for scope ${inspect(this.#scope)}`);
18
+ }
19
+ }
20
+ export class OutputMemberSpace extends SymbolTable {
21
+ constructor(symbol, key, binder) {
22
+ super(key, binder);
23
+ this.#symbol = symbol;
24
+ }
25
+ #symbol;
26
+ /**
27
+ * The symbol this member space belongs to.
28
+ */
29
+ get symbol() {
30
+ return this.#symbol;
31
+ }
32
+ [inspect.custom]() {
33
+ return untrack(() => `OutputMemberSpace for symbol ${inspect(this.#symbol)}`);
34
+ }
35
+ }
36
+ //# sourceMappingURL=output-space.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["inspect","untrack","SymbolTable","OutputDeclarationSpace","constructor","scope","key","binder","custom","OutputMemberSpace","symbol"],"sources":["../../../src/symbols/output-space.ts"],"sourcesContent":[null],"mappings":"AACA,SAASA,OAAO,QAAQ,eAAe;AACvC,SAASC,OAAO,QAAQ,kBAAkB;AAG1C,SAASC,WAAW,QAAQ,mBAAmB;AAG/C,OAAO,MAAMC,sBAAsB,SAASD,WAAW,CAAC;EACtDE,WAAWA,CAACC,KAAkB,EAAEC,GAAW,EAAEC,MAAe,EAAE;IAC5D,KAAK,CAACD,GAAG,EAAEC,MAAM,CAAC;IAClB,IAAI,CAAC,CAACF,KAAK,GAAGA,KAAK;EACrB;EAEA,CAACA,KAAK;EACN;AACF;AACA;EACE,IAAIA,KAAKA,CAAA,EAAG;IACV,OAAO,IAAI,CAAC,CAACA,KAAK;EACpB;EAEA,CAACL,OAAO,CAACQ,MAAM,IAAI;IACjB,OAAOP,OAAO,CACZ,MAAM,oCAAoCD,OAAO,CAAC,IAAI,CAAC,CAACK,KAAK,CAAC,EAChE,CAAC;EACH;AACF;AAEA,OAAO,MAAMI,iBAAiB,SAASP,WAAW,CAAC;EACjDE,WAAWA,CAACM,MAAoB,EAAEJ,GAAW,EAAEC,MAAe,EAAE;IAC9D,KAAK,CAACD,GAAG,EAAEC,MAAM,CAAC;IAClB,IAAI,CAAC,CAACG,MAAM,GAAGA,MAAM;EACvB;EAEA,CAACA,MAAM;EACP;AACF;AACA;EACE,IAAIA,MAAMA,CAAA,EAAG;IACX,OAAO,IAAI,CAAC,CAACA,MAAM;EACrB;EAEA,CAACV,OAAO,CAACQ,MAAM,IAAI;IACjB,OAAOP,OAAO,CACZ,MAAM,gCAAgCD,OAAO,CAAC,IAAI,CAAC,CAACU,MAAM,CAAC,EAC7D,CAAC;EACH;AACF","ignoreList":[]}