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