@alloy-js/core 0.16.0 → 0.18.0-dev.2
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/CHANGELOG.md +15 -0
- package/dist/src/binder.d.ts +19 -235
- package/dist/src/binder.d.ts.map +1 -1
- package/dist/src/binder.js +85 -386
- package/dist/src/code.d.ts +1 -1
- package/dist/src/code.d.ts.map +1 -1
- package/dist/src/components/Block.d.ts +1 -1
- package/dist/src/components/Block.d.ts.map +1 -1
- package/dist/src/components/Block.js +3 -1
- 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 +6 -5
- package/dist/src/components/For.d.ts +1 -1
- package/dist/src/components/For.d.ts.map +1 -1
- package/dist/src/components/For.js +1 -1
- package/dist/src/components/Indent.d.ts +1 -1
- package/dist/src/components/Indent.d.ts.map +1 -1
- package/dist/src/components/List.d.ts +1 -1
- package/dist/src/components/List.d.ts.map +1 -1
- package/dist/src/components/List.js +3 -1
- package/dist/src/components/MemberDeclaration.d.ts +3 -3
- package/dist/src/components/MemberDeclaration.d.ts.map +1 -1
- package/dist/src/components/MemberDeclaration.js +4 -4
- package/dist/src/components/MemberScope.d.ts +2 -2
- package/dist/src/components/MemberScope.d.ts.map +1 -1
- package/dist/src/components/MemberScope.js +0 -2
- package/dist/src/components/Output.d.ts +1 -1
- package/dist/src/components/Output.d.ts.map +1 -1
- package/dist/src/components/Output.js +1 -1
- package/dist/src/components/Prose.d.ts +1 -1
- package/dist/src/components/Prose.d.ts.map +1 -1
- 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 +2 -2
- package/dist/src/components/Scope.d.ts.map +1 -1
- package/dist/src/components/Scope.js +3 -6
- package/dist/src/components/Show.d.ts +1 -1
- package/dist/src/components/Show.d.ts.map +1 -1
- package/dist/src/components/SourceDirectory.d.ts +1 -1
- package/dist/src/components/SourceDirectory.d.ts.map +1 -1
- package/dist/src/components/SourceDirectory.js +1 -1
- package/dist/src/components/SourceFile.d.ts +1 -1
- package/dist/src/components/SourceFile.d.ts.map +1 -1
- package/dist/src/components/SourceFile.js +1 -1
- package/dist/src/components/StatementList.d.ts +1 -1
- package/dist/src/components/StatementList.d.ts.map +1 -1
- package/dist/src/components/StatementList.js +1 -1
- package/dist/src/components/Switch.d.ts +2 -2
- package/dist/src/components/Switch.d.ts.map +1 -1
- package/dist/src/components/Switch.js +2 -1
- package/dist/src/components/Wrap.d.ts +1 -1
- package/dist/src/components/Wrap.d.ts.map +1 -1
- package/dist/src/context/assignment.d.ts +1 -1
- package/dist/src/context/assignment.d.ts.map +1 -1
- package/dist/src/context/binder.d.ts +3 -3
- package/dist/src/context/binder.d.ts.map +1 -1
- package/dist/src/context/declaration.d.ts +1 -1
- package/dist/src/context/declaration.d.ts.map +1 -1
- package/dist/src/context/member-declaration.d.ts +1 -1
- package/dist/src/context/member-declaration.d.ts.map +1 -1
- package/dist/src/context/member-declaration.js +0 -1
- package/dist/src/context/member-scope.d.ts +1 -1
- package/dist/src/context/member-scope.d.ts.map +1 -1
- package/dist/src/context/name-policy.d.ts +1 -1
- package/dist/src/context/name-policy.d.ts.map +1 -1
- package/dist/src/context/scope.d.ts +1 -1
- package/dist/src/context/scope.d.ts.map +1 -1
- package/dist/src/context/source-directory.d.ts +1 -1
- package/dist/src/context/source-directory.d.ts.map +1 -1
- package/dist/src/context/source-file.d.ts +2 -2
- package/dist/src/context/source-file.d.ts.map +1 -1
- package/dist/src/context.d.ts +2 -2
- package/dist/src/context.d.ts.map +1 -1
- package/dist/src/context.js +1 -1
- package/dist/src/debug.d.ts +1 -0
- package/dist/src/debug.d.ts.map +1 -1
- package/dist/src/debug.js +4 -1
- package/dist/src/index.d.ts +8 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +8 -2
- package/dist/src/jsx-runtime.d.ts +4 -272
- package/dist/src/jsx-runtime.d.ts.map +1 -1
- package/dist/src/jsx-runtime.js +3 -315
- package/dist/src/props-combinators.d.ts +19 -0
- package/dist/src/props-combinators.d.ts.map +1 -0
- package/dist/src/props-combinators.js +108 -0
- package/dist/src/reactive-union-set.d.ts +29 -0
- package/dist/src/reactive-union-set.d.ts.map +1 -0
- package/dist/src/reactive-union-set.js +183 -0
- package/dist/src/reactivity.d.ts +75 -0
- package/dist/src/reactivity.d.ts.map +1 -0
- package/dist/src/reactivity.js +141 -0
- package/dist/src/refkey.d.ts +36 -0
- package/dist/src/refkey.d.ts.map +1 -1
- package/dist/src/refkey.js +40 -0
- package/dist/src/render.d.ts +5 -1
- package/dist/src/render.d.ts.map +1 -1
- package/dist/src/render.js +68 -15
- package/dist/src/runtime/component.d.ts +24 -0
- package/dist/src/runtime/component.d.ts.map +1 -0
- package/dist/src/runtime/component.js +19 -0
- package/dist/src/runtime/intrinsic.d.ts +168 -0
- package/dist/src/runtime/intrinsic.d.ts.map +1 -0
- package/dist/src/runtime/intrinsic.js +11 -0
- package/dist/src/scheduler.d.ts +2 -2
- package/dist/src/scheduler.d.ts.map +1 -1
- package/dist/src/scheduler.js +27 -6
- package/dist/src/slot.d.ts +2 -2
- package/dist/src/slot.d.ts.map +1 -1
- package/dist/src/slot.js +1 -1
- package/dist/src/stc.d.ts +1 -1
- package/dist/src/stc.d.ts.map +1 -1
- package/dist/src/sti.d.ts +7 -6
- package/dist/src/sti.d.ts.map +1 -1
- package/dist/src/sti.js +1 -1
- package/dist/src/symbols/flags.d.ts +70 -0
- package/dist/src/symbols/flags.d.ts.map +1 -0
- package/dist/src/symbols/flags.js +72 -0
- package/dist/src/symbols/index.d.ts +7 -0
- package/dist/src/symbols/index.d.ts.map +1 -0
- package/dist/src/symbols/index.js +6 -0
- package/dist/src/symbols/output-scope.d.ts +94 -0
- package/dist/src/symbols/output-scope.d.ts.map +1 -0
- package/dist/src/symbols/output-scope.js +222 -0
- package/dist/src/symbols/output-symbol.d.ts +89 -0
- package/dist/src/symbols/output-symbol.d.ts.map +1 -0
- package/dist/src/symbols/output-symbol.js +333 -0
- package/dist/src/symbols/symbol-flow.d.ts +13 -0
- package/dist/src/symbols/symbol-flow.d.ts.map +1 -0
- package/dist/src/symbols/symbol-flow.js +74 -0
- package/dist/src/symbols/symbol-slot.d.ts +12 -0
- package/dist/src/symbols/symbol-slot.d.ts.map +1 -0
- package/dist/src/symbols/symbol-slot.js +36 -0
- package/dist/src/symbols/symbol-table.d.ts +14 -0
- package/dist/src/symbols/symbol-table.d.ts.map +1 -0
- package/dist/src/symbols/symbol-table.js +42 -0
- package/dist/src/tap.d.ts +3 -2
- package/dist/src/tap.d.ts.map +1 -1
- package/dist/src/tracer.d.ts +238 -0
- package/dist/src/tracer.d.ts.map +1 -0
- package/dist/src/tracer.js +496 -0
- package/dist/src/tsdoc-metadata.json +1 -1
- package/dist/src/utils.d.ts +4 -3
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +2 -1
- package/dist/test/components/slot.test.js +5 -7
- package/dist/test/props-with-defaults.test.js +1 -1
- package/dist/test/reactive-union-set.test.d.ts +2 -0
- package/dist/test/reactive-union-set.test.d.ts.map +1 -0
- package/dist/test/reactive-union-set.test.js +170 -0
- package/dist/test/reactivity/cleanup.test.js +2 -1
- package/dist/test/reactivity/memo.test.js +1 -1
- package/dist/test/reactivity/untrack.test.js +1 -1
- package/dist/test/rendering/memoization.test.js +2 -1
- package/dist/test/split-props.test.js +1 -1
- package/dist/test/symbols/output-scope.test.d.ts +2 -0
- package/dist/test/symbols/output-scope.test.d.ts.map +1 -0
- package/dist/test/symbols/output-scope.test.js +343 -0
- package/dist/test/symbols/output-symbol.test.d.ts +2 -0
- package/dist/test/symbols/output-symbol.test.d.ts.map +1 -0
- package/dist/test/symbols/output-symbol.test.js +447 -0
- package/dist/test/symbols/resolution.test.d.ts +2 -0
- package/dist/test/symbols/resolution.test.d.ts.map +1 -0
- package/dist/test/symbols/resolution.test.js +141 -0
- package/dist/test/symbols/utils.d.ts +25 -0
- package/dist/test/symbols/utils.d.ts.map +1 -0
- package/dist/test/symbols/utils.js +47 -0
- package/dist/testing/extend-expect.d.ts +15 -0
- package/dist/testing/extend-expect.d.ts.map +1 -1
- package/dist/testing/extend-expect.js +2 -1
- package/dist/testing/render.d.ts +1 -1
- package/dist/testing/render.d.ts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +28 -24
- package/src/binder.ts +146 -672
- package/src/code.ts +1 -1
- package/src/components/Block.tsx +4 -1
- package/src/components/Declaration.tsx +8 -7
- package/src/components/For.tsx +2 -1
- package/src/components/Indent.tsx +1 -1
- package/src/components/List.tsx +3 -1
- package/src/components/MemberDeclaration.tsx +7 -6
- package/src/components/MemberScope.tsx +2 -5
- package/src/components/Output.tsx +2 -1
- package/src/components/Prose.tsx +1 -1
- package/src/components/ReferenceOrContent.tsx +1 -1
- package/src/components/Scope.tsx +3 -7
- package/src/components/Show.tsx +1 -1
- package/src/components/SourceDirectory.tsx +2 -1
- package/src/components/SourceFile.tsx +2 -1
- package/src/components/StatementList.tsx +2 -1
- package/src/components/Switch.tsx +2 -1
- package/src/components/Wrap.tsx +1 -1
- package/src/context/assignment.ts +1 -1
- package/src/context/binder.ts +3 -3
- package/src/context/declaration.ts +1 -1
- package/src/context/member-declaration.ts +1 -1
- package/src/context/member-scope.ts +1 -1
- package/src/context/name-policy.ts +1 -1
- package/src/context/scope.ts +1 -1
- package/src/context/source-directory.ts +1 -1
- package/src/context/source-file.ts +2 -2
- package/src/context.ts +3 -7
- package/src/debug.ts +5 -1
- package/src/index.ts +15 -1
- package/src/jsx-runtime.ts +15 -674
- package/src/props-combinators.ts +148 -0
- package/src/reactive-union-set.ts +238 -0
- package/src/reactivity.ts +230 -0
- package/src/refkey.ts +40 -0
- package/src/render.ts +97 -26
- package/src/runtime/component.ts +67 -0
- package/src/runtime/intrinsic.ts +199 -0
- package/src/scheduler.ts +31 -6
- package/src/slot.ts +3 -4
- package/src/stc.ts +2 -2
- package/src/sti.ts +11 -11
- package/src/symbols/flags.ts +82 -0
- package/src/symbols/index.ts +6 -0
- package/src/symbols/output-scope.ts +296 -0
- package/src/symbols/output-symbol.ts +459 -0
- package/src/symbols/symbol-flow.ts +100 -0
- package/src/symbols/symbol-slot.tsx +48 -0
- package/src/symbols/symbol-table.ts +72 -0
- package/src/tap.ts +3 -2
- package/src/tracer.ts +474 -0
- package/src/utils.tsx +7 -5
- package/temp/api.json +7446 -5133
- package/test/components/slot.test.tsx +8 -11
- package/test/props-with-defaults.test.ts +1 -1
- package/test/reactive-union-set.test.tsx +191 -0
- package/test/reactivity/cleanup.test.tsx +2 -1
- package/test/reactivity/memo.test.tsx +1 -1
- package/test/reactivity/untrack.test.ts +1 -1
- package/test/rendering/basic.test.tsx +1 -1
- package/test/rendering/memoization.test.tsx +1 -1
- package/test/split-props.test.ts +1 -1
- package/test/symbols/output-scope.test.ts +300 -0
- package/test/symbols/output-symbol.test.ts +456 -0
- package/test/symbols/resolution.test.ts +170 -0
- package/test/symbols/utils.ts +93 -0
- package/test/utils.test.tsx +1 -1
- package/testing/extend-expect.ts +16 -0
- package/testing/render.ts +1 -2
- package/LICENSE +0 -7
- package/dist/test/symbols.test.d.ts +0 -2
- package/dist/test/symbols.test.d.ts.map +0 -1
- package/dist/test/symbols.test.js +0 -884
- package/test/symbols.test.ts +0 -1006
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
import {
|
|
2
|
+
reactive,
|
|
3
|
+
ReactiveFlags,
|
|
4
|
+
shallowReactive,
|
|
5
|
+
track,
|
|
6
|
+
TrackOpTypes,
|
|
7
|
+
trigger,
|
|
8
|
+
TriggerOpTypes,
|
|
9
|
+
watch,
|
|
10
|
+
} from "@vue/reactivity";
|
|
11
|
+
import type { Binder } from "../binder.js";
|
|
12
|
+
import { useBinder } from "../context/binder.js";
|
|
13
|
+
import { useScope } from "../context/scope.js";
|
|
14
|
+
import type { ReactiveUnionSetOptions } from "../reactive-union-set.js";
|
|
15
|
+
import type { Refkey } from "../refkey.js";
|
|
16
|
+
import {
|
|
17
|
+
formatScope,
|
|
18
|
+
formatScopeName,
|
|
19
|
+
trace,
|
|
20
|
+
traceEffect,
|
|
21
|
+
TracePhase,
|
|
22
|
+
} from "../tracer.js";
|
|
23
|
+
import { OutputScopeFlags } from "./flags.js";
|
|
24
|
+
import type { OutputSymbol } from "./output-symbol.js";
|
|
25
|
+
import { SymbolTable } from "./symbol-table.js";
|
|
26
|
+
|
|
27
|
+
let scopeCount = 0;
|
|
28
|
+
|
|
29
|
+
export interface OutputScopeOptions {
|
|
30
|
+
flags?: OutputScopeFlags;
|
|
31
|
+
kind?: string;
|
|
32
|
+
metadata?: Record<string, unknown>;
|
|
33
|
+
parent?: OutputScope;
|
|
34
|
+
owner?: OutputSymbol;
|
|
35
|
+
binder?: Binder;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* A container of symbols accessible within some scope in your output code.
|
|
40
|
+
*
|
|
41
|
+
* @remarks
|
|
42
|
+
*
|
|
43
|
+
* Scopes form a tree. All scopes except the global scope have a parent scope
|
|
44
|
+
* identified by `parent`. Scopes can have nested scopes which can be accessed
|
|
45
|
+
* using the `children` property. Whether a child scope can be accessed from
|
|
46
|
+
* the parent scope is determined by each language's scoping rules.
|
|
47
|
+
*
|
|
48
|
+
* This interface is the base implementation of scope. Generally, most languages
|
|
49
|
+
* will have subtypes of this interface that provide additional metadata about
|
|
50
|
+
* the scope. For example, TypeScript scopes need to track whether the scope
|
|
51
|
+
* represents a package, module, class, function, etc.
|
|
52
|
+
*
|
|
53
|
+
* Scopes are reactive values, which allows you to observe changes to the scope
|
|
54
|
+
* within a reactive context.
|
|
55
|
+
*/
|
|
56
|
+
export class OutputScope {
|
|
57
|
+
// my kingdom for decorators
|
|
58
|
+
#name: string;
|
|
59
|
+
/**
|
|
60
|
+
* The name of the scope.
|
|
61
|
+
*/
|
|
62
|
+
get name() {
|
|
63
|
+
track(this, TrackOpTypes.GET, "name");
|
|
64
|
+
return this.#name;
|
|
65
|
+
}
|
|
66
|
+
set name(name: string) {
|
|
67
|
+
const old = this.#name;
|
|
68
|
+
this.#name = name;
|
|
69
|
+
trigger(this, TriggerOpTypes.SET, "name", name, old);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
#id: number;
|
|
73
|
+
/**
|
|
74
|
+
* The unique id of this scope.
|
|
75
|
+
*/
|
|
76
|
+
get id() {
|
|
77
|
+
return this.#id;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
#kind: string;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* The kind of scope. Subtypes will likely provide a set of known scope kinds.
|
|
84
|
+
* The kind is not used by the binder itself.
|
|
85
|
+
*/
|
|
86
|
+
get kind() {
|
|
87
|
+
return this.#kind;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
#flags: OutputScopeFlags;
|
|
91
|
+
/**
|
|
92
|
+
* The flags that describe this scope.
|
|
93
|
+
*/
|
|
94
|
+
get flags() {
|
|
95
|
+
track(this, TrackOpTypes.GET, "flags");
|
|
96
|
+
return this.#flags;
|
|
97
|
+
}
|
|
98
|
+
set flags(flags: OutputScopeFlags) {
|
|
99
|
+
const old = this.#flags;
|
|
100
|
+
this.#flags = flags;
|
|
101
|
+
trigger(this, TriggerOpTypes.SET, "flags", flags, old);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// read only
|
|
105
|
+
#metadata: Record<string, unknown>;
|
|
106
|
+
get metadata() {
|
|
107
|
+
return this.#metadata;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
#parent?: OutputScope;
|
|
111
|
+
/**
|
|
112
|
+
* The container of this scope. This is only defined for scopes which don't
|
|
113
|
+
* have the {@link OutputScopeFlags.StaticMemberScope} or
|
|
114
|
+
* {@link OutputScopeFlags.InstanceMemberScope} flag.
|
|
115
|
+
*/
|
|
116
|
+
get parent() {
|
|
117
|
+
return this.#parent;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
#owner?: OutputSymbol;
|
|
121
|
+
/**
|
|
122
|
+
* The symbol that owns this scope. This is only defined for scopes that have
|
|
123
|
+
* the {@link OutputScopeFlags.StaticMemberScope} or
|
|
124
|
+
* {@link OutputScopeFlags.InstanceMemberScope} flag.
|
|
125
|
+
*/
|
|
126
|
+
get owner() {
|
|
127
|
+
return this.#owner;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
#symbols: SymbolTable;
|
|
131
|
+
/**
|
|
132
|
+
* The symbols defined within this scope.
|
|
133
|
+
*/
|
|
134
|
+
get symbols() {
|
|
135
|
+
return this.#symbols;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
#symbolsByRefkey: ReadonlyMap<Refkey, OutputSymbol>;
|
|
139
|
+
/**
|
|
140
|
+
* The symbols defined within this scope, indexed by refkey.
|
|
141
|
+
*/
|
|
142
|
+
get symbolsByRefkey() {
|
|
143
|
+
return this.#symbolsByRefkey;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
#symbolNames: ReadonlySet<string>;
|
|
147
|
+
get symbolNames() {
|
|
148
|
+
return this.#symbolNames;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
#children: Set<OutputScope>;
|
|
152
|
+
/**
|
|
153
|
+
* The scopes nested within this scope.
|
|
154
|
+
*/
|
|
155
|
+
get children() {
|
|
156
|
+
return this.#children;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
#binder: Binder | undefined;
|
|
160
|
+
/**
|
|
161
|
+
* The binder that created this scope.
|
|
162
|
+
*/
|
|
163
|
+
get binder() {
|
|
164
|
+
return this.#binder;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
[ReactiveFlags.SKIP] = this;
|
|
168
|
+
|
|
169
|
+
constructor(name: string, options: OutputScopeOptions = {}) {
|
|
170
|
+
this.#name = name;
|
|
171
|
+
this.#id = scopeCount++;
|
|
172
|
+
this.#flags = options.flags ?? OutputScopeFlags.None;
|
|
173
|
+
this.#kind = options.kind ?? "scope";
|
|
174
|
+
this.#metadata = reactive(options.metadata ?? {});
|
|
175
|
+
this.#binder = options.binder ?? useBinder();
|
|
176
|
+
this.#owner = options.owner;
|
|
177
|
+
this.#children = shallowReactive(new Set());
|
|
178
|
+
|
|
179
|
+
if (this.#flags & OutputScopeFlags.MemberScope) {
|
|
180
|
+
if (!this.#owner) {
|
|
181
|
+
throw new Error("Member scopes must have an owner");
|
|
182
|
+
}
|
|
183
|
+
} else {
|
|
184
|
+
if (!this.#parent) {
|
|
185
|
+
this.#parent =
|
|
186
|
+
options.parent ?? useScope() ?? this.#binder?.globalScope;
|
|
187
|
+
}
|
|
188
|
+
if (this.#parent) {
|
|
189
|
+
// not global scope
|
|
190
|
+
this.#parent.children.add(this);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
this.#symbols = new SymbolTable(this, {
|
|
195
|
+
nameConflictResolver: this.#binder?.nameConflictResolver,
|
|
196
|
+
});
|
|
197
|
+
this.#symbolsByRefkey = this.#symbols.createIndex((s) => s.refkeys);
|
|
198
|
+
this.#symbolNames = this.#symbols.createDerivedSet((s) => {
|
|
199
|
+
return s.name;
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
if (this.#parent) {
|
|
203
|
+
this.#parent.children.add(this);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
this.#binder?.notifyScopeCreated(this);
|
|
207
|
+
|
|
208
|
+
trace(TracePhase.scope.create, () => `${formatScope(this)}`);
|
|
209
|
+
traceEffect(TracePhase.scope.update, () => {
|
|
210
|
+
return `${formatScope(this)}`;
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
moveSymbolsFrom(
|
|
215
|
+
source: OutputScope,
|
|
216
|
+
options?: ReactiveUnionSetOptions<OutputSymbol>,
|
|
217
|
+
) {
|
|
218
|
+
trace(
|
|
219
|
+
TracePhase.scope.copySymbols,
|
|
220
|
+
() =>
|
|
221
|
+
`Moving symbols from ${formatScopeName(source)} to ${formatScopeName(this)}`,
|
|
222
|
+
);
|
|
223
|
+
this.#symbols.addSubset(source.#symbols, {
|
|
224
|
+
onAdd: (symbol) => {
|
|
225
|
+
if (options?.onAdd) {
|
|
226
|
+
return options.onAdd(symbol);
|
|
227
|
+
}
|
|
228
|
+
symbol.scope = this;
|
|
229
|
+
return symbol;
|
|
230
|
+
},
|
|
231
|
+
onDelete: (symbol) => {
|
|
232
|
+
if (options?.onDelete) {
|
|
233
|
+
options.onDelete(symbol);
|
|
234
|
+
}
|
|
235
|
+
},
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
copySymbolsFrom(
|
|
240
|
+
source: OutputScope,
|
|
241
|
+
options?: ReactiveUnionSetOptions<OutputSymbol>,
|
|
242
|
+
) {
|
|
243
|
+
trace(
|
|
244
|
+
TracePhase.scope.copySymbols,
|
|
245
|
+
() =>
|
|
246
|
+
`Copying symbols from ${formatScopeName(source)} to ${formatScopeName(this)}`,
|
|
247
|
+
);
|
|
248
|
+
this.#symbols.addSubset(source.#symbols, {
|
|
249
|
+
onAdd: (symbol) => {
|
|
250
|
+
if (options?.onAdd) {
|
|
251
|
+
return options.onAdd(symbol);
|
|
252
|
+
}
|
|
253
|
+
return symbol.copyToScope(this);
|
|
254
|
+
},
|
|
255
|
+
onDelete: (symbol) => {
|
|
256
|
+
if (options?.onDelete) {
|
|
257
|
+
options.onDelete(symbol);
|
|
258
|
+
}
|
|
259
|
+
},
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
clone(options: { parent?: OutputScope; owner?: OutputSymbol } = {}) {
|
|
264
|
+
if (this.#flags & OutputScopeFlags.MemberScope && !options.owner) {
|
|
265
|
+
throw new Error("Member scope clones must specify an owner symbol");
|
|
266
|
+
} else if (this.#flags & ~OutputScopeFlags.MemberScope && !options.parent) {
|
|
267
|
+
throw new Error("Non-member scope clones must specify a parent scope");
|
|
268
|
+
}
|
|
269
|
+
const clone = new OutputScope(this.#name, {
|
|
270
|
+
binder: this.#binder,
|
|
271
|
+
flags: this.#flags,
|
|
272
|
+
kind: this.#kind,
|
|
273
|
+
metadata: this.#metadata,
|
|
274
|
+
parent: options.parent,
|
|
275
|
+
owner: options.owner,
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
watch(
|
|
279
|
+
() => this.name,
|
|
280
|
+
(newName) => (clone.name = newName),
|
|
281
|
+
);
|
|
282
|
+
watch(
|
|
283
|
+
() => this.flags,
|
|
284
|
+
(newFlags) => (clone.flags = newFlags),
|
|
285
|
+
);
|
|
286
|
+
// todo: this should be reactive, but cloning non-member scopes
|
|
287
|
+
// seems like a very rare thing.
|
|
288
|
+
for (const child of this.#children) {
|
|
289
|
+
clone.children.add(child.clone());
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
clone.copySymbolsFrom(this);
|
|
293
|
+
|
|
294
|
+
return clone;
|
|
295
|
+
}
|
|
296
|
+
}
|