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

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 (129) hide show
  1. package/dist/src/binder.d.ts +62 -38
  2. package/dist/src/binder.d.ts.map +1 -1
  3. package/dist/src/binder.js +214 -173
  4. package/dist/src/components/Declaration.d.ts +2 -2
  5. package/dist/src/components/Declaration.d.ts.map +1 -1
  6. package/dist/src/components/Declaration.js +8 -2
  7. package/dist/src/components/MemberDeclaration.d.ts +2 -2
  8. package/dist/src/components/MemberDeclaration.d.ts.map +1 -1
  9. package/dist/src/components/MemberDeclaration.js +9 -5
  10. package/dist/src/components/MemberScope.d.ts +30 -13
  11. package/dist/src/components/MemberScope.d.ts.map +1 -1
  12. package/dist/src/components/MemberScope.js +37 -15
  13. package/dist/src/components/Output.d.ts.map +1 -1
  14. package/dist/src/components/Output.js +2 -5
  15. package/dist/src/components/ReferenceOrContent.d.ts +1 -1
  16. package/dist/src/components/ReferenceOrContent.d.ts.map +1 -1
  17. package/dist/src/components/Scope.d.ts +5 -5
  18. package/dist/src/components/Scope.d.ts.map +1 -1
  19. package/dist/src/components/Scope.js +9 -5
  20. package/dist/src/context/member-scope.d.ts +7 -8
  21. package/dist/src/context/member-scope.d.ts.map +1 -1
  22. package/dist/src/context/member-scope.js +5 -5
  23. package/dist/src/context/name-policy.d.ts.map +1 -1
  24. package/dist/src/context/name-policy.js +3 -0
  25. package/dist/src/context/scope.d.ts +1 -0
  26. package/dist/src/context/scope.d.ts.map +1 -1
  27. package/dist/src/context/scope.js +7 -0
  28. package/dist/src/inspect.browser.d.ts +5 -0
  29. package/dist/src/inspect.browser.d.ts.map +1 -0
  30. package/dist/src/inspect.browser.js +5 -0
  31. package/dist/src/inspect.d.ts +2 -0
  32. package/dist/src/inspect.d.ts.map +1 -0
  33. package/dist/src/inspect.js +1 -0
  34. package/dist/src/name-policy.d.ts +11 -0
  35. package/dist/src/name-policy.d.ts.map +1 -1
  36. package/dist/src/name-policy.js +3 -0
  37. package/dist/src/reactive-union-set.d.ts.map +1 -1
  38. package/dist/src/reactive-union-set.js +12 -8
  39. package/dist/src/refkey.d.ts +39 -3
  40. package/dist/src/refkey.d.ts.map +1 -1
  41. package/dist/src/refkey.js +52 -8
  42. package/dist/src/symbols/basic-scope.d.ts +14 -0
  43. package/dist/src/symbols/basic-scope.d.ts.map +1 -0
  44. package/dist/src/symbols/basic-scope.js +20 -0
  45. package/dist/src/symbols/basic-symbol.d.ts +19 -0
  46. package/dist/src/symbols/basic-symbol.d.ts.map +1 -0
  47. package/dist/src/symbols/basic-symbol.js +28 -0
  48. package/dist/src/symbols/index.d.ts +3 -1
  49. package/dist/src/symbols/index.d.ts.map +1 -1
  50. package/dist/src/symbols/index.js +3 -1
  51. package/dist/src/symbols/output-scope.d.ts +70 -41
  52. package/dist/src/symbols/output-scope.d.ts.map +1 -1
  53. package/dist/src/symbols/output-scope.js +98 -130
  54. package/dist/src/symbols/output-space.d.ts +25 -0
  55. package/dist/src/symbols/output-space.d.ts.map +1 -0
  56. package/dist/src/symbols/output-space.js +35 -0
  57. package/dist/src/symbols/output-symbol.d.ts +213 -37
  58. package/dist/src/symbols/output-symbol.d.ts.map +1 -1
  59. package/dist/src/symbols/output-symbol.js +323 -203
  60. package/dist/src/symbols/symbol-flow.d.ts +1 -1
  61. package/dist/src/symbols/symbol-flow.d.ts.map +1 -1
  62. package/dist/src/symbols/symbol-flow.js +22 -7
  63. package/dist/src/symbols/symbol-slot.d.ts +27 -9
  64. package/dist/src/symbols/symbol-slot.d.ts.map +1 -1
  65. package/dist/src/symbols/symbol-slot.js +20 -4
  66. package/dist/src/symbols/symbol-table.d.ts +19 -8
  67. package/dist/src/symbols/symbol-table.d.ts.map +1 -1
  68. package/dist/src/symbols/symbol-table.js +65 -16
  69. package/dist/src/tracer.d.ts +15 -3
  70. package/dist/src/tracer.d.ts.map +1 -1
  71. package/dist/src/tracer.js +39 -63
  72. package/dist/test/components/declaration.test.js +9 -14
  73. package/dist/test/components/reference-or-content.test.js +2 -2
  74. package/dist/test/symbols/output-scope.test.js +33 -198
  75. package/dist/test/symbols/output-symbol.test.js +139 -385
  76. package/dist/test/symbols/resolution.test.js +431 -114
  77. package/dist/test/symbols/symbol-table.test.d.ts +2 -0
  78. package/dist/test/symbols/symbol-table.test.d.ts.map +1 -0
  79. package/dist/test/symbols/symbol-table.test.js +14 -0
  80. package/dist/test/symbols/utils.d.ts +10 -24
  81. package/dist/test/symbols/utils.d.ts.map +1 -1
  82. package/dist/test/symbols/utils.js +23 -45
  83. package/dist/tsconfig.tsbuildinfo +1 -1
  84. package/package.json +4 -2
  85. package/src/binder.ts +348 -273
  86. package/src/components/Declaration.tsx +13 -3
  87. package/src/components/MemberDeclaration.tsx +15 -8
  88. package/src/components/MemberScope.tsx +61 -20
  89. package/src/components/Output.tsx +0 -4
  90. package/src/components/Scope.tsx +16 -9
  91. package/src/context/member-scope.ts +10 -10
  92. package/src/context/name-policy.ts +3 -0
  93. package/src/context/scope.ts +9 -0
  94. package/src/inspect.browser.ts +6 -0
  95. package/src/inspect.ts +1 -0
  96. package/src/name-policy.ts +14 -0
  97. package/src/reactive-union-set.ts +14 -8
  98. package/src/refkey.ts +88 -14
  99. package/src/symbols/basic-scope.ts +23 -0
  100. package/src/symbols/basic-symbol.ts +32 -0
  101. package/src/symbols/index.ts +3 -1
  102. package/src/symbols/output-scope.ts +131 -170
  103. package/src/symbols/output-space.ts +49 -0
  104. package/src/symbols/output-symbol.ts +434 -258
  105. package/src/symbols/symbol-flow.ts +38 -9
  106. package/src/symbols/symbol-slot.tsx +46 -8
  107. package/src/symbols/symbol-table.ts +95 -21
  108. package/src/tracer.ts +53 -83
  109. package/temp/api.json +5559 -3079
  110. package/test/components/declaration.test.tsx +6 -19
  111. package/test/components/reference-or-content.test.tsx +2 -2
  112. package/test/symbols/output-scope.test.ts +33 -125
  113. package/test/symbols/output-symbol.test.ts +128 -348
  114. package/test/symbols/resolution.test.ts +530 -117
  115. package/test/symbols/symbol-table.test.ts +15 -0
  116. package/test/symbols/utils.ts +38 -74
  117. package/tsdoc.json +4 -0
  118. package/dist/src/slot.d.ts +0 -15
  119. package/dist/src/slot.d.ts.map +0 -1
  120. package/dist/src/slot.js +0 -50
  121. package/dist/src/symbols/flags.d.ts +0 -70
  122. package/dist/src/symbols/flags.d.ts.map +0 -1
  123. package/dist/src/symbols/flags.js +0 -72
  124. package/dist/test/components/slot.test.d.ts +0 -2
  125. package/dist/test/components/slot.test.d.ts.map +0 -1
  126. package/dist/test/components/slot.test.js +0 -134
  127. package/src/slot.ts +0 -89
  128. package/src/symbols/flags.ts +0 -82
  129. package/test/components/slot.test.tsx +0 -174
@@ -1,26 +1,15 @@
1
1
  import { expect, it } from "vitest";
2
2
  import { Output } from "../../src/components/Output.jsx";
3
- import {
4
- Declaration,
5
- ref,
6
- renderTree,
7
- Scope,
8
- useBinder,
9
- } from "../../src/index.js";
3
+ import { Declaration, ref, renderTree, Scope } from "../../src/index.js";
10
4
  import { flushJobs } from "../../src/scheduler.js";
11
- import { createTap } from "../../src/tap.js";
5
+ import { BasicScope } from "../../src/symbols/basic-scope.js";
12
6
 
13
7
  it("creates and cleans up a symbol", () => {
14
- const GetBinder = createTap(() => {
15
- return useBinder();
16
- });
17
-
18
- const binderRef = GetBinder.ref;
19
8
  const doDecl = ref(true);
9
+ const scope = new BasicScope("test", undefined);
20
10
  const template = (
21
11
  <Output>
22
- <GetBinder />
23
- <Scope name="foo">
12
+ <Scope value={scope}>
24
13
  {doDecl.value ?
25
14
  <Declaration name="foo"></Declaration>
26
15
  : ""}
@@ -30,10 +19,8 @@ it("creates and cleans up a symbol", () => {
30
19
 
31
20
  renderTree(template);
32
21
 
33
- const binder = binderRef.value!;
34
- const subScope = [...binder.globalScope.children][0];
35
- expect(subScope.symbols.size).toBe(1);
22
+ expect(scope.symbols.size).toBe(1);
36
23
  doDecl.value = false;
37
24
  flushJobs();
38
- expect(subScope.symbols.size).toBe(0);
25
+ expect(scope.symbols.size).toBe(0);
39
26
  });
@@ -20,7 +20,7 @@ function TestWrapper(props: { children: Children }) {
20
20
 
21
21
  function Reference(props: { refkey: Refkey }) {
22
22
  const result = resolve(props.refkey);
23
- return result.value.targetDeclaration.name;
23
+ return result.value.symbol.name;
24
24
  }
25
25
 
26
26
  return (
@@ -111,7 +111,7 @@ it("resolve ref via source file reference", () => {
111
111
 
112
112
  const Reference = vi.fn((props: { refkey: Refkey }) => {
113
113
  const result = resolve(props.refkey);
114
- return `ViaRef.${result.value.targetDeclaration.name}`;
114
+ return `ViaRef.${result.value.symbol.name}`;
115
115
  });
116
116
 
117
117
  const template = (
@@ -1,48 +1,33 @@
1
1
  import { reactive, watch } from "@vue/reactivity";
2
- import { beforeEach, describe, expect, it, vi } from "vitest";
3
- import { Binder, createOutputBinder } from "../../src/binder.js";
2
+ import { describe, expect, it, vi } from "vitest";
4
3
  import { Refkey } from "../../src/refkey.js";
5
4
  import { flushJobs } from "../../src/scheduler.js";
6
- import { OutputScopeFlags } from "../../src/symbols/flags.js";
7
- import { OutputScope } from "../../src/symbols/output-scope.js";
8
- import { OutputSymbol } from "../../src/symbols/output-symbol.js";
5
+ import { BasicScope } from "../../src/symbols/basic-scope.js";
9
6
  import { SymbolTable } from "../../src/symbols/symbol-table.js";
10
-
11
- let binder: Binder;
12
- beforeEach(() => {
13
- binder = createOutputBinder();
14
- });
7
+ import { binder, createScope, createSymbol } from "./utils.js";
15
8
 
16
9
  describe("OutputScope constructor", () => {
17
10
  it("initializes properties correctly with default options", () => {
18
- const scope = new OutputScope("testScope", { binder });
11
+ const scope = createScope("testScope");
19
12
  expect(scope.name).toBe("testScope");
20
13
  expect(scope.binder).toBe(binder);
21
14
  expect(scope.id).toEqual(expect.any(Number));
22
- expect(scope.kind).toBe("scope");
23
- expect(scope.flags).toBe(OutputScopeFlags.None);
24
15
  expect(scope.metadata).toEqual({});
25
- expect(scope.parent).toBe(binder.globalScope);
26
- expect(scope.owner).toBeUndefined();
27
16
  expect(scope.symbols).toBeInstanceOf(SymbolTable);
28
17
  expect(scope.symbolNames.size).toBe(0);
29
18
  expect(scope.children.size).toBe(0);
30
19
  });
31
20
 
32
21
  it("initializes properties correctly with custom options", () => {
33
- const parentScope = new OutputScope("parentScope", { binder });
22
+ const parentScope = createScope("parentScope");
34
23
  const metadata = { foo: "bar" };
35
24
 
36
- const scope = new OutputScope("testScope", {
25
+ const scope = new BasicScope("testScope", parentScope, {
37
26
  binder,
38
- kind: "namespace",
39
27
  metadata,
40
- parent: parentScope,
41
28
  });
42
29
 
43
30
  expect(scope.name).toBe("testScope");
44
- expect(scope.kind).toBe("namespace");
45
- expect(scope.flags).toBe(OutputScopeFlags.None);
46
31
  expect(scope.metadata.foo).toBe("bar");
47
32
  expect(scope.parent).toBe(parentScope);
48
33
  expect(parentScope.children.has(scope)).toBe(true);
@@ -51,7 +36,7 @@ describe("OutputScope constructor", () => {
51
36
 
52
37
  describe("OutputScope reactivity", () => {
53
38
  it("is reactive on name", () => {
54
- const scope = new OutputScope("initialName", { binder });
39
+ const scope = createScope("initialName");
55
40
  const nameSpy = vi.fn();
56
41
  watch(() => scope.name, nameSpy);
57
42
 
@@ -61,31 +46,20 @@ describe("OutputScope reactivity", () => {
61
46
  expect(scope.name).toBe("newName");
62
47
  });
63
48
 
64
- it("is reactive on flags", () => {
65
- const scope = new OutputScope("scope", { binder });
66
- const flagsSpy = vi.fn();
67
- watch(() => scope.flags, flagsSpy);
68
-
69
- scope.flags = OutputScopeFlags.InstanceMemberScope;
70
- flushJobs();
71
- expect(flagsSpy).toHaveBeenCalled();
72
- expect(scope.flags).toBe(OutputScopeFlags.InstanceMemberScope);
73
- });
74
-
75
49
  it("updates symbolNames when symbols are added", () => {
76
- const scope = new OutputScope("scope", { binder });
50
+ const scope = createScope("scope");
77
51
  const symbolNamesSpy = vi.fn();
78
52
  watch(() => scope.symbolNames.size, symbolNamesSpy);
79
53
 
80
- new OutputSymbol("symbol1", { binder, scope });
54
+ createSymbol("symbol1", scope);
81
55
  flushJobs();
82
56
  expect(symbolNamesSpy).toHaveBeenCalled();
83
57
  expect(scope.symbolNames.has("symbol1")).toBe(true);
84
58
  });
85
59
 
86
60
  it("updates symbolNames when a symbol's name changes", () => {
87
- const scope = new OutputScope("scope", { binder });
88
- const symbol = new OutputSymbol("oldName", { binder, scope });
61
+ const scope = createScope("scope");
62
+ const [symbol] = createSymbol("oldName", scope);
89
63
  flushJobs();
90
64
 
91
65
  // Verify initial state
@@ -114,7 +88,7 @@ describe("OutputScope reactivity", () => {
114
88
  });
115
89
 
116
90
  it("doesn't get wrapped in a reactive proxy", () => {
117
- const scope = new OutputScope("scope", { binder });
91
+ const scope = createScope("scope");
118
92
 
119
93
  const rScope = reactive(scope);
120
94
  expect(rScope).toBe(scope);
@@ -123,9 +97,9 @@ describe("OutputScope reactivity", () => {
123
97
 
124
98
  describe("OutputScope#symbols", () => {
125
99
  it("adds symbols to its collection", () => {
126
- const scope = new OutputScope("scope", { binder });
127
- const sym1 = new OutputSymbol("sym1", { binder, scope });
128
- const sym2 = new OutputSymbol("sym2", { binder, scope });
100
+ const scope = createScope("scope");
101
+ const [sym1] = createSymbol("sym1", scope);
102
+ const [sym2] = createSymbol("sym2", scope);
129
103
  flushJobs();
130
104
 
131
105
  expect(scope.symbols.size).toBe(2);
@@ -134,23 +108,25 @@ describe("OutputScope#symbols", () => {
134
108
  });
135
109
 
136
110
  it("resolves symbol name conflicts", () => {
137
- const scope = new OutputScope("scope", { binder });
138
- const s1 = new OutputSymbol("sym", { binder, scope });
139
- const s2 = new OutputSymbol("sym", { binder, scope });
140
- const s3 = new OutputSymbol("sym", { binder, scope });
111
+ const scope = createScope("scope");
112
+ const [s1] = createSymbol("sym", scope);
113
+ const [s2] = createSymbol("sym", scope);
114
+ const [s3] = createSymbol("sym", scope);
115
+
141
116
  flushJobs();
142
117
 
143
118
  expect(s1.name).toBe("sym");
144
119
  expect(s2.name).toBe("sym_2");
145
120
  expect(s3.name).toBe("sym_3");
121
+ flushJobs();
146
122
  expect(scope.symbolNames.has("sym")).toBe(true);
147
123
  expect(scope.symbolNames.has("sym_2")).toBe(true);
148
124
  expect(scope.symbolNames.has("sym_3")).toBe(true);
149
125
  });
150
126
 
151
127
  it("updates when a symbol is deleted", () => {
152
- const scope = new OutputScope("scope", { binder });
153
- const sym = new OutputSymbol("sym", { binder, scope });
128
+ const scope = createScope("scope");
129
+ const [sym] = createSymbol("sym", scope);
154
130
  flushJobs();
155
131
 
156
132
  expect(scope.symbols.size).toBe(1);
@@ -166,15 +142,15 @@ describe("OutputScope#symbols", () => {
166
142
  });
167
143
 
168
144
  it("updates when a symbol changes scope", () => {
169
- const scope1 = new OutputScope("scope1", { binder });
170
- const scope2 = new OutputScope("scope2", { binder });
171
- const sym = new OutputSymbol("sym", { binder, scope: scope1 });
145
+ const scope1 = createScope("scope1");
146
+ const scope2 = createScope("scope2");
147
+ const [sym] = createSymbol("sym", scope1);
172
148
  flushJobs();
173
149
 
174
150
  expect(scope1.symbols.size).toBe(1);
175
151
  expect(scope2.symbols.size).toBe(0);
176
152
 
177
- sym.scope = scope2;
153
+ sym.spaces = [scope2.symbols];
178
154
  flushJobs();
179
155
 
180
156
  expect(scope1.symbols.size).toBe(0);
@@ -188,7 +164,7 @@ describe("OutputScope#symbols", () => {
188
164
 
189
165
  describe("OutputScope#symbolsByRefkey", () => {
190
166
  it("maps refkeys to symbols", () => {
191
- const scope = new OutputScope("scope", { binder });
167
+ const scope = createScope("scope");
192
168
 
193
169
  // Use the refkey function to create refkeys
194
170
  // This is based on how refkey is being imported in binder.ts
@@ -197,16 +173,12 @@ describe("OutputScope#symbolsByRefkey", () => {
197
173
  const key2b = "key2b" as unknown as Refkey;
198
174
 
199
175
  // Create a symbol with a refkey
200
- const sym1 = new OutputSymbol("sym1", {
201
- binder,
202
- scope,
176
+ const [sym1] = createSymbol("sym1", scope, {
203
177
  refkeys: [key1],
204
178
  });
205
179
 
206
180
  // Create a symbol with multiple refkeys
207
- const sym2 = new OutputSymbol("sym2", {
208
- binder,
209
- scope,
181
+ const [sym2] = createSymbol("sym2", scope, {
210
182
  refkeys: [key2a, key2b],
211
183
  });
212
184
 
@@ -220,9 +192,9 @@ describe("OutputScope#symbolsByRefkey", () => {
220
192
 
221
193
  describe("OutputScope#children", () => {
222
194
  it("tracks child scopes", () => {
223
- const parentScope = new OutputScope("parent", { binder });
224
- const child1 = new OutputScope("child1", { binder, parent: parentScope });
225
- const child2 = new OutputScope("child2", { binder, parent: parentScope });
195
+ const parentScope = createScope("parent");
196
+ const child1 = createScope("child1", parentScope);
197
+ const child2 = createScope("child2", parentScope);
226
198
  flushJobs();
227
199
 
228
200
  expect(parentScope.children.size).toBe(2);
@@ -234,67 +206,3 @@ describe("OutputScope#children", () => {
234
206
  expect(child2.parent).toBe(parentScope);
235
207
  });
236
208
  });
237
-
238
- describe("OutputScope#clone", () => {
239
- let originalScope: OutputScope;
240
- const originalMetadata = { data: "original", nested: { value: 1 } };
241
-
242
- beforeEach(() => {
243
- const parentScope = new OutputScope("parent", { binder });
244
-
245
- originalScope = new OutputScope("original", {
246
- binder: binder,
247
- kind: "class",
248
- metadata: { ...originalMetadata },
249
- parent: parentScope,
250
- });
251
-
252
- // Add a symbol and child scope to the original
253
- new OutputSymbol("symbolInOriginal", { binder, scope: originalScope });
254
- new OutputScope("childOfOriginal", { binder, parent: originalScope });
255
- flushJobs();
256
- });
257
-
258
- it("clones basic properties", () => {
259
- const newScope = new OutputScope("newScope", { binder });
260
- const clonedScope = originalScope.clone({ parent: newScope });
261
-
262
- expect(clonedScope.name).toBe(originalScope.name);
263
- expect(clonedScope.kind).toBe(originalScope.kind);
264
- expect(clonedScope.flags).toBe(originalScope.flags);
265
- expect(clonedScope.id).not.toBe(originalScope.id);
266
-
267
- expect(clonedScope.metadata).toEqual(originalScope.metadata);
268
-
269
- expect(clonedScope.symbols.size).toBe(1);
270
- expect(clonedScope.children.size).toBe(1);
271
- });
272
-
273
- it("can override parent in clone options", () => {
274
- const newParent = new OutputScope("newParent", { binder });
275
- const clonedScope = originalScope.clone({ parent: newParent });
276
- flushJobs();
277
-
278
- expect(clonedScope.parent).toBe(newParent);
279
- expect(newParent.children.has(clonedScope)).toBe(true);
280
- });
281
-
282
- it("can override owner in clone options", () => {
283
- const newOwnerParent = new OutputScope("newOwnerParent", { binder });
284
- const newOwner = new OutputSymbol("newOwner", {
285
- binder,
286
- scope: newOwnerParent,
287
- });
288
- const clonedScope = originalScope.clone({ owner: newOwner });
289
- flushJobs();
290
-
291
- expect(clonedScope.owner).toBe(newOwner);
292
- });
293
-
294
- it("allows independent changes to clone properties", () => {
295
- const clonedScope = originalScope.clone();
296
- clonedScope.name = "clonedName";
297
-
298
- expect(originalScope.name).toBe("original");
299
- });
300
- });