@alloy-js/core 0.3.0 → 0.5.0
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 +20 -0
- package/dist/src/binder.d.ts +43 -18
- package/dist/src/binder.d.ts.map +1 -1
- package/dist/src/binder.js +120 -16
- package/dist/src/binder.js.map +1 -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.map +1 -1
- package/dist/src/components/Indent.d.ts +2 -2
- package/dist/src/components/Indent.d.ts.map +1 -1
- package/dist/src/components/Indent.js.map +1 -1
- 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.map +1 -1
- package/dist/src/components/MemberName.d.ts +1 -1
- package/dist/src/components/MemberName.d.ts.map +1 -1
- package/dist/src/components/MemberScope.d.ts +2 -2
- package/dist/src/components/MemberScope.d.ts.map +1 -1
- package/dist/src/components/Name.d.ts +1 -1
- package/dist/src/components/Name.d.ts.map +1 -1
- package/dist/src/components/Output.d.ts +2 -2
- package/dist/src/components/Output.d.ts.map +1 -1
- package/dist/src/components/Output.js +6 -2
- package/dist/src/components/Output.js.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.map +1 -1
- package/dist/src/components/SourceDirectory.d.ts +3 -3
- package/dist/src/components/SourceDirectory.d.ts.map +1 -1
- package/dist/src/components/SourceDirectory.js +1 -1
- package/dist/src/components/SourceDirectory.js.map +1 -1
- package/dist/src/components/SourceFile.d.ts +3 -3
- package/dist/src/components/SourceFile.d.ts.map +1 -1
- package/dist/src/components/SourceFile.js +1 -1
- package/dist/src/components/SourceFile.js.map +1 -1
- package/dist/src/components/stc/index.d.ts +18 -18
- package/dist/src/context/assignment.d.ts.map +1 -1
- package/dist/src/context/assignment.js +2 -2
- package/dist/src/context/assignment.js.map +1 -1
- package/dist/src/context/binder.d.ts.map +1 -1
- package/dist/src/context/binder.js +2 -2
- package/dist/src/context/binder.js.map +1 -1
- package/dist/src/context/declaration.d.ts.map +1 -1
- package/dist/src/context/declaration.js +2 -2
- package/dist/src/context/declaration.js.map +1 -1
- package/dist/src/context/indent.d.ts.map +1 -1
- package/dist/src/context/indent.js +2 -2
- package/dist/src/context/indent.js.map +1 -1
- package/dist/src/context/member-declaration.d.ts +1 -0
- package/dist/src/context/member-declaration.d.ts.map +1 -1
- package/dist/src/context/member-declaration.js +5 -2
- package/dist/src/context/member-declaration.js.map +1 -1
- package/dist/src/context/member-scope.d.ts.map +1 -1
- package/dist/src/context/member-scope.js +2 -2
- package/dist/src/context/member-scope.js.map +1 -1
- package/dist/src/context/name-policy.d.ts.map +1 -1
- package/dist/src/context/name-policy.js +2 -2
- package/dist/src/context/name-policy.js.map +1 -1
- package/dist/src/context/scope.d.ts.map +1 -1
- package/dist/src/context/scope.js +2 -2
- package/dist/src/context/scope.js.map +1 -1
- package/dist/src/context/source-directory.d.ts.map +1 -1
- package/dist/src/context/source-directory.js +2 -2
- package/dist/src/context/source-directory.js.map +1 -1
- package/dist/src/context/source-file.d.ts.map +1 -1
- package/dist/src/context/source-file.js +2 -2
- package/dist/src/context/source-file.js.map +1 -1
- package/dist/src/context.d.ts +5 -2
- package/dist/src/context.d.ts.map +1 -1
- package/dist/src/context.js +11 -4
- package/dist/src/context.js.map +1 -1
- package/dist/src/debug.d.ts +14 -0
- package/dist/src/debug.d.ts.map +1 -0
- package/dist/src/debug.js +163 -0
- package/dist/src/debug.js.map +1 -0
- package/dist/src/index.d.ts +3 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +3 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/jsx-runtime.d.ts +27 -4
- package/dist/src/jsx-runtime.d.ts.map +1 -1
- package/dist/src/jsx-runtime.js +20 -7
- package/dist/src/jsx-runtime.js.map +1 -1
- package/dist/src/render.d.ts +1 -1
- package/dist/src/render.d.ts.map +1 -1
- package/dist/src/render.js +15 -13
- package/dist/src/render.js.map +1 -1
- package/dist/src/slot.d.ts +15 -0
- package/dist/src/slot.d.ts.map +1 -0
- package/dist/src/slot.js +51 -0
- package/dist/src/slot.js.map +1 -0
- package/dist/src/tap.d.ts +19 -0
- package/dist/src/tap.d.ts.map +1 -0
- package/dist/src/tap.js +39 -0
- package/dist/src/tap.js.map +1 -0
- package/dist/src/utils.d.ts +1 -6
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +1 -34
- package/dist/src/utils.js.map +1 -1
- package/dist/src/write-output.browser.d.ts +2 -0
- package/dist/src/write-output.browser.d.ts.map +1 -0
- package/dist/src/write-output.browser.js +4 -0
- package/dist/src/write-output.browser.js.map +1 -0
- package/dist/src/write-output.d.ts +7 -0
- package/dist/src/write-output.d.ts.map +1 -0
- package/dist/src/write-output.js +34 -0
- package/dist/src/write-output.js.map +1 -0
- package/dist/test/components/slot.test.d.ts +2 -0
- package/dist/test/components/slot.test.d.ts.map +1 -0
- 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 +10 -6
- package/src/binder.ts +214 -50
- package/src/components/Declaration.tsx +1 -1
- package/src/components/Indent.tsx +1 -1
- package/src/components/MemberDeclaration.tsx +1 -1
- package/src/components/MemberScope.tsx +1 -1
- package/src/components/Output.tsx +4 -2
- package/src/components/Scope.tsx +1 -1
- package/src/components/SourceDirectory.tsx +2 -2
- package/src/components/SourceFile.tsx +2 -6
- package/src/context/assignment.ts +6 -2
- package/src/context/binder.ts +7 -2
- package/src/context/declaration.ts +2 -2
- package/src/context/indent.ts +13 -6
- package/src/context/member-declaration.ts +10 -2
- package/src/context/member-scope.ts +6 -2
- package/src/context/name-policy.ts +6 -2
- package/src/context/scope.ts +7 -2
- package/src/context/source-directory.ts +2 -2
- package/src/context/source-file.ts +2 -2
- package/src/context.ts +15 -4
- package/src/debug.ts +209 -0
- package/src/index.ts +3 -1
- package/src/jsx-runtime.ts +46 -11
- package/src/render.ts +21 -19
- package/src/slot.ts +90 -0
- package/src/tap.ts +69 -0
- package/src/utils.ts +2 -34
- package/src/write-output.browser.ts +3 -0
- package/src/write-output.ts +33 -0
- package/temp/api.json +1848 -203
- package/test/components/slot.test.tsx +172 -0
- package/test/rendering/basic.test.tsx +1 -1
- package/test/symbols.test.ts +161 -3
- package/testing/render.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alloy-js/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist/src/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
"import": "./dist/src/index.js"
|
|
10
10
|
},
|
|
11
11
|
"./jsx-runtime": {
|
|
12
|
+
"types": "./dist/src/jsx-runtime.d.ts",
|
|
12
13
|
"development": "./src/jsx-runtime.ts",
|
|
13
14
|
"import": "./dist/src/jsx-runtime.js"
|
|
14
15
|
},
|
|
@@ -25,6 +26,10 @@
|
|
|
25
26
|
"import": "./dist/src/components/index.js"
|
|
26
27
|
}
|
|
27
28
|
},
|
|
29
|
+
"browser": {
|
|
30
|
+
"./dist/src/write-output.js": "./dist/src/write-output.browser.js",
|
|
31
|
+
"./src/write-output.ts": "./src/write-output.browser.ts"
|
|
32
|
+
},
|
|
28
33
|
"keywords": [],
|
|
29
34
|
"author": "brian.terlson@microsoft.com",
|
|
30
35
|
"license": "MIT",
|
|
@@ -32,6 +37,8 @@
|
|
|
32
37
|
"@babel/core": "^7.24.7",
|
|
33
38
|
"@babel/preset-typescript": "^7.24.7",
|
|
34
39
|
"@vue/reactivity": "^3.4.30",
|
|
40
|
+
"chalk": "^5.3.0",
|
|
41
|
+
"cli-table3": "^0.6.5",
|
|
35
42
|
"pathe": "^1.1.2",
|
|
36
43
|
"@alloy-js/babel-preset": "~0.1.1"
|
|
37
44
|
},
|
|
@@ -41,11 +48,8 @@
|
|
|
41
48
|
"@rollup/plugin-babel": "^6.0.4",
|
|
42
49
|
"@rollup/plugin-typescript": "^11.1.6",
|
|
43
50
|
"concurrently": "^8.2.2",
|
|
44
|
-
"typescript": "^5.
|
|
45
|
-
"vitest": "^
|
|
46
|
-
},
|
|
47
|
-
"overrides": {
|
|
48
|
-
"esbuild": "0.23"
|
|
51
|
+
"typescript": "^5.7.3",
|
|
52
|
+
"vitest": "^3.0.4"
|
|
49
53
|
},
|
|
50
54
|
"type": "module",
|
|
51
55
|
"scripts": {
|
package/src/binder.ts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import { memo } from "@alloy-js/core/jsx-runtime";
|
|
2
1
|
import {
|
|
3
2
|
computed,
|
|
4
3
|
effect,
|
|
5
4
|
reactive,
|
|
5
|
+
ref,
|
|
6
6
|
Ref,
|
|
7
7
|
ShallowRef,
|
|
8
8
|
shallowRef,
|
|
9
9
|
} from "@vue/reactivity";
|
|
10
|
+
import { useBinder } from "./context/binder.js";
|
|
10
11
|
import { useMemberScope } from "./context/member-scope.js";
|
|
11
12
|
import { useScope } from "./context/scope.js";
|
|
13
|
+
import { memo, untrack } from "./jsx-runtime.js";
|
|
12
14
|
import { refkey, Refkey } from "./refkey.js";
|
|
13
15
|
export type Metadata = object;
|
|
14
16
|
|
|
@@ -222,6 +224,21 @@ export interface OutputScope {
|
|
|
222
224
|
getSymbolNames(): Set<string>;
|
|
223
225
|
}
|
|
224
226
|
|
|
227
|
+
export type CreateSymbolOptions<T extends OutputSymbol = OutputSymbol> = {
|
|
228
|
+
name: string;
|
|
229
|
+
scope?: OutputScope;
|
|
230
|
+
refkey?: Refkey;
|
|
231
|
+
flags?: OutputSymbolFlags;
|
|
232
|
+
} & Omit<T, keyof OutputSymbol>;
|
|
233
|
+
|
|
234
|
+
export type CreateScopeOptions<T extends OutputScope = OutputScope> = {
|
|
235
|
+
kind: T["kind"];
|
|
236
|
+
name: string;
|
|
237
|
+
parent?: OutputScope | undefined;
|
|
238
|
+
flags?: OutputScopeFlags;
|
|
239
|
+
owner?: OutputSymbol;
|
|
240
|
+
} & Omit<T, keyof OutputScope>;
|
|
241
|
+
|
|
225
242
|
/**
|
|
226
243
|
* The binder tracks all output scopes and symbols. Scopes are nested containers
|
|
227
244
|
* for symbols.
|
|
@@ -240,28 +257,13 @@ export interface Binder {
|
|
|
240
257
|
* Create a new scope. The scope will be added to the parent scope's children.
|
|
241
258
|
* The returned scope object is reactive.
|
|
242
259
|
*/
|
|
243
|
-
createScope<T extends OutputScope>(
|
|
244
|
-
args: {
|
|
245
|
-
kind: T["kind"];
|
|
246
|
-
name: string;
|
|
247
|
-
parent?: OutputScope | undefined;
|
|
248
|
-
flags?: OutputScopeFlags;
|
|
249
|
-
owner?: OutputSymbol;
|
|
250
|
-
} & Omit<T, keyof OutputScope>,
|
|
251
|
-
): T;
|
|
260
|
+
createScope<T extends OutputScope>(args: CreateScopeOptions<T>): T;
|
|
252
261
|
|
|
253
262
|
/**
|
|
254
263
|
* Create a new symbol. The symbol will be added to the parent scope's symbols.
|
|
255
264
|
* The returned symbol object is reactive.
|
|
256
265
|
*/
|
|
257
|
-
createSymbol<T extends OutputSymbol>(
|
|
258
|
-
args: {
|
|
259
|
-
name: string;
|
|
260
|
-
scope?: OutputScope;
|
|
261
|
-
refkey?: unknown;
|
|
262
|
-
flags?: OutputSymbolFlags;
|
|
263
|
-
} & Omit<T, keyof OutputSymbol>,
|
|
264
|
-
): T;
|
|
266
|
+
createSymbol<T extends OutputSymbol>(args: CreateSymbolOptions<T>): T;
|
|
265
267
|
|
|
266
268
|
/**
|
|
267
269
|
* Instantiate the static members of a symbol into the instance members of
|
|
@@ -302,6 +304,42 @@ export interface Binder {
|
|
|
302
304
|
key: Refkey,
|
|
303
305
|
): Ref<ResolutionResult<TScope, TSymbol> | undefined>;
|
|
304
306
|
|
|
307
|
+
/**
|
|
308
|
+
* Find a symbol with a given name in the given scope. Returns a ref
|
|
309
|
+
* for the symbol, such that when the symbol is available, the ref value
|
|
310
|
+
* will update.
|
|
311
|
+
*/
|
|
312
|
+
findSymbolName<
|
|
313
|
+
TScope extends OutputScope = OutputScope,
|
|
314
|
+
TSymbol extends OutputSymbol = OutputSymbol,
|
|
315
|
+
>(
|
|
316
|
+
currentScope: TScope | undefined,
|
|
317
|
+
name: string,
|
|
318
|
+
): Ref<TSymbol | undefined>;
|
|
319
|
+
|
|
320
|
+
findScopeName<TScope extends OutputScope = OutputScope>(
|
|
321
|
+
currentScope: TScope | undefined,
|
|
322
|
+
name: string,
|
|
323
|
+
): Ref<TScope | undefined>;
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* Resolve a fully qualified name to a symbol. Access a nested scope by name
|
|
327
|
+
* with `::`, a nested static member with `.` and a nested instance member
|
|
328
|
+
* with `#`.
|
|
329
|
+
*
|
|
330
|
+
* Per-language packages may provide their own resolveFQN function that uses
|
|
331
|
+
* syntax more natural to that language.
|
|
332
|
+
*/
|
|
333
|
+
resolveFQN<
|
|
334
|
+
TScope extends OutputScope = OutputScope,
|
|
335
|
+
TSymbol extends OutputSymbol = OutputSymbol,
|
|
336
|
+
>(
|
|
337
|
+
fqn: string,
|
|
338
|
+
): Ref<TSymbol | TScope | undefined>;
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* The global scope. This is the root scope for all symbols.
|
|
342
|
+
*/
|
|
305
343
|
globalScope: OutputScope;
|
|
306
344
|
}
|
|
307
345
|
|
|
@@ -325,11 +363,15 @@ export interface Binder {
|
|
|
325
363
|
* When we resolve the refkey for `bar` from within `namespace scope 2`, we will get the following
|
|
326
364
|
* resolution result:
|
|
327
365
|
*
|
|
328
|
-
*
|
|
329
|
-
*
|
|
330
|
-
*
|
|
331
|
-
*
|
|
332
|
-
*
|
|
366
|
+
* **targetDeclaration**: symbol bar, the symbol we resolved.
|
|
367
|
+
*
|
|
368
|
+
* **commonScope**: global scope, because this is the most specific scope that contains both the declaration and the reference.
|
|
369
|
+
*
|
|
370
|
+
* **pathUp**: [namespace scope 2], because this is the scope between the reference and the common scope.
|
|
371
|
+
*
|
|
372
|
+
* **pathDown**: [namespace scope 1], because this is the scope between the common scope and the declaration
|
|
373
|
+
*
|
|
374
|
+
* **memberPath**: [foo, bar], because we resolved a member symbol and these are the symbols that lead from the base declaration to the member symbol.
|
|
333
375
|
*/
|
|
334
376
|
export interface ResolutionResult<
|
|
335
377
|
TScope extends OutputScope,
|
|
@@ -377,6 +419,9 @@ export function createOutputBinder(options: BinderOptions = {}): Binder {
|
|
|
377
419
|
addStaticMembersToSymbol,
|
|
378
420
|
addInstanceMembersToSymbol,
|
|
379
421
|
instantiateSymbolInto,
|
|
422
|
+
findSymbolName,
|
|
423
|
+
findScopeName,
|
|
424
|
+
resolveFQN: resolveFQN as any,
|
|
380
425
|
globalScope: undefined as any,
|
|
381
426
|
};
|
|
382
427
|
|
|
@@ -396,18 +441,18 @@ export function createOutputBinder(options: BinderOptions = {}): Binder {
|
|
|
396
441
|
|
|
397
442
|
const knownDeclarations = new Map<Refkey, OutputSymbol>();
|
|
398
443
|
const waitingDeclarations = new Map<Refkey, Ref<OutputSymbol | undefined>>();
|
|
444
|
+
const waitingSymbolNames = new Map<
|
|
445
|
+
OutputScope,
|
|
446
|
+
Map<string, Ref<OutputSymbol | undefined>>
|
|
447
|
+
>();
|
|
448
|
+
const waitingScopeNames = new Map<
|
|
449
|
+
OutputScope,
|
|
450
|
+
Map<string, Ref<OutputScope | undefined>>
|
|
451
|
+
>();
|
|
399
452
|
|
|
400
453
|
return binder;
|
|
401
454
|
|
|
402
|
-
function createScope<T extends OutputScope>(
|
|
403
|
-
args: {
|
|
404
|
-
kind: string;
|
|
405
|
-
name: string;
|
|
406
|
-
parent?: OutputScope;
|
|
407
|
-
flags?: OutputScopeFlags;
|
|
408
|
-
owner?: OutputSymbol;
|
|
409
|
-
} & Omit<T, keyof OutputScope>,
|
|
410
|
-
): T {
|
|
455
|
+
function createScope<T extends OutputScope>(args: CreateScopeOptions<T>): T {
|
|
411
456
|
const {
|
|
412
457
|
kind,
|
|
413
458
|
name,
|
|
@@ -454,16 +499,19 @@ export function createOutputBinder(options: BinderOptions = {}): Binder {
|
|
|
454
499
|
parentScope.children.add(scope);
|
|
455
500
|
}
|
|
456
501
|
|
|
502
|
+
if (waitingScopeNames.has(parentScope!)) {
|
|
503
|
+
const waiting = waitingScopeNames.get(parentScope!);
|
|
504
|
+
if (waiting?.has(name)) {
|
|
505
|
+
const ref = waiting.get(name)!;
|
|
506
|
+
ref.value = scope;
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
|
|
457
510
|
return scope as T;
|
|
458
511
|
}
|
|
459
512
|
|
|
460
513
|
function createSymbol<T extends OutputSymbol>(
|
|
461
|
-
args:
|
|
462
|
-
name: string;
|
|
463
|
-
scope?: OutputScope;
|
|
464
|
-
refkey?: Refkey;
|
|
465
|
-
flags?: OutputSymbolFlags;
|
|
466
|
-
} & Omit<T, keyof OutputSymbol>,
|
|
514
|
+
args: CreateSymbolOptions<T>,
|
|
467
515
|
): T {
|
|
468
516
|
const {
|
|
469
517
|
name,
|
|
@@ -531,7 +579,7 @@ export function createOutputBinder(options: BinderOptions = {}): Binder {
|
|
|
531
579
|
scope.symbolsByRefkey.set(symbol.refkey, symbol);
|
|
532
580
|
|
|
533
581
|
deconflict(symbol);
|
|
534
|
-
notifyRefkey(
|
|
582
|
+
notifyRefkey(symbol);
|
|
535
583
|
|
|
536
584
|
return symbol;
|
|
537
585
|
}
|
|
@@ -747,16 +795,132 @@ export function createOutputBinder(options: BinderOptions = {}): Binder {
|
|
|
747
795
|
return computed(() => cb(declSignal.value));
|
|
748
796
|
}
|
|
749
797
|
|
|
750
|
-
function notifyRefkey(
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
798
|
+
function notifyRefkey(symbol: OutputSymbol): void {
|
|
799
|
+
effect(() => {
|
|
800
|
+
const refkey = symbol.refkey;
|
|
801
|
+
if (!refkey) return;
|
|
802
|
+
|
|
803
|
+
knownDeclarations.set(refkey, symbol);
|
|
804
|
+
if (waitingDeclarations.has(refkey)) {
|
|
805
|
+
const signal = waitingDeclarations.get(refkey)!;
|
|
806
|
+
signal.value = symbol;
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
const waitingScope = waitingSymbolNames.get(symbol.scope);
|
|
810
|
+
if (waitingScope) {
|
|
811
|
+
const waitingName = waitingScope.get(symbol.name);
|
|
812
|
+
if (waitingName) {
|
|
813
|
+
waitingName.value = symbol;
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
});
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
function findSymbolName<TSymbol extends OutputSymbol = OutputSymbol>(
|
|
820
|
+
scope: OutputScope | undefined,
|
|
821
|
+
name: string,
|
|
822
|
+
): Ref<TSymbol | undefined> {
|
|
823
|
+
return untrack(() => {
|
|
824
|
+
scope ??= binder.globalScope;
|
|
825
|
+
for (const sym of scope.symbols) {
|
|
826
|
+
if (sym.name === name) {
|
|
827
|
+
return shallowRef(sym) as Ref<TSymbol>;
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
const symRef = shallowRef<OutputSymbol | undefined>(undefined);
|
|
832
|
+
if (!waitingSymbolNames.has(scope)) {
|
|
833
|
+
waitingSymbolNames.set(scope, new Map());
|
|
834
|
+
}
|
|
835
|
+
const waiting = waitingSymbolNames.get(scope)!;
|
|
836
|
+
waiting.set(name, symRef);
|
|
837
|
+
return symRef as Ref<TSymbol | undefined>;
|
|
838
|
+
});
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
function findScopeName<TScope extends OutputScope = OutputScope>(
|
|
842
|
+
scope: OutputScope | undefined,
|
|
843
|
+
name: string,
|
|
844
|
+
): Ref<TScope | undefined> {
|
|
845
|
+
return untrack(() => {
|
|
846
|
+
scope ??= binder.globalScope;
|
|
847
|
+
for (const child of scope.children) {
|
|
848
|
+
if (child.name === name) {
|
|
849
|
+
return ref(child) as Ref<TScope>;
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
const scopeRef = shallowRef<OutputScope | undefined>(undefined);
|
|
854
|
+
if (!waitingScopeNames.has(scope)) {
|
|
855
|
+
waitingScopeNames.set(scope, new Map());
|
|
856
|
+
}
|
|
857
|
+
const waiting = waitingScopeNames.get(scope)!;
|
|
858
|
+
waiting.set(name, scopeRef);
|
|
859
|
+
|
|
860
|
+
return scopeRef as Ref<TScope | undefined>;
|
|
861
|
+
});
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
function findScopeOrSymbolName(scope: OutputScope, name: string) {
|
|
865
|
+
return untrack(() => {
|
|
866
|
+
return computed(() => {
|
|
867
|
+
return (
|
|
868
|
+
findSymbolName(scope, name).value ?? findScopeName(scope, name).value
|
|
869
|
+
);
|
|
870
|
+
});
|
|
871
|
+
});
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
function resolveFQN(
|
|
875
|
+
fqn: string,
|
|
876
|
+
): Ref<OutputScope | OutputSymbol | undefined> {
|
|
877
|
+
const parts = fqn.match(/[^.#]+|[.#]/g);
|
|
878
|
+
if (!parts) return ref(undefined);
|
|
879
|
+
if (parts.length === 0) return ref(undefined);
|
|
880
|
+
|
|
881
|
+
parts.unshift(".");
|
|
882
|
+
|
|
883
|
+
return computed(() => {
|
|
884
|
+
let base: OutputScope | OutputSymbol | undefined = binder.globalScope;
|
|
885
|
+
|
|
886
|
+
for (let i = 0; i < parts.length; i += 2) {
|
|
887
|
+
if (base === undefined) {
|
|
888
|
+
return;
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
const op = parts[i];
|
|
892
|
+
const name = parts[i + 1];
|
|
893
|
+
|
|
894
|
+
if (op === ".") {
|
|
895
|
+
if ("originalName" in base) {
|
|
896
|
+
if (!base.staticMemberScope) {
|
|
897
|
+
return undefined;
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
base = findSymbolName(
|
|
901
|
+
(base as OutputSymbol).staticMemberScope,
|
|
902
|
+
name,
|
|
903
|
+
).value;
|
|
904
|
+
} else {
|
|
905
|
+
base = findScopeOrSymbolName(base, name).value;
|
|
906
|
+
}
|
|
907
|
+
} else if (op === "#") {
|
|
908
|
+
if ("originalName" in base) {
|
|
909
|
+
if (!base.instanceMemberScope) {
|
|
910
|
+
return undefined;
|
|
911
|
+
}
|
|
912
|
+
base = findSymbolName(
|
|
913
|
+
(base as OutputSymbol).instanceMemberScope,
|
|
914
|
+
name,
|
|
915
|
+
).value;
|
|
916
|
+
} else {
|
|
917
|
+
return undefined;
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
return base;
|
|
923
|
+
});
|
|
760
924
|
}
|
|
761
925
|
}
|
|
762
926
|
|
|
@@ -774,7 +938,7 @@ export function resolve<
|
|
|
774
938
|
TScope extends OutputScope,
|
|
775
939
|
TSymbol extends OutputSymbol,
|
|
776
940
|
>(refkey: Refkey): Ref<ResolutionResult<TScope, TSymbol>> {
|
|
777
|
-
const scope = useScope();
|
|
941
|
+
const scope = useScope() ?? useBinder().globalScope;
|
|
778
942
|
const memberScope = useMemberScope();
|
|
779
943
|
const binder = scope.binder;
|
|
780
944
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Children } from "@alloy-js/core/jsx-runtime";
|
|
2
1
|
import { OutputSymbol } from "../binder.js";
|
|
3
2
|
import { useContext } from "../context.js";
|
|
4
3
|
import { BinderContext } from "../context/binder.js";
|
|
5
4
|
import { DeclarationContext } from "../context/declaration.js";
|
|
5
|
+
import { Children } from "../jsx-runtime.js";
|
|
6
6
|
import { Refkey, refkey } from "../refkey.js";
|
|
7
7
|
|
|
8
8
|
export interface DeclarationProps {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Children } from "@alloy-js/core/jsx-runtime";
|
|
2
1
|
import { OutputSymbol, OutputSymbolFlags } from "../binder.js";
|
|
3
2
|
import { useContext } from "../context.js";
|
|
4
3
|
import { BinderContext } from "../context/binder.js";
|
|
5
4
|
import { MemberDeclarationContext } from "../context/member-declaration.js";
|
|
5
|
+
import { Children } from "../jsx-runtime.js";
|
|
6
6
|
import { Refkey, refkey } from "../refkey.js";
|
|
7
7
|
|
|
8
8
|
export interface MemberDeclarationProps {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Children } from "@alloy-js/core/jsx-runtime";
|
|
2
1
|
import {
|
|
3
2
|
createOutputBinder,
|
|
4
3
|
getSymbolCreator,
|
|
@@ -6,8 +5,11 @@ import {
|
|
|
6
5
|
} from "../binder.js";
|
|
7
6
|
import { BinderContext } from "../context/binder.js";
|
|
8
7
|
import { NamePolicyContext } from "../context/name-policy.js";
|
|
8
|
+
import { Children } from "../jsx-runtime.js";
|
|
9
9
|
import { NamePolicy } from "../name-policy.js";
|
|
10
|
+
import { extensionEffects } from "../slot.js";
|
|
10
11
|
import { SourceDirectory } from "./SourceDirectory.js";
|
|
12
|
+
|
|
11
13
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
12
14
|
import { SourceFile } from "./SourceFile.js";
|
|
13
15
|
|
|
@@ -58,7 +60,7 @@ export function Output(props: OutputProps) {
|
|
|
58
60
|
}
|
|
59
61
|
|
|
60
62
|
return <BinderContext.Provider value={binder}>
|
|
61
|
-
{
|
|
63
|
+
{() => { extensionEffects.forEach(e => e())}}{
|
|
62
64
|
props.namePolicy ?
|
|
63
65
|
<NamePolicyContext.Provider value={props.namePolicy}>
|
|
64
66
|
{dir}
|
package/src/components/Scope.tsx
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Children } from "@alloy-js/core/jsx-runtime";
|
|
2
1
|
import { OutputScope } from "../binder.js";
|
|
3
2
|
import { useContext } from "../context.js";
|
|
4
3
|
import { BinderContext } from "../context/binder.js";
|
|
5
4
|
import { ScopeContext } from "../context/scope.js";
|
|
5
|
+
import { Children } from "../jsx-runtime.js";
|
|
6
6
|
|
|
7
7
|
export interface ScopeProps {
|
|
8
8
|
kind?: string;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { Children, getContext } from "@alloy-js/core/jsx-runtime";
|
|
2
1
|
import { shallowReactive } from "@vue/reactivity";
|
|
3
2
|
import { join } from "pathe";
|
|
4
3
|
import { useContext } from "../context.js";
|
|
5
4
|
import { SourceDirectoryContext } from "../context/source-directory.js";
|
|
5
|
+
import { Children, getContext } from "../jsx-runtime.js";
|
|
6
6
|
|
|
7
7
|
export interface SourceDirectoryProps {
|
|
8
8
|
path: string;
|
|
9
|
-
children?: Children
|
|
9
|
+
children?: Children;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export function SourceDirectory(props: SourceDirectoryProps) {
|
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Children,
|
|
3
|
-
ComponentDefinition,
|
|
4
|
-
getContext,
|
|
5
|
-
} from "@alloy-js/core/jsx-runtime";
|
|
6
1
|
import { join } from "pathe";
|
|
7
2
|
import { useContext } from "../context.js";
|
|
8
3
|
import { IndentContext } from "../context/indent.js";
|
|
9
4
|
import { SourceDirectoryContext } from "../context/source-directory.js";
|
|
10
5
|
import { SourceFileContext } from "../context/source-file.js";
|
|
6
|
+
import { Children, ComponentDefinition, getContext } from "../jsx-runtime.js";
|
|
11
7
|
import { Refkey } from "../refkey.js";
|
|
12
8
|
|
|
13
9
|
export interface SourceFileProps {
|
|
@@ -21,7 +17,7 @@ export interface SourceFileProps {
|
|
|
21
17
|
*/
|
|
22
18
|
filetype: string;
|
|
23
19
|
|
|
24
|
-
children?: Children
|
|
20
|
+
children?: Children;
|
|
25
21
|
|
|
26
22
|
/**
|
|
27
23
|
* The component to use to render refkeys references within the file's
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { OutputSymbol } from "../binder.js";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
ComponentContext,
|
|
4
|
+
createNamedContext,
|
|
5
|
+
useContext,
|
|
6
|
+
} from "../context.js";
|
|
3
7
|
|
|
4
8
|
export interface AssignmentContext {
|
|
5
9
|
/**
|
|
@@ -31,7 +35,7 @@ export interface AssignmentContext {
|
|
|
31
35
|
* symbols for the object value's properties.
|
|
32
36
|
*/
|
|
33
37
|
export const AssignmentContext: ComponentContext<AssignmentContext> =
|
|
34
|
-
|
|
38
|
+
createNamedContext("Assignment");
|
|
35
39
|
|
|
36
40
|
/**
|
|
37
41
|
* Creates a new {@link (AssignmentContext:interface)}.
|
package/src/context/binder.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { Binder } from "../binder.js";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
ComponentContext,
|
|
4
|
+
createNamedContext,
|
|
5
|
+
useContext,
|
|
6
|
+
} from "../context.js";
|
|
3
7
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
4
8
|
import type { Output } from "../components/Output.js";
|
|
5
9
|
|
|
@@ -7,7 +11,8 @@ import type { Output } from "../components/Output.js";
|
|
|
7
11
|
* The binder context provides the binder instance to all components. This
|
|
8
12
|
* context is provided by the {@link Output | output component}.
|
|
9
13
|
*/
|
|
10
|
-
export const BinderContext: ComponentContext<Binder> =
|
|
14
|
+
export const BinderContext: ComponentContext<Binder> =
|
|
15
|
+
createNamedContext("Binder");
|
|
11
16
|
|
|
12
17
|
export function useBinder() {
|
|
13
18
|
return useContext(BinderContext)!;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { OutputSymbol } from "../binder.js";
|
|
2
|
-
import { ComponentContext,
|
|
2
|
+
import { ComponentContext, createNamedContext } from "../context.js";
|
|
3
3
|
|
|
4
4
|
export const DeclarationContext: ComponentContext<OutputSymbol> =
|
|
5
|
-
|
|
5
|
+
createNamedContext("Declaration");
|
package/src/context/indent.ts
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
import { IndentState } from "../components/Indent.jsx";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
ComponentContext,
|
|
4
|
+
createContext,
|
|
5
|
+
createNamedContext,
|
|
6
|
+
} from "../context.js";
|
|
3
7
|
|
|
4
|
-
export const IndentContext: ComponentContext<IndentState> =
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
export const IndentContext: ComponentContext<IndentState> = createNamedContext(
|
|
9
|
+
"Indent",
|
|
10
|
+
{
|
|
11
|
+
level: 0,
|
|
12
|
+
indent: " ",
|
|
13
|
+
indentString: "",
|
|
14
|
+
},
|
|
15
|
+
);
|
|
9
16
|
|
|
10
17
|
export const TestContext: ComponentContext<string> = createContext("test");
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { OutputSymbol } from "../binder.js";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
ComponentContext,
|
|
4
|
+
createNamedContext,
|
|
5
|
+
useContext,
|
|
6
|
+
} from "../context.js";
|
|
3
7
|
|
|
4
8
|
/**
|
|
5
9
|
* Provides the symbol for the member currently being declared.
|
|
@@ -7,4 +11,8 @@ import { ComponentContext, createContext } from "../context.js";
|
|
|
7
11
|
* @see {@link DeclarationContext} for getting the symbol for the current non-member declaration.
|
|
8
12
|
*/
|
|
9
13
|
export const MemberDeclarationContext: ComponentContext<OutputSymbol> =
|
|
10
|
-
|
|
14
|
+
createNamedContext("MemberDeclaration");
|
|
15
|
+
|
|
16
|
+
export function useMemberDeclaration() {
|
|
17
|
+
return useContext(MemberDeclarationContext);
|
|
18
|
+
}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { OutputScope } from "../binder.js";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
ComponentContext,
|
|
4
|
+
createNamedContext,
|
|
5
|
+
useContext,
|
|
6
|
+
} from "../context.js";
|
|
3
7
|
|
|
4
8
|
/**
|
|
5
9
|
* The member scope context provides the instance and static member scopes that
|
|
@@ -10,7 +14,7 @@ export interface MemberScopeContext {
|
|
|
10
14
|
instanceMembers?: OutputScope;
|
|
11
15
|
}
|
|
12
16
|
export const MemberScopeContext: ComponentContext<MemberScopeContext> =
|
|
13
|
-
|
|
17
|
+
createNamedContext("MemberScope");
|
|
14
18
|
|
|
15
19
|
export function useMemberScope() {
|
|
16
20
|
return useContext(MemberScopeContext)!;
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
ComponentContext,
|
|
3
|
+
createNamedContext,
|
|
4
|
+
useContext,
|
|
5
|
+
} from "../context.js";
|
|
2
6
|
import { NamePolicy } from "../name-policy.js";
|
|
3
7
|
|
|
4
8
|
export const NamePolicyContext: ComponentContext<NamePolicy<string>> =
|
|
5
|
-
|
|
9
|
+
createNamedContext<NamePolicy<string>>("NamePolicy", {
|
|
6
10
|
getName(name) {
|
|
7
11
|
return name;
|
|
8
12
|
},
|
package/src/context/scope.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { OutputScope } from "../binder.js";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
ComponentContext,
|
|
4
|
+
createNamedContext,
|
|
5
|
+
useContext,
|
|
6
|
+
} from "../context.js";
|
|
3
7
|
|
|
4
|
-
export const ScopeContext: ComponentContext<OutputScope> =
|
|
8
|
+
export const ScopeContext: ComponentContext<OutputScope> =
|
|
9
|
+
createNamedContext("Scope");
|
|
5
10
|
|
|
6
11
|
export function useScope() {
|
|
7
12
|
return useContext(ScopeContext)!;
|