@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
package/src/binder.ts
CHANGED
|
@@ -1,251 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
computed,
|
|
3
|
-
reactive,
|
|
4
|
-
ref,
|
|
5
|
-
Ref,
|
|
6
|
-
ShallowRef,
|
|
7
|
-
shallowRef,
|
|
8
|
-
} from "@vue/reactivity";
|
|
9
|
-
import { useBinder } from "./context/binder.js";
|
|
1
|
+
import { computed, ref, Ref, ShallowRef, shallowRef } from "@vue/reactivity";
|
|
10
2
|
import { useMemberScope } from "./context/member-scope.js";
|
|
11
3
|
import { useScope } from "./context/scope.js";
|
|
12
|
-
import { effect,
|
|
4
|
+
import { effect, untrack } from "./reactivity.js";
|
|
13
5
|
import { refkey, Refkey } from "./refkey.js";
|
|
14
|
-
import {
|
|
6
|
+
import { OutputSymbolFlags } from "./symbols/flags.js";
|
|
7
|
+
import { OutputScope } from "./symbols/output-scope.js";
|
|
8
|
+
import { type OutputSymbol } from "./symbols/output-symbol.js";
|
|
9
|
+
import {
|
|
10
|
+
formatRefkeys,
|
|
11
|
+
formatSymbol,
|
|
12
|
+
formatSymbolName,
|
|
13
|
+
trace,
|
|
14
|
+
TracePhase,
|
|
15
|
+
} from "./tracer.js";
|
|
15
16
|
export type Metadata = object;
|
|
16
17
|
|
|
17
|
-
/**
|
|
18
|
-
* Flags that describe an output symbol.
|
|
19
|
-
*/
|
|
20
|
-
export enum OutputSymbolFlags {
|
|
21
|
-
None = 0,
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* The symbol is an instance member container. Symbols with this flag will have a
|
|
25
|
-
* instanceMemberScope property that contains symbols for instance members.
|
|
26
|
-
*/
|
|
27
|
-
InstanceMemberContainer = 1 << 0,
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* The symbol is a static member container. Symbols with this flag will have a
|
|
31
|
-
* staticMemberScope property that contains symbols for static members.
|
|
32
|
-
*/
|
|
33
|
-
StaticMemberContainer = 1 << 1,
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Whether this symbol contains members of any kind.
|
|
37
|
-
*/
|
|
38
|
-
MemberContainer = InstanceMemberContainer | StaticMemberContainer,
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Whether this symbol is an instance member of another symbol (i.e that it is
|
|
42
|
-
* stored in an instance member scope).
|
|
43
|
-
*/
|
|
44
|
-
InstanceMember = 1 << 2,
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Whether this symbol is a static member of another symbol (i.e that it is
|
|
48
|
-
* stored in a static member scope).
|
|
49
|
-
*/
|
|
50
|
-
StaticMember = 1 << 3,
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Whether this is an instance member or static member of another symbol.
|
|
54
|
-
*/
|
|
55
|
-
Member = InstanceMember | StaticMember,
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* An output symbol is a named entity that can be referenced in your output
|
|
60
|
-
* code. Referencing symbols is generally accomplished by using a
|
|
61
|
-
* {@link Refkey}.
|
|
62
|
-
*
|
|
63
|
-
* @remarks
|
|
64
|
-
*
|
|
65
|
-
* This interface is the base implementation of symbol. Generally, most
|
|
66
|
-
* languages will have subtypes of this interface that provide additional,
|
|
67
|
-
* language-specific metadata about declared symbols. For example, symbols in
|
|
68
|
-
* TypeScript need to track whether they are exported or what kind of symbol
|
|
69
|
-
* they are (e.g. type, value, parameter, etc.)
|
|
70
|
-
*
|
|
71
|
-
* Symbols are reactive values, which allows you to observe changes to the symbol
|
|
72
|
-
* information. For example, a symbol's name may change if it becomes conflicted
|
|
73
|
-
* with a symbol that is added later.
|
|
74
|
-
*/
|
|
75
|
-
export interface OutputSymbol {
|
|
76
|
-
/**
|
|
77
|
-
* The original name of the symbol, before any conflicts were resolved.
|
|
78
|
-
*/
|
|
79
|
-
originalName: string;
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* The name of the symbol.
|
|
83
|
-
*/
|
|
84
|
-
name: string;
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* The symbol's flags.
|
|
88
|
-
*/
|
|
89
|
-
flags: OutputSymbolFlags;
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* The scope in which the symbol is defined.
|
|
93
|
-
*/
|
|
94
|
-
scope: OutputScope;
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* The binder instance that created this symbol.
|
|
98
|
-
*/
|
|
99
|
-
binder: Binder;
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* The unique values that reference this symbol.
|
|
103
|
-
*/
|
|
104
|
-
refkeys: Refkey[];
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* The instance members available on this symbol.
|
|
108
|
-
*
|
|
109
|
-
* @remarks
|
|
110
|
-
*
|
|
111
|
-
* Instance members are members that are available when this symbol is
|
|
112
|
-
* instantiated. Instantiation is language-specific. For example, in
|
|
113
|
-
* TypeScript, instance members of symbols for classes are available when the
|
|
114
|
-
* class is instantiated with a new expression.
|
|
115
|
-
*
|
|
116
|
-
* When a symbol cannot have instance members, this is undefined.
|
|
117
|
-
*/
|
|
118
|
-
instanceMemberScope?: OutputScope;
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* The static members available on this symbol.
|
|
122
|
-
*
|
|
123
|
-
* @remarks
|
|
124
|
-
*
|
|
125
|
-
* Static members are members that are available on the symbol itself. These symbols
|
|
126
|
-
* can be accessed off the parent symbol directly with a refkey. There is only ever
|
|
127
|
-
* one static member symbol in the output (i.e., the symbol is unique).
|
|
128
|
-
*/
|
|
129
|
-
staticMemberScope?: OutputScope;
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Additional custom metadata about this symbol.
|
|
133
|
-
*/
|
|
134
|
-
metadata: Record<string, unknown>;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Flags that describe an output scope.
|
|
139
|
-
*/
|
|
140
|
-
export enum OutputScopeFlags {
|
|
141
|
-
None = 0,
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* This scope is a static member scope.
|
|
145
|
-
*/
|
|
146
|
-
StaticMemberScope = 1 << 0,
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* This scope is an instance member scope.
|
|
150
|
-
*/
|
|
151
|
-
InstanceMemberScope = 1 << 1,
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* This scope is a member scope. Scopes with this flag will have an `owner`
|
|
155
|
-
* property that points to the symbol whose member this scope holds.
|
|
156
|
-
*/
|
|
157
|
-
MemberScope = StaticMemberScope | InstanceMemberScope,
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* A container of symbols accessible within some scope in your output code.
|
|
162
|
-
*
|
|
163
|
-
* @remarks
|
|
164
|
-
*
|
|
165
|
-
* Scopes form a tree. All scopes except the global scope have a parent scope
|
|
166
|
-
* identified by `parent`. Scopes can have nested scopes which can be accessed
|
|
167
|
-
* using the `children` property. Whether a child scope can be accessed from
|
|
168
|
-
* the parent scope is determined by each language's scoping rules.
|
|
169
|
-
*
|
|
170
|
-
* This interface is the base implementation of scope. Generally, most languages
|
|
171
|
-
* will have subtypes of this interface that provide additional metadata about
|
|
172
|
-
* the scope. For example, TypeScript scopes need to track whether the scope
|
|
173
|
-
* represents a package, module, class, function, etc.
|
|
174
|
-
*
|
|
175
|
-
* Scopes are reactive values, which allows you to observe changes to the scope
|
|
176
|
-
* within a reactive context.
|
|
177
|
-
*/
|
|
178
|
-
export interface OutputScope {
|
|
179
|
-
/**
|
|
180
|
-
* The kind of scope. Subtypes will likely provide a set of known scope kinds.
|
|
181
|
-
* The kind is not used by the binder itself.
|
|
182
|
-
*/
|
|
183
|
-
kind?: string;
|
|
184
|
-
|
|
185
|
-
/**
|
|
186
|
-
* The name of the scope.
|
|
187
|
-
*/
|
|
188
|
-
name: string;
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* The flags that describe this scope.
|
|
192
|
-
*/
|
|
193
|
-
flags: OutputScopeFlags;
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* The symbols defined within this scope.
|
|
197
|
-
*/
|
|
198
|
-
symbols: Set<OutputSymbol>;
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
* The symbols defined within this scope, indexed by refkey.
|
|
202
|
-
*/
|
|
203
|
-
symbolsByRefkey: Map<Refkey, OutputSymbol>;
|
|
204
|
-
|
|
205
|
-
/**
|
|
206
|
-
* The scopes nested within this scope.
|
|
207
|
-
*/
|
|
208
|
-
children: Set<OutputScope>;
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* The container of this scope.
|
|
212
|
-
*/
|
|
213
|
-
parent: OutputScope | undefined;
|
|
214
|
-
|
|
215
|
-
/**
|
|
216
|
-
* The symbol that owns this scope. This is only defined for scopes that have
|
|
217
|
-
* the {@link OutputScopeFlags.StaticMemberScope} flag.
|
|
218
|
-
*/
|
|
219
|
-
owner?: OutputSymbol;
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* The binder that created this scope.
|
|
223
|
-
*/
|
|
224
|
-
binder: Binder;
|
|
225
|
-
|
|
226
|
-
/**
|
|
227
|
-
* Get the names of all symbols in this scope.
|
|
228
|
-
*/
|
|
229
|
-
getSymbolNames(): Set<string>;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
export type CreateSymbolOptions<T extends OutputSymbol = OutputSymbol> = {
|
|
233
|
-
name: string;
|
|
234
|
-
scope?: OutputScope;
|
|
235
|
-
refkey?: Refkey | Refkey[];
|
|
236
|
-
flags?: OutputSymbolFlags;
|
|
237
|
-
metadata?: Record<string, unknown>;
|
|
238
|
-
} & Omit<T, keyof OutputSymbol>;
|
|
239
|
-
|
|
240
|
-
export type CreateScopeOptions<T extends OutputScope = OutputScope> = {
|
|
241
|
-
kind: T["kind"];
|
|
242
|
-
name: string;
|
|
243
|
-
parent?: OutputScope | undefined;
|
|
244
|
-
flags?: OutputScopeFlags;
|
|
245
|
-
owner?: OutputSymbol;
|
|
246
|
-
metadata?: Record<string, unknown>;
|
|
247
|
-
} & Omit<T, keyof OutputScope>;
|
|
248
|
-
|
|
249
18
|
/**
|
|
250
19
|
* The binder tracks all output scopes and symbols. Scopes are nested containers
|
|
251
20
|
* for symbols.
|
|
@@ -260,47 +29,6 @@ export type CreateScopeOptions<T extends OutputScope = OutputScope> = {
|
|
|
260
29
|
*
|
|
261
30
|
*/
|
|
262
31
|
export interface Binder {
|
|
263
|
-
/**
|
|
264
|
-
* Create a new scope. The scope will be added to the parent scope's children.
|
|
265
|
-
* The returned scope object is reactive.
|
|
266
|
-
*/
|
|
267
|
-
createScope<T extends OutputScope>(args: CreateScopeOptions<T>): T;
|
|
268
|
-
|
|
269
|
-
/**
|
|
270
|
-
* Create a new symbol. The symbol will be added to the parent scope's symbols.
|
|
271
|
-
* The returned symbol object is reactive.
|
|
272
|
-
*/
|
|
273
|
-
createSymbol<T extends OutputSymbol>(args: CreateSymbolOptions<T>): T;
|
|
274
|
-
|
|
275
|
-
/**
|
|
276
|
-
* Delete the given symbol. The symbol will be removed from its parent's
|
|
277
|
-
* scope. Any resolutions to this symbol will become undefined.
|
|
278
|
-
*/
|
|
279
|
-
deleteSymbol(symbol: OutputSymbol): void;
|
|
280
|
-
|
|
281
|
-
/**
|
|
282
|
-
* Instantiate the static members of a symbol into the instance members of
|
|
283
|
-
* another symbol.
|
|
284
|
-
*
|
|
285
|
-
* @param sourceSym - The symbol to add instance members to.
|
|
286
|
-
* @param targetSym - The symbol with the static members to instantiate.
|
|
287
|
-
*/
|
|
288
|
-
instantiateSymbolInto(sourceSym: OutputSymbol, targetSym: OutputSymbol): void;
|
|
289
|
-
|
|
290
|
-
/**
|
|
291
|
-
* Add static members to an existing symbol.
|
|
292
|
-
*
|
|
293
|
-
* @param symbol - The symbol to add static members to.
|
|
294
|
-
*/
|
|
295
|
-
addStaticMembersToSymbol(symbol: OutputSymbol): void;
|
|
296
|
-
|
|
297
|
-
/**
|
|
298
|
-
* Add instance members to an existing symbol.
|
|
299
|
-
*
|
|
300
|
-
* @param symbol - The symbol to add instance members to.
|
|
301
|
-
*/
|
|
302
|
-
addInstanceMembersToSymbol(symbol: OutputSymbol): void;
|
|
303
|
-
|
|
304
32
|
/**
|
|
305
33
|
* Resolve the given refkey in the current scope.
|
|
306
34
|
*
|
|
@@ -358,6 +86,26 @@ export interface Binder {
|
|
|
358
86
|
* The global scope. This is the root scope for all symbols.
|
|
359
87
|
*/
|
|
360
88
|
globalScope: OutputScope;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* The name conflict resolver to use for this binder.
|
|
92
|
+
*/
|
|
93
|
+
nameConflictResolver?: NameConflictResolver;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Notifies the binder that a scope has been created.
|
|
97
|
+
*/
|
|
98
|
+
notifyScopeCreated(scope: OutputScope): void;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Notifies the binder that a symbol has been created.
|
|
102
|
+
*/
|
|
103
|
+
notifySymbolCreated(symbol: OutputSymbol): void;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Notifies the binder that a symbol has been deleted.
|
|
107
|
+
*/
|
|
108
|
+
notifySymbolDeleted(symbol: OutputSymbol): void;
|
|
361
109
|
}
|
|
362
110
|
|
|
363
111
|
/**
|
|
@@ -426,32 +174,21 @@ export interface BinderOptions {
|
|
|
426
174
|
|
|
427
175
|
export function createOutputBinder(options: BinderOptions = {}): Binder {
|
|
428
176
|
const binder: Binder = {
|
|
429
|
-
createScope,
|
|
430
|
-
createSymbol,
|
|
431
|
-
deleteSymbol,
|
|
432
177
|
resolveDeclarationByKey,
|
|
433
178
|
getSymbolForRefkey,
|
|
434
|
-
addStaticMembersToSymbol,
|
|
435
|
-
addInstanceMembersToSymbol,
|
|
436
|
-
instantiateSymbolInto,
|
|
437
179
|
findSymbolName,
|
|
438
180
|
findScopeName,
|
|
439
181
|
resolveFQN: resolveFQN as any,
|
|
440
182
|
globalScope: undefined as any,
|
|
183
|
+
notifyScopeCreated,
|
|
184
|
+
notifySymbolCreated,
|
|
185
|
+
notifySymbolDeleted,
|
|
186
|
+
nameConflictResolver: options.nameConflictResolver,
|
|
441
187
|
};
|
|
442
188
|
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
binder.globalScope = reactive({
|
|
446
|
-
kind: "global",
|
|
447
|
-
name: "<global>",
|
|
448
|
-
symbols: new Set(),
|
|
449
|
-
symbolsByRefkey: new Map(),
|
|
450
|
-
children: new Set(),
|
|
451
|
-
parent: undefined,
|
|
189
|
+
binder.globalScope = new OutputScope("<global>", {
|
|
452
190
|
binder,
|
|
453
|
-
|
|
454
|
-
getSymbolNames: symbolNames(globalSymbols),
|
|
191
|
+
kind: "global",
|
|
455
192
|
});
|
|
456
193
|
|
|
457
194
|
const knownDeclarations = new Map<Refkey, OutputSymbol>();
|
|
@@ -464,153 +201,22 @@ export function createOutputBinder(options: BinderOptions = {}): Binder {
|
|
|
464
201
|
OutputScope,
|
|
465
202
|
Map<string, Ref<OutputScope | undefined>>
|
|
466
203
|
>();
|
|
467
|
-
const deconflictJobs = new Map<OutputScope, Map<string, QueueJob>>();
|
|
468
204
|
|
|
469
205
|
return binder;
|
|
470
206
|
|
|
471
|
-
function
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
name,
|
|
475
|
-
parent,
|
|
476
|
-
owner,
|
|
477
|
-
flags = OutputScopeFlags.None,
|
|
478
|
-
metadata = {},
|
|
479
|
-
...rest
|
|
480
|
-
} = args;
|
|
481
|
-
|
|
482
|
-
if (flags & OutputScopeFlags.MemberScope) {
|
|
483
|
-
if (!owner) {
|
|
484
|
-
throw new Error("Member scopes must have an owner");
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
// member scopes don't have a parent regular scope. Perhaps in the future
|
|
489
|
-
// their parent would be something like a prototype object.
|
|
490
|
-
let parentScope: OutputScope | undefined;
|
|
491
|
-
if (parent) {
|
|
492
|
-
parentScope = parent;
|
|
493
|
-
} else if (flags & OutputScopeFlags.MemberScope) {
|
|
494
|
-
parentScope = undefined;
|
|
495
|
-
} else {
|
|
496
|
-
parentScope = useScope() ?? binder.globalScope;
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
const symbols = reactive(new Set<OutputSymbol>());
|
|
500
|
-
const symbolsByRefkey = reactive(new Map<Refkey, OutputSymbol>());
|
|
501
|
-
const scope: T = reactive({
|
|
502
|
-
kind: kind,
|
|
503
|
-
name: name,
|
|
504
|
-
symbols,
|
|
505
|
-
symbolsByRefkey,
|
|
506
|
-
children: new Set(),
|
|
507
|
-
parent: parentScope,
|
|
508
|
-
flags,
|
|
509
|
-
owner,
|
|
510
|
-
binder,
|
|
511
|
-
metadata,
|
|
512
|
-
...rest,
|
|
513
|
-
getSymbolNames: symbolNames(symbols),
|
|
514
|
-
}) as T;
|
|
515
|
-
|
|
516
|
-
if (parentScope) {
|
|
517
|
-
parentScope.children.add(scope);
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
if (waitingScopeNames.has(parentScope!)) {
|
|
521
|
-
const waiting = waitingScopeNames.get(parentScope!);
|
|
522
|
-
if (waiting?.has(name)) {
|
|
523
|
-
const ref = waiting.get(name)!;
|
|
524
|
-
ref.value = scope;
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
return scope as T;
|
|
529
|
-
}
|
|
530
|
-
|
|
531
|
-
function createSymbol<T extends OutputSymbol>(
|
|
532
|
-
args: CreateSymbolOptions<T>,
|
|
533
|
-
): T {
|
|
534
|
-
const {
|
|
535
|
-
name,
|
|
536
|
-
scope = useDefaultScope(args.flags),
|
|
537
|
-
refkey,
|
|
538
|
-
flags = OutputSymbolFlags.None,
|
|
539
|
-
metadata = {},
|
|
540
|
-
...rest
|
|
541
|
-
} = args;
|
|
542
|
-
|
|
543
|
-
const allRefkeys = [refkey ?? []].flat();
|
|
544
|
-
|
|
545
|
-
if (!scope) {
|
|
546
|
-
throw new Error(
|
|
547
|
-
"No scope was provided and no scope could be found in context",
|
|
548
|
-
);
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
if (
|
|
552
|
-
flags & OutputSymbolFlags.Member &&
|
|
553
|
-
(scope.flags & OutputScopeFlags.MemberScope) === 0
|
|
554
|
-
) {
|
|
555
|
-
throw new Error("Member symbols must be stored in a member scope.");
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
if (scope.flags & OutputScopeFlags.StaticMemberScope) {
|
|
559
|
-
if (
|
|
560
|
-
~flags & OutputSymbolFlags.InstanceMember &&
|
|
561
|
-
~flags & OutputSymbolFlags.StaticMember
|
|
562
|
-
) {
|
|
563
|
-
throw new Error(
|
|
564
|
-
"Symbols stored in a member scope must have either OutputSymbolFlags.InstanceMember or OutputSymbolFlags.StaticMember flags",
|
|
565
|
-
);
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
const symbol = reactive({
|
|
570
|
-
originalName: name,
|
|
571
|
-
name: name,
|
|
572
|
-
scope,
|
|
573
|
-
refkeys: allRefkeys,
|
|
574
|
-
binder,
|
|
575
|
-
flags,
|
|
576
|
-
metadata,
|
|
577
|
-
...rest,
|
|
578
|
-
}) as T;
|
|
579
|
-
|
|
580
|
-
if (args.flags && args.flags & OutputSymbolFlags.InstanceMemberContainer) {
|
|
581
|
-
symbol.instanceMemberScope = createScope({
|
|
582
|
-
kind: "member",
|
|
583
|
-
name: "instance members",
|
|
584
|
-
parent: undefined,
|
|
585
|
-
owner: symbol,
|
|
586
|
-
flags: OutputScopeFlags.InstanceMemberScope,
|
|
587
|
-
});
|
|
588
|
-
}
|
|
589
|
-
|
|
590
|
-
if (args.flags && args.flags & OutputSymbolFlags.StaticMemberContainer) {
|
|
591
|
-
symbol.staticMemberScope = createScope({
|
|
592
|
-
kind: "member",
|
|
593
|
-
name: "static members",
|
|
594
|
-
parent: undefined,
|
|
595
|
-
owner: symbol,
|
|
596
|
-
flags: OutputScopeFlags.StaticMemberScope,
|
|
597
|
-
});
|
|
207
|
+
function notifyScopeCreated(scope: OutputScope) {
|
|
208
|
+
if (!scope.parent || !waitingScopeNames.has(scope.parent)) {
|
|
209
|
+
return;
|
|
598
210
|
}
|
|
599
211
|
|
|
600
|
-
scope.
|
|
601
|
-
|
|
602
|
-
scope.
|
|
212
|
+
const waiting = waitingScopeNames.get(scope.parent)!;
|
|
213
|
+
if (waiting?.has(scope.name)) {
|
|
214
|
+
const ref = waiting.get(scope.name)!;
|
|
215
|
+
ref.value = scope;
|
|
603
216
|
}
|
|
604
|
-
|
|
605
|
-
deconflict(symbol);
|
|
606
|
-
notifyRefkey(symbol);
|
|
607
|
-
|
|
608
|
-
return symbol;
|
|
609
217
|
}
|
|
610
218
|
|
|
611
|
-
function
|
|
612
|
-
symbol.scope.symbols.delete(symbol);
|
|
613
|
-
|
|
219
|
+
function notifySymbolDeleted(symbol: OutputSymbol) {
|
|
614
220
|
if (!refkey) {
|
|
615
221
|
return;
|
|
616
222
|
}
|
|
@@ -622,138 +228,23 @@ export function createOutputBinder(options: BinderOptions = {}): Binder {
|
|
|
622
228
|
}
|
|
623
229
|
}
|
|
624
230
|
|
|
625
|
-
function
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
effect(() => {
|
|
634
|
-
// copy instance members if it's an instance‐container
|
|
635
|
-
if (source.flags & OutputSymbolFlags.InstanceMemberContainer) {
|
|
636
|
-
copyMembers(
|
|
637
|
-
source.instanceMemberScope!.symbols,
|
|
638
|
-
target,
|
|
639
|
-
target.staticMemberScope!,
|
|
640
|
-
);
|
|
231
|
+
function hasTransientScope(symbol: OutputSymbol) {
|
|
232
|
+
let sym: OutputSymbol | undefined = symbol;
|
|
233
|
+
let transient = false;
|
|
234
|
+
while (sym) {
|
|
235
|
+
if (sym.flags & OutputSymbolFlags.Transient) {
|
|
236
|
+
transient = true;
|
|
237
|
+
break;
|
|
641
238
|
}
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
if (source.flags & OutputSymbolFlags.StaticMemberContainer) {
|
|
645
|
-
copyMembers(
|
|
646
|
-
source.staticMemberScope!.symbols,
|
|
647
|
-
target,
|
|
648
|
-
target.staticMemberScope!,
|
|
649
|
-
);
|
|
239
|
+
if (sym.flags & ~OutputSymbolFlags.Member) {
|
|
240
|
+
break;
|
|
650
241
|
}
|
|
651
|
-
});
|
|
652
242
|
|
|
653
|
-
|
|
654
|
-
* Recursively copy `symbols` from `sourceSym` into `intoScope` of `targetSym`.
|
|
655
|
-
* Always marks each instantiation as StaticMember so lookups use dot notation (e.g. Parent.child)
|
|
656
|
-
* and preserves any StaticMemberContainer flag to auto create newSym.staticMemberScope.
|
|
657
|
-
*/
|
|
658
|
-
function copyMembers(
|
|
659
|
-
symbols: Set<OutputSymbol>,
|
|
660
|
-
targetSym: OutputSymbol,
|
|
661
|
-
intoScope: OutputScope,
|
|
662
|
-
) {
|
|
663
|
-
for (const srcSym of symbols) {
|
|
664
|
-
untrack(() => {
|
|
665
|
-
const wantKey = refkey(targetSym.refkeys[0], srcSym.refkeys[0]);
|
|
666
|
-
|
|
667
|
-
// create the new symbol. Preserve StaticMemberContainer if present
|
|
668
|
-
const newSym = createSymbol({
|
|
669
|
-
name: srcSym.name,
|
|
670
|
-
scope: intoScope,
|
|
671
|
-
refkey: wantKey,
|
|
672
|
-
flags: srcSym.flags | OutputSymbolFlags.StaticMember,
|
|
673
|
-
});
|
|
674
|
-
|
|
675
|
-
onCleanup(() => {
|
|
676
|
-
binder.deleteSymbol(newSym);
|
|
677
|
-
});
|
|
678
|
-
|
|
679
|
-
// if the source symbol itself was a container of static members,
|
|
680
|
-
// recurse into the newSym.staticMemberScope that createSymbol just gave us
|
|
681
|
-
if (
|
|
682
|
-
srcSym.staticMemberScope &&
|
|
683
|
-
srcSym.staticMemberScope.symbols.size > 0
|
|
684
|
-
) {
|
|
685
|
-
// ensure we have that scope
|
|
686
|
-
addStaticMembersToSymbol(newSym);
|
|
687
|
-
|
|
688
|
-
copyMembers(
|
|
689
|
-
srcSym.staticMemberScope.symbols,
|
|
690
|
-
newSym,
|
|
691
|
-
newSym.staticMemberScope!,
|
|
692
|
-
);
|
|
693
|
-
}
|
|
694
|
-
});
|
|
695
|
-
}
|
|
696
|
-
}
|
|
697
|
-
}
|
|
698
|
-
|
|
699
|
-
function addStaticMembersToSymbol(symbol: OutputSymbol) {
|
|
700
|
-
if (symbol.flags & OutputSymbolFlags.StaticMemberContainer) {
|
|
701
|
-
// nothing to do.
|
|
702
|
-
return;
|
|
243
|
+
sym = sym.scope.owner;
|
|
703
244
|
}
|
|
704
245
|
|
|
705
|
-
|
|
706
|
-
symbol.staticMemberScope = createScope({
|
|
707
|
-
kind: "member",
|
|
708
|
-
name: "static members",
|
|
709
|
-
parent: undefined,
|
|
710
|
-
owner: symbol,
|
|
711
|
-
flags: OutputScopeFlags.StaticMemberScope,
|
|
712
|
-
});
|
|
713
|
-
}
|
|
714
|
-
|
|
715
|
-
function addInstanceMembersToSymbol(symbol: OutputSymbol) {
|
|
716
|
-
if (symbol.flags & OutputSymbolFlags.InstanceMemberContainer) {
|
|
717
|
-
// nothing to do.
|
|
718
|
-
return;
|
|
719
|
-
}
|
|
720
|
-
|
|
721
|
-
symbol.flags |= OutputSymbolFlags.InstanceMemberContainer;
|
|
722
|
-
symbol.instanceMemberScope = createScope({
|
|
723
|
-
kind: "member",
|
|
724
|
-
name: "instance members",
|
|
725
|
-
parent: undefined,
|
|
726
|
-
owner: symbol,
|
|
727
|
-
flags: OutputScopeFlags.InstanceMemberScope,
|
|
728
|
-
});
|
|
729
|
-
}
|
|
730
|
-
|
|
731
|
-
function resolveDeclarationByKey<
|
|
732
|
-
TScope extends OutputScope = OutputScope,
|
|
733
|
-
TSymbol extends OutputSymbol = OutputSymbol,
|
|
734
|
-
>(
|
|
735
|
-
currentScope: TScope | undefined,
|
|
736
|
-
currentMemberScope: TScope | undefined,
|
|
737
|
-
key: Refkey,
|
|
738
|
-
): Ref<ResolutionResult<TScope, TSymbol> | undefined> {
|
|
739
|
-
const targetDeclaration = knownDeclarations.get(key);
|
|
740
|
-
|
|
741
|
-
if (targetDeclaration) {
|
|
742
|
-
// this any cast hides a ridiculous error, fix it probably
|
|
743
|
-
return shallowRef(
|
|
744
|
-
buildResult(currentScope, currentMemberScope, targetDeclaration),
|
|
745
|
-
) as any;
|
|
746
|
-
} else {
|
|
747
|
-
return waitForRefkey(key, (symbol) => {
|
|
748
|
-
if (symbol) {
|
|
749
|
-
return buildResult(currentScope, currentMemberScope, symbol);
|
|
750
|
-
} else {
|
|
751
|
-
return undefined;
|
|
752
|
-
}
|
|
753
|
-
});
|
|
754
|
-
}
|
|
246
|
+
return transient;
|
|
755
247
|
}
|
|
756
|
-
|
|
757
248
|
function buildResult<
|
|
758
249
|
TScope extends OutputScope = OutputScope,
|
|
759
250
|
TSymbol extends OutputSymbol = OutputSymbol,
|
|
@@ -762,6 +253,9 @@ export function createOutputBinder(options: BinderOptions = {}): Binder {
|
|
|
762
253
|
currentMemberScope: TScope | undefined,
|
|
763
254
|
targetDeclarationBase: TSymbol,
|
|
764
255
|
): ResolutionResult<TScope, TSymbol> {
|
|
256
|
+
trace(TracePhase.resolve.success, () => {
|
|
257
|
+
return `Resolved ${formatRefkeys(targetDeclarationBase.refkeys)} to ${formatSymbol(targetDeclarationBase)}`;
|
|
258
|
+
});
|
|
765
259
|
if (targetDeclarationBase.flags & OutputSymbolFlags.InstanceMember) {
|
|
766
260
|
// todo: handle referencing nested objects by refkey
|
|
767
261
|
return {
|
|
@@ -838,109 +332,91 @@ export function createOutputBinder(options: BinderOptions = {}): Binder {
|
|
|
838
332
|
return chain;
|
|
839
333
|
}
|
|
840
334
|
|
|
841
|
-
function
|
|
842
|
-
|
|
843
|
-
const existingNames = [...scope.symbols].filter(
|
|
844
|
-
(sym) => sym.name === symbol.name,
|
|
845
|
-
);
|
|
846
|
-
|
|
847
|
-
if (existingNames.length < 2) {
|
|
848
|
-
return;
|
|
849
|
-
}
|
|
850
|
-
|
|
851
|
-
queueJob(
|
|
852
|
-
deconflictJobForScopeAndName(
|
|
853
|
-
scope,
|
|
854
|
-
symbol.name,
|
|
855
|
-
options.nameConflictResolver,
|
|
856
|
-
),
|
|
857
|
-
);
|
|
858
|
-
}
|
|
859
|
-
|
|
860
|
-
function deconflictJobForScopeAndName(
|
|
861
|
-
scope: OutputScope,
|
|
862
|
-
name: string,
|
|
863
|
-
handler: NameConflictResolver | undefined,
|
|
335
|
+
function getSymbolForRefkey<TSymbol extends OutputSymbol = OutputSymbol>(
|
|
336
|
+
refkey: Refkey,
|
|
864
337
|
) {
|
|
865
|
-
if (
|
|
866
|
-
|
|
338
|
+
if (waitingDeclarations.has(refkey)) {
|
|
339
|
+
return waitingDeclarations.get(refkey)! as ShallowRef<TSymbol>;
|
|
867
340
|
}
|
|
868
341
|
|
|
869
|
-
const
|
|
870
|
-
|
|
871
|
-
|
|
342
|
+
const symbolRef = shallowRef<TSymbol | undefined>();
|
|
343
|
+
waitingDeclarations.set(refkey, symbolRef);
|
|
344
|
+
if (knownDeclarations.has(refkey)) {
|
|
345
|
+
symbolRef.value = knownDeclarations.get(refkey) as TSymbol;
|
|
872
346
|
}
|
|
873
|
-
|
|
874
|
-
const conflictedSymbols = [...scope.symbols].filter(
|
|
875
|
-
(sym) => sym.name === name,
|
|
876
|
-
);
|
|
877
|
-
if (handler) {
|
|
878
|
-
handler(name, conflictedSymbols);
|
|
879
|
-
} else {
|
|
880
|
-
defaultConflictHandler(name, conflictedSymbols);
|
|
881
|
-
}
|
|
882
|
-
jobs.delete(name);
|
|
883
|
-
};
|
|
884
|
-
|
|
885
|
-
jobs.set(name, job);
|
|
886
|
-
return job;
|
|
347
|
+
return symbolRef;
|
|
887
348
|
}
|
|
888
349
|
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
conflictedSymbols: OutputSymbol[],
|
|
896
|
-
) {
|
|
897
|
-
for (let i = 1; i < conflictedSymbols.length; i++) {
|
|
898
|
-
conflictedSymbols[i].name =
|
|
899
|
-
conflictedSymbols[i].originalName + "_" + (i + 1);
|
|
900
|
-
}
|
|
901
|
-
}
|
|
902
|
-
|
|
903
|
-
function getSymbolForRefkey<TSymbol extends OutputSymbol>(
|
|
350
|
+
function resolveDeclarationByKey<
|
|
351
|
+
TScope extends OutputScope = OutputScope,
|
|
352
|
+
TSymbol extends OutputSymbol = OutputSymbol,
|
|
353
|
+
>(
|
|
354
|
+
currentScope: TScope | undefined,
|
|
355
|
+
currentMemberScope: TScope | undefined,
|
|
904
356
|
refkey: Refkey,
|
|
905
|
-
):
|
|
906
|
-
const
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
357
|
+
): ShallowRef<ResolutionResult<TScope, TSymbol> | undefined> {
|
|
358
|
+
const resolvedSymbol = getSymbolForRefkey(refkey);
|
|
359
|
+
return computed(() => {
|
|
360
|
+
trace(
|
|
361
|
+
TracePhase.resolve.pending,
|
|
362
|
+
() => `Resolving ${formatRefkeys(refkey)}.`,
|
|
363
|
+
);
|
|
364
|
+
const symbol = resolvedSymbol.value as TSymbol;
|
|
365
|
+
if (!symbol) {
|
|
366
|
+
trace(
|
|
367
|
+
TracePhase.resolve.failure,
|
|
368
|
+
() => `No symbol for ${formatRefkeys(refkey)}.`,
|
|
369
|
+
);
|
|
370
|
+
return undefined;
|
|
918
371
|
}
|
|
919
|
-
|
|
372
|
+
trace(
|
|
373
|
+
TracePhase.resolve.pending,
|
|
374
|
+
() =>
|
|
375
|
+
`${formatRefkeys(refkey)} resolved to ${formatSymbolName(symbol)}.`,
|
|
376
|
+
);
|
|
377
|
+
if (hasTransientScope(symbol)) {
|
|
378
|
+
trace(
|
|
379
|
+
TracePhase.resolve.failure,
|
|
380
|
+
() => `Symbol ${formatSymbolName(symbol)} in transient scope.`,
|
|
381
|
+
);
|
|
382
|
+
return undefined;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
trace(
|
|
386
|
+
TracePhase.resolve.success,
|
|
387
|
+
() =>
|
|
388
|
+
`${formatRefkeys(refkey)} successfully resolved to ${formatSymbolName(symbol)}.`,
|
|
389
|
+
);
|
|
390
|
+
return buildResult(currentScope, currentMemberScope, symbol);
|
|
391
|
+
});
|
|
920
392
|
}
|
|
921
393
|
|
|
922
|
-
function
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
refkey: Refkey,
|
|
927
|
-
cb: (
|
|
928
|
-
symbol: TSymbol | undefined,
|
|
929
|
-
) => ResolutionResult<TScope, TSymbol> | undefined,
|
|
930
|
-
): ShallowRef<ResolutionResult<TScope, TSymbol> | undefined> {
|
|
931
|
-
let declSignal;
|
|
932
|
-
if (waitingDeclarations.has(refkey)) {
|
|
933
|
-
declSignal = waitingDeclarations.get(refkey)! as ShallowRef<TSymbol>;
|
|
934
|
-
} else {
|
|
935
|
-
declSignal = shallowRef();
|
|
936
|
-
waitingDeclarations.set(refkey, declSignal);
|
|
394
|
+
function notifySymbolCreated(symbol: OutputSymbol): void {
|
|
395
|
+
if (symbol.flags & OutputSymbolFlags.Transient) {
|
|
396
|
+
// just ignore transient symbols.
|
|
397
|
+
return;
|
|
937
398
|
}
|
|
399
|
+
effect<Refkey[]>((oldRefkeys) => {
|
|
400
|
+
trace(
|
|
401
|
+
TracePhase.resolve.pending,
|
|
402
|
+
() => `Notifying resolutions for ${formatRefkeys(symbol.refkeys)}.`,
|
|
403
|
+
);
|
|
938
404
|
|
|
939
|
-
|
|
940
|
-
|
|
405
|
+
if (oldRefkeys) {
|
|
406
|
+
for (const refkey of oldRefkeys) {
|
|
407
|
+
if (!symbol.refkeys.includes(refkey)) {
|
|
408
|
+
// remove the old refkey from the known declarations
|
|
409
|
+
knownDeclarations.delete(refkey);
|
|
410
|
+
|
|
411
|
+
// reset any waiting declarations
|
|
412
|
+
if (waitingDeclarations.has(refkey)) {
|
|
413
|
+
const signal = waitingDeclarations.get(refkey)!;
|
|
414
|
+
signal.value = undefined;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
}
|
|
941
419
|
|
|
942
|
-
function notifyRefkey(symbol: OutputSymbol): void {
|
|
943
|
-
effect(() => {
|
|
944
420
|
for (const refkey of symbol.refkeys) {
|
|
945
421
|
// notify those waiting for this refkey
|
|
946
422
|
knownDeclarations.set(refkey, symbol);
|
|
@@ -958,13 +434,15 @@ export function createOutputBinder(options: BinderOptions = {}): Binder {
|
|
|
958
434
|
}
|
|
959
435
|
}
|
|
960
436
|
}
|
|
437
|
+
|
|
438
|
+
return [...symbol.refkeys];
|
|
961
439
|
});
|
|
962
440
|
}
|
|
963
441
|
|
|
964
442
|
function findSymbolName<TSymbol extends OutputSymbol = OutputSymbol>(
|
|
965
443
|
scope: OutputScope | undefined,
|
|
966
444
|
name: string,
|
|
967
|
-
):
|
|
445
|
+
): ShallowRef<TSymbol | undefined> {
|
|
968
446
|
return untrack(() => {
|
|
969
447
|
scope ??= binder.globalScope;
|
|
970
448
|
for (const sym of scope.symbols) {
|
|
@@ -986,12 +464,12 @@ export function createOutputBinder(options: BinderOptions = {}): Binder {
|
|
|
986
464
|
function findScopeName<TScope extends OutputScope = OutputScope>(
|
|
987
465
|
scope: OutputScope | undefined,
|
|
988
466
|
name: string,
|
|
989
|
-
):
|
|
467
|
+
): ShallowRef<TScope | undefined> {
|
|
990
468
|
return untrack(() => {
|
|
991
469
|
scope ??= binder.globalScope;
|
|
992
470
|
for (const child of scope.children) {
|
|
993
471
|
if (child.name === name) {
|
|
994
|
-
return
|
|
472
|
+
return shallowRef(child) as Ref<TScope>;
|
|
995
473
|
}
|
|
996
474
|
}
|
|
997
475
|
|
|
@@ -1083,9 +561,16 @@ export function resolve<
|
|
|
1083
561
|
TScope extends OutputScope,
|
|
1084
562
|
TSymbol extends OutputSymbol,
|
|
1085
563
|
>(refkey: Refkey): Ref<ResolutionResult<TScope, TSymbol>> {
|
|
1086
|
-
const scope = useScope()
|
|
564
|
+
const scope = useScope();
|
|
1087
565
|
const memberScope = useMemberScope();
|
|
1088
|
-
const binder =
|
|
566
|
+
const binder =
|
|
567
|
+
scope?.binder ??
|
|
568
|
+
memberScope?.instanceMembers?.binder ??
|
|
569
|
+
memberScope?.staticMembers?.binder;
|
|
570
|
+
|
|
571
|
+
if (!binder) {
|
|
572
|
+
throw new Error("Can't resolve refkey without a binder");
|
|
573
|
+
}
|
|
1089
574
|
|
|
1090
575
|
return binder.resolveDeclarationByKey(
|
|
1091
576
|
scope,
|
|
@@ -1109,17 +594,6 @@ export interface SymbolCreator {
|
|
|
1109
594
|
[createSymbolsSymbol](binder: Binder): void;
|
|
1110
595
|
}
|
|
1111
596
|
|
|
1112
|
-
function symbolNames(symbols: Set<OutputSymbol>): () => Set<string> {
|
|
1113
|
-
return memo(() => {
|
|
1114
|
-
const names = new Set<string>();
|
|
1115
|
-
for (const sym of symbols.values()) {
|
|
1116
|
-
names.add(sym.name);
|
|
1117
|
-
}
|
|
1118
|
-
|
|
1119
|
-
return names;
|
|
1120
|
-
});
|
|
1121
|
-
}
|
|
1122
|
-
|
|
1123
597
|
/**
|
|
1124
598
|
* Use symbol flags to determine the scope in which a symbol with those flags
|
|
1125
599
|
* should be declared given the current context.
|