@alloy-js/core 0.20.0-dev.3 → 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/src/utils.d.ts +1 -1
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +4 -4
- package/dist/src/write-output.d.ts +1 -1
- package/dist/src/write-output.d.ts.map +1 -1
- package/dist/src/write-output.js +31 -37
- 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/src/utils.tsx +4 -4
- package/src/write-output.ts +33 -45
- package/temp/api.json +5551 -3066
- 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
package/dist/src/write-output.js
CHANGED
|
@@ -6,47 +6,41 @@ import { traverseOutput } from "./utils.js";
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
export async function writeOutput(output, basePath = "") {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
return await traverseOutput(output, {
|
|
10
|
+
async visitDirectory(directory) {
|
|
11
|
+
const path = resolve(basePath, directory.path);
|
|
12
|
+
if (await AlloyHost.exists(path)) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
// eslint-disable-next-line no-console
|
|
16
|
+
console.log("create", relative(process.cwd(), path));
|
|
17
|
+
await AlloyHost.mkdir(path);
|
|
18
|
+
},
|
|
19
|
+
async visitFile(file) {
|
|
20
|
+
if ("contents" in file) {
|
|
21
|
+
const path = resolve(basePath, file.path);
|
|
14
22
|
if (await AlloyHost.exists(path)) {
|
|
15
|
-
|
|
23
|
+
// eslint-disable-next-line no-console
|
|
24
|
+
console.log("overwrite", relative(process.cwd(), path));
|
|
25
|
+
} else {
|
|
26
|
+
// eslint-disable-next-line no-console
|
|
27
|
+
console.log("create", relative(process.cwd(), path));
|
|
16
28
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const path = resolve(basePath, file.path);
|
|
26
|
-
if (await AlloyHost.exists(path)) {
|
|
27
|
-
// eslint-disable-next-line no-console
|
|
28
|
-
console.log("overwrite", relative(process.cwd(), path));
|
|
29
|
-
} else {
|
|
30
|
-
// eslint-disable-next-line no-console
|
|
31
|
-
console.log("create", relative(process.cwd(), path));
|
|
32
|
-
}
|
|
33
|
-
await AlloyHost.write(path, file.contents);
|
|
29
|
+
await AlloyHost.write(path, file.contents);
|
|
30
|
+
} else {
|
|
31
|
+
// copy file
|
|
32
|
+
const source = resolve(basePath, file.sourcePath);
|
|
33
|
+
const target = resolve(basePath, file.path);
|
|
34
|
+
if (await AlloyHost.exists(target)) {
|
|
35
|
+
// eslint-disable-next-line no-console
|
|
36
|
+
console.log("copy over", relative(process.cwd(), target));
|
|
34
37
|
} else {
|
|
35
|
-
//
|
|
36
|
-
|
|
37
|
-
const target = resolve(basePath, file.path);
|
|
38
|
-
if (await AlloyHost.exists(target)) {
|
|
39
|
-
// eslint-disable-next-line no-console
|
|
40
|
-
console.log("copy over", relative(process.cwd(), target));
|
|
41
|
-
} else {
|
|
42
|
-
// eslint-disable-next-line no-console
|
|
43
|
-
console.log("copy", relative(process.cwd(), target));
|
|
44
|
-
}
|
|
45
|
-
await AlloyHost.mkdir(dirname(target));
|
|
46
|
-
await AlloyHost.write(target, AlloyHost.read(source).stream());
|
|
38
|
+
// eslint-disable-next-line no-console
|
|
39
|
+
console.log("copy", relative(process.cwd(), target));
|
|
47
40
|
}
|
|
48
|
-
|
|
41
|
+
await AlloyHost.mkdir(dirname(target));
|
|
42
|
+
await AlloyHost.write(target, AlloyHost.read(source).stream());
|
|
43
|
+
}
|
|
49
44
|
}
|
|
50
45
|
});
|
|
51
|
-
return Promise.all(ops);
|
|
52
46
|
}
|
|
@@ -1,32 +1,27 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { memo as _$memo, createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
2
|
import { expect, it } from "vitest";
|
|
3
3
|
import { Output } from "../../src/components/Output.js";
|
|
4
|
-
import { Declaration, ref, renderTree, Scope
|
|
4
|
+
import { Declaration, ref, renderTree, Scope } from "../../src/index.js";
|
|
5
5
|
import { flushJobs } from "../../src/scheduler.js";
|
|
6
|
-
import {
|
|
6
|
+
import { BasicScope } from "../../src/symbols/basic-scope.js";
|
|
7
7
|
it("creates and cleans up a symbol", () => {
|
|
8
|
-
const GetBinder = createTap(() => {
|
|
9
|
-
return useBinder();
|
|
10
|
-
});
|
|
11
|
-
const binderRef = GetBinder.ref;
|
|
12
8
|
const doDecl = ref(true);
|
|
9
|
+
const scope = new BasicScope("test", undefined);
|
|
13
10
|
const template = _$createComponent(Output, {
|
|
14
11
|
get children() {
|
|
15
|
-
return
|
|
16
|
-
|
|
12
|
+
return _$createComponent(Scope, {
|
|
13
|
+
value: scope,
|
|
17
14
|
get children() {
|
|
18
15
|
return _$memo(() => !!doDecl.value)() ? _$createComponent(Declaration, {
|
|
19
16
|
name: "foo"
|
|
20
17
|
}) : "";
|
|
21
18
|
}
|
|
22
|
-
})
|
|
19
|
+
});
|
|
23
20
|
}
|
|
24
21
|
});
|
|
25
22
|
renderTree(template);
|
|
26
|
-
|
|
27
|
-
const subScope = [...binder.globalScope.children][0];
|
|
28
|
-
expect(subScope.symbols.size).toBe(1);
|
|
23
|
+
expect(scope.symbols.size).toBe(1);
|
|
29
24
|
doDecl.value = false;
|
|
30
25
|
flushJobs();
|
|
31
|
-
expect(
|
|
26
|
+
expect(scope.symbols.size).toBe(0);
|
|
32
27
|
});
|
|
@@ -6,7 +6,7 @@ function TestWrapper(props) {
|
|
|
6
6
|
const GetBinder = createTap(() => useBinder());
|
|
7
7
|
function Reference(props) {
|
|
8
8
|
const result = resolve(props.refkey);
|
|
9
|
-
return result.value.
|
|
9
|
+
return result.value.symbol.name;
|
|
10
10
|
}
|
|
11
11
|
return _$createComponent(Output, {
|
|
12
12
|
get children() {
|
|
@@ -112,7 +112,7 @@ it("resolve ref via source file reference", () => {
|
|
|
112
112
|
const GetBinder = createTap(() => useBinder());
|
|
113
113
|
const Reference = vi.fn(props => {
|
|
114
114
|
const result = resolve(props.refkey);
|
|
115
|
-
return `ViaRef.${result.value.
|
|
115
|
+
return `ViaRef.${result.value.symbol.name}`;
|
|
116
116
|
});
|
|
117
117
|
const template = _$createComponent(Output, {
|
|
118
118
|
get children() {
|
|
@@ -1,48 +1,30 @@
|
|
|
1
1
|
import { reactive, watch } from "@vue/reactivity";
|
|
2
|
-
import {
|
|
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 {
|
|
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
|
-
|
|
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 =
|
|
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 =
|
|
32
|
-
binder
|
|
33
|
-
});
|
|
19
|
+
const parentScope = createScope("parentScope");
|
|
34
20
|
const metadata = {
|
|
35
21
|
foo: "bar"
|
|
36
22
|
};
|
|
37
|
-
const scope = new
|
|
23
|
+
const scope = new BasicScope("testScope", parentScope, {
|
|
38
24
|
binder,
|
|
39
|
-
|
|
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 =
|
|
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 =
|
|
76
|
-
binder
|
|
77
|
-
});
|
|
44
|
+
const scope = createScope("scope");
|
|
78
45
|
const symbolNamesSpy = vi.fn();
|
|
79
46
|
watch(() => scope.symbolNames.size, symbolNamesSpy);
|
|
80
|
-
|
|
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 =
|
|
90
|
-
|
|
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 =
|
|
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 =
|
|
131
|
-
|
|
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 =
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
const
|
|
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 =
|
|
172
|
-
|
|
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 =
|
|
190
|
-
|
|
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.
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
246
|
-
|
|
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
|
});
|