@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.
- package/dist/src/binder.d.ts +62 -38
- package/dist/src/binder.d.ts.map +1 -1
- package/dist/src/binder.js +214 -173
- package/dist/src/components/Declaration.d.ts +2 -2
- package/dist/src/components/Declaration.d.ts.map +1 -1
- package/dist/src/components/Declaration.js +8 -2
- package/dist/src/components/MemberDeclaration.d.ts +2 -2
- package/dist/src/components/MemberDeclaration.d.ts.map +1 -1
- package/dist/src/components/MemberDeclaration.js +9 -5
- package/dist/src/components/MemberScope.d.ts +30 -13
- package/dist/src/components/MemberScope.d.ts.map +1 -1
- package/dist/src/components/MemberScope.js +37 -15
- package/dist/src/components/Output.d.ts.map +1 -1
- package/dist/src/components/Output.js +2 -5
- package/dist/src/components/ReferenceOrContent.d.ts +1 -1
- package/dist/src/components/ReferenceOrContent.d.ts.map +1 -1
- package/dist/src/components/Scope.d.ts +5 -5
- package/dist/src/components/Scope.d.ts.map +1 -1
- package/dist/src/components/Scope.js +9 -5
- package/dist/src/context/member-scope.d.ts +7 -8
- package/dist/src/context/member-scope.d.ts.map +1 -1
- package/dist/src/context/member-scope.js +5 -5
- package/dist/src/context/name-policy.d.ts.map +1 -1
- package/dist/src/context/name-policy.js +3 -0
- package/dist/src/context/scope.d.ts +1 -0
- package/dist/src/context/scope.d.ts.map +1 -1
- package/dist/src/context/scope.js +7 -0
- package/dist/src/inspect.browser.d.ts +5 -0
- package/dist/src/inspect.browser.d.ts.map +1 -0
- package/dist/src/inspect.browser.js +5 -0
- package/dist/src/inspect.d.ts +2 -0
- package/dist/src/inspect.d.ts.map +1 -0
- package/dist/src/inspect.js +1 -0
- package/dist/src/name-policy.d.ts +11 -0
- package/dist/src/name-policy.d.ts.map +1 -1
- package/dist/src/name-policy.js +3 -0
- package/dist/src/reactive-union-set.d.ts.map +1 -1
- package/dist/src/reactive-union-set.js +12 -8
- package/dist/src/refkey.d.ts +39 -3
- package/dist/src/refkey.d.ts.map +1 -1
- package/dist/src/refkey.js +52 -8
- package/dist/src/symbols/basic-scope.d.ts +14 -0
- package/dist/src/symbols/basic-scope.d.ts.map +1 -0
- package/dist/src/symbols/basic-scope.js +20 -0
- package/dist/src/symbols/basic-symbol.d.ts +19 -0
- package/dist/src/symbols/basic-symbol.d.ts.map +1 -0
- package/dist/src/symbols/basic-symbol.js +28 -0
- package/dist/src/symbols/index.d.ts +3 -1
- package/dist/src/symbols/index.d.ts.map +1 -1
- package/dist/src/symbols/index.js +3 -1
- package/dist/src/symbols/output-scope.d.ts +70 -41
- package/dist/src/symbols/output-scope.d.ts.map +1 -1
- package/dist/src/symbols/output-scope.js +98 -130
- package/dist/src/symbols/output-space.d.ts +25 -0
- package/dist/src/symbols/output-space.d.ts.map +1 -0
- package/dist/src/symbols/output-space.js +35 -0
- package/dist/src/symbols/output-symbol.d.ts +213 -37
- package/dist/src/symbols/output-symbol.d.ts.map +1 -1
- package/dist/src/symbols/output-symbol.js +323 -203
- package/dist/src/symbols/symbol-flow.d.ts +1 -1
- package/dist/src/symbols/symbol-flow.d.ts.map +1 -1
- package/dist/src/symbols/symbol-flow.js +22 -7
- package/dist/src/symbols/symbol-slot.d.ts +27 -9
- package/dist/src/symbols/symbol-slot.d.ts.map +1 -1
- package/dist/src/symbols/symbol-slot.js +20 -4
- package/dist/src/symbols/symbol-table.d.ts +19 -8
- package/dist/src/symbols/symbol-table.d.ts.map +1 -1
- package/dist/src/symbols/symbol-table.js +65 -16
- package/dist/src/tracer.d.ts +15 -3
- package/dist/src/tracer.d.ts.map +1 -1
- package/dist/src/tracer.js +39 -63
- package/dist/test/components/declaration.test.js +9 -14
- package/dist/test/components/reference-or-content.test.js +2 -2
- package/dist/test/symbols/output-scope.test.js +33 -198
- package/dist/test/symbols/output-symbol.test.js +139 -385
- package/dist/test/symbols/resolution.test.js +431 -114
- package/dist/test/symbols/symbol-table.test.d.ts +2 -0
- package/dist/test/symbols/symbol-table.test.d.ts.map +1 -0
- package/dist/test/symbols/symbol-table.test.js +14 -0
- package/dist/test/symbols/utils.d.ts +10 -24
- package/dist/test/symbols/utils.d.ts.map +1 -1
- package/dist/test/symbols/utils.js +23 -45
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -2
- package/src/binder.ts +348 -273
- package/src/components/Declaration.tsx +13 -3
- package/src/components/MemberDeclaration.tsx +15 -8
- package/src/components/MemberScope.tsx +61 -20
- package/src/components/Output.tsx +0 -4
- package/src/components/Scope.tsx +16 -9
- package/src/context/member-scope.ts +10 -10
- package/src/context/name-policy.ts +3 -0
- package/src/context/scope.ts +9 -0
- package/src/inspect.browser.ts +6 -0
- package/src/inspect.ts +1 -0
- package/src/name-policy.ts +14 -0
- package/src/reactive-union-set.ts +14 -8
- package/src/refkey.ts +88 -14
- package/src/symbols/basic-scope.ts +23 -0
- package/src/symbols/basic-symbol.ts +32 -0
- package/src/symbols/index.ts +3 -1
- package/src/symbols/output-scope.ts +131 -170
- package/src/symbols/output-space.ts +49 -0
- package/src/symbols/output-symbol.ts +434 -258
- package/src/symbols/symbol-flow.ts +38 -9
- package/src/symbols/symbol-slot.tsx +46 -8
- package/src/symbols/symbol-table.ts +95 -21
- package/src/tracer.ts +53 -83
- package/temp/api.json +5559 -3079
- package/test/components/declaration.test.tsx +6 -19
- package/test/components/reference-or-content.test.tsx +2 -2
- package/test/symbols/output-scope.test.ts +33 -125
- package/test/symbols/output-symbol.test.ts +128 -348
- package/test/symbols/resolution.test.ts +530 -117
- package/test/symbols/symbol-table.test.ts +15 -0
- package/test/symbols/utils.ts +38 -74
- package/tsdoc.json +4 -0
- package/dist/src/slot.d.ts +0 -15
- package/dist/src/slot.d.ts.map +0 -1
- package/dist/src/slot.js +0 -50
- package/dist/src/symbols/flags.d.ts +0 -70
- package/dist/src/symbols/flags.d.ts.map +0 -1
- package/dist/src/symbols/flags.js +0 -72
- package/dist/test/components/slot.test.d.ts +0 -2
- package/dist/test/components/slot.test.d.ts.map +0 -1
- package/dist/test/components/slot.test.js +0 -134
- package/src/slot.ts +0 -89
- package/src/symbols/flags.ts +0 -82
- package/test/components/slot.test.tsx +0 -174
|
@@ -1,26 +1,12 @@
|
|
|
1
1
|
import { reactive, watch } from "@vue/reactivity";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { MemberScopeContext } from "../../src/context/member-scope.js";
|
|
5
|
-
import { ScopeContext } from "../../src/index.browser.js";
|
|
6
|
-
import { renderTree } from "../../src/render.js";
|
|
2
|
+
import { describe, expect, it, vi } from "vitest";
|
|
3
|
+
import { namekey } from "../../src/refkey.js";
|
|
7
4
|
import { flushJobs } from "../../src/scheduler.js";
|
|
8
|
-
import {
|
|
9
|
-
import { OutputScope } from "../../src/symbols/output-scope.js";
|
|
10
|
-
import { OutputSymbol } from "../../src/symbols/output-symbol.js";
|
|
11
|
-
let binder;
|
|
12
|
-
beforeEach(() => {
|
|
13
|
-
binder = createOutputBinder();
|
|
14
|
-
});
|
|
5
|
+
import { binder, createScope, createSymbol } from "./utils.js";
|
|
15
6
|
describe("OutputSymbol reactivity", () => {
|
|
16
7
|
it("keeps symbol names up-to-date", () => {
|
|
17
|
-
const scope =
|
|
18
|
-
|
|
19
|
-
});
|
|
20
|
-
const symbol = new OutputSymbol("sym", {
|
|
21
|
-
binder,
|
|
22
|
-
scope
|
|
23
|
-
});
|
|
8
|
+
const scope = createScope("scope");
|
|
9
|
+
const [symbol] = createSymbol("sym", scope);
|
|
24
10
|
flushJobs();
|
|
25
11
|
expect(scope.symbolNames.has("sym")).toBe(true);
|
|
26
12
|
symbol.name = "bar";
|
|
@@ -28,126 +14,39 @@ describe("OutputSymbol reactivity", () => {
|
|
|
28
14
|
expect(scope.symbolNames.has("bar")).toBe(true);
|
|
29
15
|
});
|
|
30
16
|
it("resolves symbol conflicts", () => {
|
|
31
|
-
const scope =
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
binder,
|
|
36
|
-
scope
|
|
37
|
-
});
|
|
38
|
-
const s2 = new OutputSymbol("sym", {
|
|
39
|
-
binder,
|
|
40
|
-
scope
|
|
41
|
-
});
|
|
42
|
-
const s3 = new OutputSymbol("sym", {
|
|
43
|
-
binder,
|
|
44
|
-
scope
|
|
45
|
-
});
|
|
17
|
+
const scope = createScope("scope");
|
|
18
|
+
const [s1] = createSymbol("sym", scope);
|
|
19
|
+
const [s2] = createSymbol("sym", scope);
|
|
20
|
+
const [s3] = createSymbol("sym", scope);
|
|
46
21
|
flushJobs();
|
|
47
22
|
expect(s1.name).toEqual("sym");
|
|
48
23
|
expect(s2.name).toEqual("sym_2");
|
|
49
24
|
expect(s3.name).toEqual("sym_3");
|
|
50
25
|
});
|
|
51
|
-
it("is reactive on name,
|
|
52
|
-
const scope =
|
|
53
|
-
|
|
54
|
-
});
|
|
55
|
-
const symbol = new OutputSymbol("sym", {
|
|
56
|
-
binder,
|
|
57
|
-
scope
|
|
58
|
-
});
|
|
26
|
+
it("is reactive on name, space, and scope", () => {
|
|
27
|
+
const scope = createScope("scope");
|
|
28
|
+
const [symbol] = createSymbol("sym", scope);
|
|
59
29
|
const nameSpy = vi.fn();
|
|
60
30
|
watch(() => symbol.name, nameSpy);
|
|
61
|
-
const flagsSpy = vi.fn();
|
|
62
|
-
watch(() => symbol.flags, flagsSpy);
|
|
63
31
|
const scopeSpy = vi.fn();
|
|
64
32
|
watch(() => symbol.scope, scopeSpy);
|
|
65
|
-
const instanceMemberScopeSpy = vi.fn();
|
|
66
|
-
watch(() => symbol.instanceMemberScope, instanceMemberScopeSpy);
|
|
67
|
-
const staticMemberScopeSpy = vi.fn();
|
|
68
|
-
watch(() => symbol.staticMemberScope, staticMemberScopeSpy);
|
|
69
33
|
symbol.name = "foo";
|
|
70
|
-
|
|
71
|
-
symbol.
|
|
72
|
-
binder
|
|
73
|
-
});
|
|
74
|
-
symbol.flags |= OutputSymbolFlags.InstanceMemberContainer | OutputSymbolFlags.StaticMemberContainer;
|
|
34
|
+
const newScope = createScope("new-scope");
|
|
35
|
+
symbol.spaces = [newScope.symbols];
|
|
75
36
|
expect(nameSpy).toHaveBeenCalled();
|
|
76
|
-
expect(flagsSpy).toHaveBeenCalled();
|
|
77
37
|
expect(scopeSpy).toHaveBeenCalled();
|
|
78
|
-
expect(instanceMemberScopeSpy).toHaveBeenCalled();
|
|
79
|
-
expect(staticMemberScopeSpy).toHaveBeenCalled();
|
|
80
38
|
});
|
|
81
39
|
it("doesn't get wrapped in a reactive proxy", () => {
|
|
82
|
-
const scope =
|
|
83
|
-
|
|
84
|
-
});
|
|
85
|
-
const symbol = new OutputSymbol("sym", {
|
|
86
|
-
binder,
|
|
87
|
-
scope
|
|
88
|
-
});
|
|
40
|
+
const scope = createScope("scope");
|
|
41
|
+
const [symbol] = createSymbol("sym", scope);
|
|
89
42
|
const rSymbol = reactive(symbol);
|
|
90
43
|
expect(rSymbol).toBe(symbol);
|
|
91
44
|
});
|
|
92
45
|
});
|
|
93
|
-
describe("OutputSymbol#flags", () => {
|
|
94
|
-
it("sets member flags based on parent scope", () => {
|
|
95
|
-
const scope = new OutputScope("scope", {
|
|
96
|
-
binder
|
|
97
|
-
});
|
|
98
|
-
const symbol = new OutputSymbol("sym", {
|
|
99
|
-
binder,
|
|
100
|
-
scope
|
|
101
|
-
});
|
|
102
|
-
expect(symbol.flags & OutputSymbolFlags.Member).toBeFalsy();
|
|
103
|
-
const memberScope = new OutputScope("member-scope", {
|
|
104
|
-
binder,
|
|
105
|
-
owner: symbol,
|
|
106
|
-
flags: OutputScopeFlags.InstanceMemberScope
|
|
107
|
-
});
|
|
108
|
-
const memberSymbol = new OutputSymbol("member-sym", {
|
|
109
|
-
binder,
|
|
110
|
-
scope: memberScope
|
|
111
|
-
});
|
|
112
|
-
expect(memberSymbol.flags & OutputSymbolFlags.InstanceMember).toBeTruthy();
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
describe("OutputSymbol#staticMemberScope", () => {
|
|
116
|
-
it("is created when needed", () => {
|
|
117
|
-
const scope = new OutputScope("scope", {
|
|
118
|
-
binder
|
|
119
|
-
});
|
|
120
|
-
const symbol = new OutputSymbol("sym", {
|
|
121
|
-
binder,
|
|
122
|
-
scope,
|
|
123
|
-
flags: OutputSymbolFlags.StaticMemberContainer
|
|
124
|
-
});
|
|
125
|
-
expect(symbol.staticMemberScope).toBeDefined();
|
|
126
|
-
expect(symbol.staticMemberScope.symbols.size).toEqual(0);
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
describe("OutputSymbol#instanceMemberScope", () => {
|
|
130
|
-
it("is created when needed", () => {
|
|
131
|
-
const scope = new OutputScope("scope", {
|
|
132
|
-
binder
|
|
133
|
-
});
|
|
134
|
-
const symbol = new OutputSymbol("sym", {
|
|
135
|
-
binder,
|
|
136
|
-
scope,
|
|
137
|
-
flags: OutputSymbolFlags.InstanceMemberContainer
|
|
138
|
-
});
|
|
139
|
-
expect(symbol.instanceMemberScope).toBeDefined();
|
|
140
|
-
expect(symbol.instanceMemberScope.symbols.size).toEqual(0);
|
|
141
|
-
});
|
|
142
|
-
});
|
|
143
46
|
describe("OutputSymbol#metadata", () => {
|
|
144
47
|
it("is reactive", () => {
|
|
145
|
-
const scope =
|
|
146
|
-
|
|
147
|
-
});
|
|
148
|
-
const symbol = new OutputSymbol("sym", {
|
|
149
|
-
binder,
|
|
150
|
-
scope,
|
|
48
|
+
const scope = createScope("scope");
|
|
49
|
+
const [symbol] = createSymbol("sym", scope, {
|
|
151
50
|
metadata: {
|
|
152
51
|
foo: "bar"
|
|
153
52
|
}
|
|
@@ -161,287 +60,142 @@ describe("OutputSymbol#metadata", () => {
|
|
|
161
60
|
});
|
|
162
61
|
describe("OutputSymbol#scope", () => {
|
|
163
62
|
it("adds to parent scope", () => {
|
|
164
|
-
const scope =
|
|
165
|
-
|
|
166
|
-
});
|
|
167
|
-
const symbol = new OutputSymbol("sym", {
|
|
168
|
-
binder,
|
|
169
|
-
scope
|
|
170
|
-
});
|
|
63
|
+
const scope = createScope("parent");
|
|
64
|
+
const [symbol] = createSymbol("sym", scope);
|
|
171
65
|
expect(scope.symbols.has(symbol)).toBe(true);
|
|
172
66
|
});
|
|
173
|
-
it("defaults to the current lexical scope when not a member", () => {
|
|
174
|
-
const scope = new OutputScope("parent", {
|
|
175
|
-
binder
|
|
176
|
-
});
|
|
177
|
-
withContext([[ScopeContext, scope]], () => {
|
|
178
|
-
const symbol = new OutputSymbol("sym", {
|
|
179
|
-
binder
|
|
180
|
-
});
|
|
181
|
-
expect(scope.symbols.has(symbol)).toBe(true);
|
|
182
|
-
});
|
|
183
|
-
});
|
|
184
|
-
it("defaults to the current member scope when a member", () => {
|
|
185
|
-
const symbol = new OutputSymbol("Class", {
|
|
186
|
-
binder,
|
|
187
|
-
scope: binder.globalScope,
|
|
188
|
-
flags: OutputSymbolFlags.MemberContainer
|
|
189
|
-
});
|
|
190
|
-
withContext([[MemberScopeContext, {
|
|
191
|
-
instanceMembers: symbol.instanceMemberScope,
|
|
192
|
-
staticMembers: symbol.staticMemberScope
|
|
193
|
-
}]], () => {
|
|
194
|
-
const ms = new OutputSymbol("ms", {
|
|
195
|
-
binder,
|
|
196
|
-
flags: OutputSymbolFlags.InstanceMember
|
|
197
|
-
});
|
|
198
|
-
const ss = new OutputSymbol("ss", {
|
|
199
|
-
binder,
|
|
200
|
-
flags: OutputSymbolFlags.StaticMember
|
|
201
|
-
});
|
|
202
|
-
expect(symbol.instanceMemberScope.symbols.has(ms)).toBe(true);
|
|
203
|
-
expect(symbol.staticMemberScope.symbols.has(ss)).toBe(true);
|
|
204
|
-
});
|
|
205
|
-
});
|
|
206
67
|
});
|
|
207
|
-
function withContext(contexts, fn) {
|
|
208
|
-
let children = fn;
|
|
209
|
-
for (let i = 0; i < contexts.length; i++) {
|
|
210
|
-
const [context, value] = contexts[i];
|
|
211
|
-
children = context.ProviderStc({
|
|
212
|
-
value
|
|
213
|
-
}).children(children);
|
|
214
|
-
}
|
|
215
|
-
renderTree(children);
|
|
216
|
-
}
|
|
217
68
|
describe("Symbol#delete", () => {
|
|
218
69
|
it("deletes from parent scope", () => {
|
|
219
|
-
const scope =
|
|
220
|
-
|
|
221
|
-
});
|
|
222
|
-
const symbol = new OutputSymbol("sym", {
|
|
223
|
-
binder,
|
|
224
|
-
scope
|
|
225
|
-
});
|
|
70
|
+
const scope = createScope("parent");
|
|
71
|
+
const [symbol] = createSymbol("sym", scope);
|
|
226
72
|
expect(scope.symbols.has(symbol)).toBe(true);
|
|
227
73
|
symbol.delete();
|
|
228
74
|
expect(scope.symbols.has(symbol)).toBe(false);
|
|
229
75
|
});
|
|
230
|
-
it("updates resolution");
|
|
231
76
|
});
|
|
232
|
-
describe("OutputSymbol#
|
|
233
|
-
it("copies
|
|
234
|
-
const scope =
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
const
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
expect(
|
|
77
|
+
describe("OutputSymbol#copy", () => {
|
|
78
|
+
it("copies name, flags", () => {
|
|
79
|
+
const scope = createScope("scope");
|
|
80
|
+
const [symbol] = createSymbol("sym", scope, {
|
|
81
|
+
transient: true
|
|
82
|
+
});
|
|
83
|
+
const copy = symbol.copy();
|
|
84
|
+
expect(copy.name).toEqual("sym");
|
|
85
|
+
expect(copy.isTransient).toBe(true);
|
|
86
|
+
expect(copy.scope).toBeUndefined();
|
|
87
|
+
});
|
|
88
|
+
it("reactively copies name from the original symbol", () => {
|
|
89
|
+
const scope = createScope("scope");
|
|
90
|
+
const [symbol] = createSymbol("sym", scope);
|
|
91
|
+
const copy = symbol.copy();
|
|
92
|
+
expect(copy.name).toEqual("sym");
|
|
93
|
+
expect(copy.scope).toBeUndefined();
|
|
248
94
|
symbol.name = "bar";
|
|
249
|
-
symbol.flags = OutputSymbolFlags.InstanceMemberContainer;
|
|
250
95
|
flushJobs();
|
|
251
|
-
expect(
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
const
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
const
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
const
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
expect(
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
binder
|
|
279
|
-
});
|
|
280
|
-
const symbol = new OutputSymbol("sym", {
|
|
281
|
-
binder,
|
|
282
|
-
scope,
|
|
283
|
-
flags: OutputSymbolFlags.MemberContainer
|
|
284
|
-
});
|
|
285
|
-
const sourceStaticMember = new OutputSymbol("static-member", {
|
|
286
|
-
binder,
|
|
287
|
-
scope: symbol.staticMemberScope,
|
|
288
|
-
flags: OutputSymbolFlags.StaticMemberContainer
|
|
289
|
-
});
|
|
290
|
-
const sourceInstanceMember = new OutputSymbol("instance-member", {
|
|
291
|
-
binder,
|
|
292
|
-
scope: symbol.instanceMemberScope
|
|
293
|
-
});
|
|
294
|
-
const scope2 = new OutputScope("scope2", {
|
|
295
|
-
binder
|
|
296
|
-
});
|
|
297
|
-
const clone = symbol.copyToScope(scope2);
|
|
298
|
-
expect(clone.instanceMemberScope).toBeDefined();
|
|
299
|
-
expect(clone.staticMemberScope).toBeDefined();
|
|
300
|
-
const clonedStaticMember = [...clone.staticMemberScope.symbols][0];
|
|
301
|
-
expect(clonedStaticMember.name).toBe("static-member");
|
|
302
|
-
expect(clonedStaticMember).toBeDefined();
|
|
303
|
-
expect(clonedStaticMember.flags).toBe(sourceStaticMember.flags);
|
|
304
|
-
const clonedInstanceMember = [...clone.instanceMemberScope.symbols][0];
|
|
305
|
-
expect(clonedInstanceMember.name).toBe("instance-member");
|
|
306
|
-
expect(clonedInstanceMember).toBeDefined();
|
|
307
|
-
expect(clonedInstanceMember.flags).toBe(sourceInstanceMember.flags);
|
|
308
|
-
expect(clonedInstanceMember.staticMemberScope).toBeUndefined();
|
|
309
|
-
|
|
310
|
-
// test reactivity
|
|
311
|
-
const newStaticSym = new OutputSymbol("new-sym", {
|
|
312
|
-
binder,
|
|
313
|
-
scope: symbol.staticMemberScope
|
|
314
|
-
});
|
|
315
|
-
const newInstanceSym = new OutputSymbol("new-sym", {
|
|
316
|
-
binder,
|
|
317
|
-
scope: symbol.instanceMemberScope
|
|
318
|
-
});
|
|
96
|
+
expect(copy.name).toEqual("bar");
|
|
97
|
+
});
|
|
98
|
+
it("copies member symbols", () => {
|
|
99
|
+
const scope = createScope("scope");
|
|
100
|
+
const [symbol] = createSymbol("sym", scope);
|
|
101
|
+
createSymbol("static-member", symbol.staticMembers);
|
|
102
|
+
createSymbol("instance-member", symbol.instanceMembers);
|
|
103
|
+
const copy = symbol.copy();
|
|
104
|
+
expect(copy.name).toEqual("sym");
|
|
105
|
+
expect(copy.staticMembers.size).toBe(1);
|
|
106
|
+
const staticMemberCopy = [...copy.staticMembers][0];
|
|
107
|
+
expect(staticMemberCopy.name).toBe("static-member");
|
|
108
|
+
expect(copy.instanceMembers.size).toBe(1);
|
|
109
|
+
const instanceMemberCopy = [...copy.instanceMembers][0];
|
|
110
|
+
expect(instanceMemberCopy.name).toBe("instance-member");
|
|
111
|
+
});
|
|
112
|
+
it("copies member symbols reactively", () => {
|
|
113
|
+
const scope = createScope("scope");
|
|
114
|
+
const [symbol] = createSymbol("sym", scope);
|
|
115
|
+
const [staticMember] = createSymbol("static-member", symbol.staticMembers);
|
|
116
|
+
createSymbol("instance-member", symbol.instanceMembers);
|
|
117
|
+
const copy = symbol.copy();
|
|
118
|
+
expect(copy.name).toEqual("sym");
|
|
119
|
+
expect(copy.staticMembers.size).toBe(1);
|
|
120
|
+
const staticMemberCopy = [...copy.staticMembers][0];
|
|
121
|
+
const [newStaticMember] = createSymbol("static-member-2", symbol.staticMembers);
|
|
122
|
+
staticMember.name = "hi";
|
|
319
123
|
flushJobs();
|
|
320
|
-
|
|
321
|
-
expect(
|
|
322
|
-
|
|
323
|
-
|
|
124
|
+
const secondStaticMemberCopy = [...copy.staticMembers][1];
|
|
125
|
+
expect(secondStaticMemberCopy.name).toBe("static-member-2");
|
|
126
|
+
expect(staticMemberCopy.name).toBe("hi");
|
|
127
|
+
newStaticMember.delete();
|
|
324
128
|
flushJobs();
|
|
325
|
-
expect(
|
|
326
|
-
expect(
|
|
129
|
+
expect(copy.staticMembers.size).toBe(1);
|
|
130
|
+
expect(copy.staticMembers.symbolNames.has("static-member-2")).toBe(false);
|
|
131
|
+
expect(copy.staticMembers.symbolNames.has("hi")).toBe(true);
|
|
327
132
|
});
|
|
328
133
|
});
|
|
329
|
-
describe("
|
|
330
|
-
it("
|
|
331
|
-
const
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
expect(
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
const
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
});
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
expect(
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
});
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
scope: classSym.instanceMemberScope,
|
|
396
|
-
flags: OutputSymbolFlags.StaticMemberContainer
|
|
397
|
-
});
|
|
398
|
-
new OutputSymbol("static-of-instance", {
|
|
399
|
-
binder,
|
|
400
|
-
scope: instanceMemberSym.staticMemberScope
|
|
401
|
-
});
|
|
402
|
-
const targetSym = new OutputSymbol("Target", {
|
|
403
|
-
binder,
|
|
404
|
-
scope
|
|
405
|
-
});
|
|
406
|
-
classSym.instantiateTo(targetSym);
|
|
407
|
-
expect(targetSym.staticMemberScope.symbolNames.has("instance-member")).toBeTruthy();
|
|
408
|
-
expect(targetSym.instanceMemberScope).toBeUndefined();
|
|
409
|
-
const instantiatedSS = [...targetSym.staticMemberScope.symbols][0];
|
|
410
|
-
expect(instantiatedSS.staticMemberScope).toBeDefined();
|
|
411
|
-
expect(instantiatedSS.staticMemberScope.symbolNames.has("static-of-instance")).toBeTruthy();
|
|
412
|
-
|
|
413
|
-
// check reactivity
|
|
414
|
-
const newSym = new OutputSymbol("new-static-of-instance", {
|
|
415
|
-
binder,
|
|
416
|
-
scope: instanceMemberSym.staticMemberScope
|
|
417
|
-
});
|
|
418
|
-
flushJobs();
|
|
419
|
-
expect(instantiatedSS.staticMemberScope.symbolNames.has("new-static-of-instance")).toBeTruthy();
|
|
420
|
-
newSym.delete();
|
|
421
|
-
flushJobs();
|
|
422
|
-
expect(instantiatedSS.staticMemberScope.symbolNames.has("static-member-2")).toBeFalsy();
|
|
423
|
-
});
|
|
424
|
-
it("is idempotent", () => {
|
|
425
|
-
const scope = new OutputScope("scope", {
|
|
426
|
-
binder
|
|
427
|
-
});
|
|
428
|
-
const source = new OutputSymbol("sym", {
|
|
429
|
-
binder,
|
|
430
|
-
scope,
|
|
431
|
-
flags: OutputSymbolFlags.InstanceMemberContainer
|
|
432
|
-
});
|
|
433
|
-
new OutputSymbol("instance-member", {
|
|
434
|
-
binder,
|
|
435
|
-
scope: source.instanceMemberScope
|
|
436
|
-
});
|
|
437
|
-
const target = new OutputSymbol("target", {
|
|
438
|
-
binder,
|
|
439
|
-
scope
|
|
440
|
-
});
|
|
441
|
-
source.instantiateTo(target);
|
|
442
|
-
source.instantiateTo(target);
|
|
443
|
-
expect(target.staticMemberScope).toBeDefined();
|
|
444
|
-
expect(target.staticMemberScope.symbolNames.size).toEqual(1);
|
|
445
|
-
expect(target.staticMemberScope.symbolNames.has("instance-member")).toBe(true);
|
|
134
|
+
describe("Output symbol name", () => {
|
|
135
|
+
it("intializes with a namekey", () => {
|
|
136
|
+
const nk = namekey("foo");
|
|
137
|
+
const scope = createScope("scope");
|
|
138
|
+
const [symbol] = createSymbol(nk, scope);
|
|
139
|
+
expect(symbol.name).toBe("foo");
|
|
140
|
+
expect(binder.getSymbolForRefkey(nk).value).toBe(symbol);
|
|
141
|
+
});
|
|
142
|
+
it("applies name policy", () => {
|
|
143
|
+
const scope = createScope("scope");
|
|
144
|
+
const [symbol] = createSymbol("foo", scope, {
|
|
145
|
+
namePolicy: name => `_${name}_`
|
|
146
|
+
});
|
|
147
|
+
expect(symbol.name).toBe("_foo_");
|
|
148
|
+
});
|
|
149
|
+
it("ignores name policy with namekey option", () => {
|
|
150
|
+
const nk = namekey("foo", {
|
|
151
|
+
ignoreNamePolicy: true
|
|
152
|
+
});
|
|
153
|
+
const scope = createScope("scope");
|
|
154
|
+
const [symbol] = createSymbol(nk, scope, {
|
|
155
|
+
namePolicy: name => `_${name}_`
|
|
156
|
+
});
|
|
157
|
+
expect(symbol.name).toBe("foo");
|
|
158
|
+
expect(symbol.ignoreNamePolicy).toBe(true);
|
|
159
|
+
});
|
|
160
|
+
it("ignores name policy with symbol option", () => {
|
|
161
|
+
const scope = createScope("scope");
|
|
162
|
+
const [symbol] = createSymbol("foo", scope, {
|
|
163
|
+
ignoreNamePolicy: true,
|
|
164
|
+
namePolicy: name => `_${name}_`
|
|
165
|
+
});
|
|
166
|
+
expect(symbol.name).toBe("foo");
|
|
167
|
+
expect(symbol.ignoreNamePolicy).toBe(true);
|
|
168
|
+
});
|
|
169
|
+
it("handles name conflicts with a default name conflict policy", async () => {
|
|
170
|
+
const scope = createScope("scope");
|
|
171
|
+
const [symbol1] = createSymbol("foo", scope);
|
|
172
|
+
const [symbol2] = createSymbol("foo", scope);
|
|
173
|
+
await flushJobs();
|
|
174
|
+
expect(symbol1.name).toBe("foo");
|
|
175
|
+
expect(symbol2.name).toBe("foo_2");
|
|
176
|
+
});
|
|
177
|
+
it("ignores name conflicts with namekey option", () => {
|
|
178
|
+
const nk1 = namekey("foo", {
|
|
179
|
+
ignoreNameConflict: true
|
|
180
|
+
});
|
|
181
|
+
const nk2 = namekey("foo", {
|
|
182
|
+
ignoreNameConflict: true
|
|
183
|
+
});
|
|
184
|
+
const scope = createScope("scope");
|
|
185
|
+
const [symbol1] = createSymbol(nk1, scope);
|
|
186
|
+
const [symbol2] = createSymbol(nk2, scope);
|
|
187
|
+
expect(symbol1.name).toBe("foo");
|
|
188
|
+
expect(symbol2.name).toBe("foo");
|
|
189
|
+
});
|
|
190
|
+
it("ignores name conflicts with symbol option", () => {
|
|
191
|
+
const scope = createScope("scope");
|
|
192
|
+
const [symbol1] = createSymbol("foo", scope, {
|
|
193
|
+
ignoreNameConflict: true
|
|
194
|
+
});
|
|
195
|
+
const [symbol2] = createSymbol("foo", scope, {
|
|
196
|
+
ignoreNameConflict: true
|
|
197
|
+
});
|
|
198
|
+
expect(symbol1.name).toBe("foo");
|
|
199
|
+
expect(symbol2.name).toBe("foo");
|
|
446
200
|
});
|
|
447
201
|
});
|