@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,48 +1,30 @@
1
1
  import { reactive, watch } from "@vue/reactivity";
2
- import { beforeEach, describe, expect, it, vi } from "vitest";
3
- import { createOutputBinder } from "../../src/binder.js";
2
+ import { describe, expect, it, vi } from "vitest";
4
3
  import { flushJobs } from "../../src/scheduler.js";
5
- import { OutputScopeFlags } from "../../src/symbols/flags.js";
6
- import { OutputScope } from "../../src/symbols/output-scope.js";
7
- import { OutputSymbol } from "../../src/symbols/output-symbol.js";
4
+ import { BasicScope } from "../../src/symbols/basic-scope.js";
8
5
  import { SymbolTable } from "../../src/symbols/symbol-table.js";
9
- let binder;
10
- beforeEach(() => {
11
- binder = createOutputBinder();
12
- });
6
+ import { binder, createScope, createSymbol } from "./utils.js";
13
7
  describe("OutputScope constructor", () => {
14
8
  it("initializes properties correctly with default options", () => {
15
- const scope = new OutputScope("testScope", {
16
- binder
17
- });
9
+ const scope = createScope("testScope");
18
10
  expect(scope.name).toBe("testScope");
19
11
  expect(scope.binder).toBe(binder);
20
12
  expect(scope.id).toEqual(expect.any(Number));
21
- expect(scope.kind).toBe("scope");
22
- expect(scope.flags).toBe(OutputScopeFlags.None);
23
13
  expect(scope.metadata).toEqual({});
24
- expect(scope.parent).toBe(binder.globalScope);
25
- expect(scope.owner).toBeUndefined();
26
14
  expect(scope.symbols).toBeInstanceOf(SymbolTable);
27
15
  expect(scope.symbolNames.size).toBe(0);
28
16
  expect(scope.children.size).toBe(0);
29
17
  });
30
18
  it("initializes properties correctly with custom options", () => {
31
- const parentScope = new OutputScope("parentScope", {
32
- binder
33
- });
19
+ const parentScope = createScope("parentScope");
34
20
  const metadata = {
35
21
  foo: "bar"
36
22
  };
37
- const scope = new OutputScope("testScope", {
23
+ const scope = new BasicScope("testScope", parentScope, {
38
24
  binder,
39
- kind: "namespace",
40
- metadata,
41
- parent: parentScope
25
+ metadata
42
26
  });
43
27
  expect(scope.name).toBe("testScope");
44
- expect(scope.kind).toBe("namespace");
45
- expect(scope.flags).toBe(OutputScopeFlags.None);
46
28
  expect(scope.metadata.foo).toBe("bar");
47
29
  expect(scope.parent).toBe(parentScope);
48
30
  expect(parentScope.children.has(scope)).toBe(true);
@@ -50,9 +32,7 @@ describe("OutputScope constructor", () => {
50
32
  });
51
33
  describe("OutputScope reactivity", () => {
52
34
  it("is reactive on name", () => {
53
- const scope = new OutputScope("initialName", {
54
- binder
55
- });
35
+ const scope = createScope("initialName");
56
36
  const nameSpy = vi.fn();
57
37
  watch(() => scope.name, nameSpy);
58
38
  scope.name = "newName";
@@ -60,39 +40,18 @@ describe("OutputScope reactivity", () => {
60
40
  expect(nameSpy).toHaveBeenCalled();
61
41
  expect(scope.name).toBe("newName");
62
42
  });
63
- it("is reactive on flags", () => {
64
- const scope = new OutputScope("scope", {
65
- binder
66
- });
67
- const flagsSpy = vi.fn();
68
- watch(() => scope.flags, flagsSpy);
69
- scope.flags = OutputScopeFlags.InstanceMemberScope;
70
- flushJobs();
71
- expect(flagsSpy).toHaveBeenCalled();
72
- expect(scope.flags).toBe(OutputScopeFlags.InstanceMemberScope);
73
- });
74
43
  it("updates symbolNames when symbols are added", () => {
75
- const scope = new OutputScope("scope", {
76
- binder
77
- });
44
+ const scope = createScope("scope");
78
45
  const symbolNamesSpy = vi.fn();
79
46
  watch(() => scope.symbolNames.size, symbolNamesSpy);
80
- new OutputSymbol("symbol1", {
81
- binder,
82
- scope
83
- });
47
+ createSymbol("symbol1", scope);
84
48
  flushJobs();
85
49
  expect(symbolNamesSpy).toHaveBeenCalled();
86
50
  expect(scope.symbolNames.has("symbol1")).toBe(true);
87
51
  });
88
52
  it("updates symbolNames when a symbol's name changes", () => {
89
- const scope = new OutputScope("scope", {
90
- binder
91
- });
92
- const symbol = new OutputSymbol("oldName", {
93
- binder,
94
- scope
95
- });
53
+ const scope = createScope("scope");
54
+ const [symbol] = createSymbol("oldName", scope);
96
55
  flushJobs();
97
56
 
98
57
  // Verify initial state
@@ -118,63 +77,38 @@ describe("OutputScope reactivity", () => {
118
77
  expect(scope.symbolNames.has("newName")).toBe(true);
119
78
  });
120
79
  it("doesn't get wrapped in a reactive proxy", () => {
121
- const scope = new OutputScope("scope", {
122
- binder
123
- });
80
+ const scope = createScope("scope");
124
81
  const rScope = reactive(scope);
125
82
  expect(rScope).toBe(scope);
126
83
  });
127
84
  });
128
85
  describe("OutputScope#symbols", () => {
129
86
  it("adds symbols to its collection", () => {
130
- const scope = new OutputScope("scope", {
131
- binder
132
- });
133
- const sym1 = new OutputSymbol("sym1", {
134
- binder,
135
- scope
136
- });
137
- const sym2 = new OutputSymbol("sym2", {
138
- binder,
139
- scope
140
- });
87
+ const scope = createScope("scope");
88
+ const [sym1] = createSymbol("sym1", scope);
89
+ const [sym2] = createSymbol("sym2", scope);
141
90
  flushJobs();
142
91
  expect(scope.symbols.size).toBe(2);
143
92
  expect(scope.symbols.has(sym1)).toBe(true);
144
93
  expect(scope.symbols.has(sym2)).toBe(true);
145
94
  });
146
95
  it("resolves symbol name conflicts", () => {
147
- const scope = new OutputScope("scope", {
148
- binder
149
- });
150
- const s1 = new OutputSymbol("sym", {
151
- binder,
152
- scope
153
- });
154
- const s2 = new OutputSymbol("sym", {
155
- binder,
156
- scope
157
- });
158
- const s3 = new OutputSymbol("sym", {
159
- binder,
160
- scope
161
- });
96
+ const scope = createScope("scope");
97
+ const [s1] = createSymbol("sym", scope);
98
+ const [s2] = createSymbol("sym", scope);
99
+ const [s3] = createSymbol("sym", scope);
162
100
  flushJobs();
163
101
  expect(s1.name).toBe("sym");
164
102
  expect(s2.name).toBe("sym_2");
165
103
  expect(s3.name).toBe("sym_3");
104
+ flushJobs();
166
105
  expect(scope.symbolNames.has("sym")).toBe(true);
167
106
  expect(scope.symbolNames.has("sym_2")).toBe(true);
168
107
  expect(scope.symbolNames.has("sym_3")).toBe(true);
169
108
  });
170
109
  it("updates when a symbol is deleted", () => {
171
- const scope = new OutputScope("scope", {
172
- binder
173
- });
174
- const sym = new OutputSymbol("sym", {
175
- binder,
176
- scope
177
- });
110
+ const scope = createScope("scope");
111
+ const [sym] = createSymbol("sym", scope);
178
112
  flushJobs();
179
113
  expect(scope.symbols.size).toBe(1);
180
114
  expect(scope.symbols.has(sym)).toBe(true);
@@ -186,20 +120,13 @@ describe("OutputScope#symbols", () => {
186
120
  expect(scope.symbolNames.has("sym")).toBe(false);
187
121
  });
188
122
  it("updates when a symbol changes scope", () => {
189
- const scope1 = new OutputScope("scope1", {
190
- binder
191
- });
192
- const scope2 = new OutputScope("scope2", {
193
- binder
194
- });
195
- const sym = new OutputSymbol("sym", {
196
- binder,
197
- scope: scope1
198
- });
123
+ const scope1 = createScope("scope1");
124
+ const scope2 = createScope("scope2");
125
+ const [sym] = createSymbol("sym", scope1);
199
126
  flushJobs();
200
127
  expect(scope1.symbols.size).toBe(1);
201
128
  expect(scope2.symbols.size).toBe(0);
202
- sym.scope = scope2;
129
+ sym.spaces = [scope2.symbols];
203
130
  flushJobs();
204
131
  expect(scope1.symbols.size).toBe(0);
205
132
  expect(scope2.symbols.size).toBe(1);
@@ -211,9 +138,7 @@ describe("OutputScope#symbols", () => {
211
138
  });
212
139
  describe("OutputScope#symbolsByRefkey", () => {
213
140
  it("maps refkeys to symbols", () => {
214
- const scope = new OutputScope("scope", {
215
- binder
216
- });
141
+ const scope = createScope("scope");
217
142
 
218
143
  // Use the refkey function to create refkeys
219
144
  // This is based on how refkey is being imported in binder.ts
@@ -222,16 +147,12 @@ describe("OutputScope#symbolsByRefkey", () => {
222
147
  const key2b = "key2b";
223
148
 
224
149
  // Create a symbol with a refkey
225
- const sym1 = new OutputSymbol("sym1", {
226
- binder,
227
- scope,
150
+ const [sym1] = createSymbol("sym1", scope, {
228
151
  refkeys: [key1]
229
152
  });
230
153
 
231
154
  // Create a symbol with multiple refkeys
232
- const sym2 = new OutputSymbol("sym2", {
233
- binder,
234
- scope,
155
+ const [sym2] = createSymbol("sym2", scope, {
235
156
  refkeys: [key2a, key2b]
236
157
  });
237
158
  flushJobs();
@@ -242,17 +163,9 @@ describe("OutputScope#symbolsByRefkey", () => {
242
163
  });
243
164
  describe("OutputScope#children", () => {
244
165
  it("tracks child scopes", () => {
245
- const parentScope = new OutputScope("parent", {
246
- binder
247
- });
248
- const child1 = new OutputScope("child1", {
249
- binder,
250
- parent: parentScope
251
- });
252
- const child2 = new OutputScope("child2", {
253
- binder,
254
- parent: parentScope
255
- });
166
+ const parentScope = createScope("parent");
167
+ const child1 = createScope("child1", parentScope);
168
+ const child2 = createScope("child2", parentScope);
256
169
  flushJobs();
257
170
  expect(parentScope.children.size).toBe(2);
258
171
  expect(parentScope.children.has(child1)).toBe(true);
@@ -262,82 +175,4 @@ describe("OutputScope#children", () => {
262
175
  expect(child1.parent).toBe(parentScope);
263
176
  expect(child2.parent).toBe(parentScope);
264
177
  });
265
- });
266
- describe("OutputScope#clone", () => {
267
- let originalScope;
268
- const originalMetadata = {
269
- data: "original",
270
- nested: {
271
- value: 1
272
- }
273
- };
274
- beforeEach(() => {
275
- const parentScope = new OutputScope("parent", {
276
- binder
277
- });
278
- originalScope = new OutputScope("original", {
279
- binder: binder,
280
- kind: "class",
281
- metadata: {
282
- ...originalMetadata
283
- },
284
- parent: parentScope
285
- });
286
-
287
- // Add a symbol and child scope to the original
288
- new OutputSymbol("symbolInOriginal", {
289
- binder,
290
- scope: originalScope
291
- });
292
- new OutputScope("childOfOriginal", {
293
- binder,
294
- parent: originalScope
295
- });
296
- flushJobs();
297
- });
298
- it("clones basic properties", () => {
299
- const newScope = new OutputScope("newScope", {
300
- binder
301
- });
302
- const clonedScope = originalScope.clone({
303
- parent: newScope
304
- });
305
- expect(clonedScope.name).toBe(originalScope.name);
306
- expect(clonedScope.kind).toBe(originalScope.kind);
307
- expect(clonedScope.flags).toBe(originalScope.flags);
308
- expect(clonedScope.id).not.toBe(originalScope.id);
309
- expect(clonedScope.metadata).toEqual(originalScope.metadata);
310
- expect(clonedScope.symbols.size).toBe(1);
311
- expect(clonedScope.children.size).toBe(1);
312
- });
313
- it("can override parent in clone options", () => {
314
- const newParent = new OutputScope("newParent", {
315
- binder
316
- });
317
- const clonedScope = originalScope.clone({
318
- parent: newParent
319
- });
320
- flushJobs();
321
- expect(clonedScope.parent).toBe(newParent);
322
- expect(newParent.children.has(clonedScope)).toBe(true);
323
- });
324
- it("can override owner in clone options", () => {
325
- const newOwnerParent = new OutputScope("newOwnerParent", {
326
- binder
327
- });
328
- const newOwner = new OutputSymbol("newOwner", {
329
- binder,
330
- scope: newOwnerParent
331
- });
332
- const clonedScope = originalScope.clone({
333
- owner: newOwner
334
- });
335
- flushJobs();
336
- expect(clonedScope.owner).toBe(newOwner);
337
- });
338
- it("allows independent changes to clone properties", () => {
339
- const clonedScope = originalScope.clone();
340
- clonedScope.name = "clonedName";
341
- expect(originalScope.name).toBe("original");
342
- });
343
178
  });