@alloy-js/core 0.21.0-dev.3 → 0.21.0-dev.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/binder.d.ts +3 -3
- package/dist/src/binder.d.ts.map +1 -1
- package/dist/src/binder.js +18 -4
- package/dist/src/binder.js.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/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/library-symbol-reference.d.ts +8 -0
- package/dist/src/library-symbol-reference.d.ts.map +1 -0
- package/dist/src/library-symbol-reference.js +5 -0
- package/dist/src/library-symbol-reference.js.map +1 -0
- package/dist/src/refkey.d.ts +10 -8
- package/dist/src/refkey.d.ts.map +1 -1
- package/dist/src/refkey.js +34 -13
- package/dist/src/refkey.js.map +1 -1
- package/dist/src/render.d.ts.map +1 -1
- package/dist/src/render.js +4 -3
- package/dist/src/render.js.map +1 -1
- package/dist/src/runtime/component.d.ts +2 -2
- package/dist/src/runtime/component.d.ts.map +1 -1
- package/dist/src/runtime/component.js.map +1 -1
- package/dist/src/symbols/output-symbol.d.ts +9 -0
- package/dist/src/symbols/output-symbol.d.ts.map +1 -1
- package/dist/src/symbols/output-symbol.js +30 -0
- package/dist/src/symbols/output-symbol.js.map +1 -1
- package/dist/test/refkey.test.js +11 -1
- package/dist/test/refkey.test.js.map +1 -1
- package/dist/test/symbols/output-scope.test.js +4 -3
- package/dist/test/symbols/output-scope.test.js.map +1 -1
- package/dist/test/symbols/resolution.test.js +29 -1
- package/dist/test/symbols/resolution.test.js.map +1 -1
- package/dist/testing/create-test-wrapper.d.ts +22 -0
- package/dist/testing/create-test-wrapper.d.ts.map +1 -0
- package/dist/testing/create-test-wrapper.js +60 -0
- package/dist/testing/create-test-wrapper.js.map +1 -0
- package/dist/testing/index.d.ts +1 -0
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js +1 -0
- package/dist/testing/index.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/binder.ts +34 -6
- package/src/index.ts +1 -0
- package/src/library-symbol-reference.ts +20 -0
- package/src/refkey.ts +57 -29
- package/src/render.ts +4 -3
- package/src/runtime/component.ts +2 -1
- package/src/symbols/output-symbol.ts +40 -0
- package/temp/api.json +447 -45
- package/test/refkey.test.ts +12 -1
- package/test/symbols/output-scope.test.ts +4 -4
- package/test/symbols/resolution.test.ts +42 -1
- package/testing/create-test-wrapper.tsx +70 -0
- package/testing/index.ts +1 -0
- package/tsconfig.json +1 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { reactive, watch } from "@vue/reactivity";
|
|
2
2
|
import { describe, expect, it, vi } from "vitest";
|
|
3
|
-
import {
|
|
3
|
+
import { refkey } from "../../src/refkey.js";
|
|
4
4
|
import { flushJobs } from "../../src/scheduler.js";
|
|
5
5
|
import { BasicScope } from "../../src/symbols/basic-scope.js";
|
|
6
6
|
import { SymbolTable } from "../../src/symbols/symbol-table.js";
|
|
@@ -168,9 +168,9 @@ describe("OutputScope#symbolsByRefkey", () => {
|
|
|
168
168
|
|
|
169
169
|
// Use the refkey function to create refkeys
|
|
170
170
|
// This is based on how refkey is being imported in binder.ts
|
|
171
|
-
const key1 =
|
|
172
|
-
const key2a =
|
|
173
|
-
const key2b =
|
|
171
|
+
const key1 = refkey();
|
|
172
|
+
const key2a = refkey();
|
|
173
|
+
const key2b = refkey();
|
|
174
174
|
|
|
175
175
|
// Create a symbol with a refkey
|
|
176
176
|
const [sym1] = createSymbol("sym1", scope, {
|
|
@@ -447,6 +447,47 @@ describe("resolving type members by refkey", () => {
|
|
|
447
447
|
expect(result.memberPath).toEqual([staticProp]);
|
|
448
448
|
});
|
|
449
449
|
|
|
450
|
+
it("string member", () => {
|
|
451
|
+
const globalScope = createScope("global");
|
|
452
|
+
const [typeSymbol, typeKey] = createSymbol("MyType", globalScope);
|
|
453
|
+
const [staticProp] = createSymbol("staticProp", typeSymbol.staticMembers);
|
|
454
|
+
|
|
455
|
+
// resolve a member of type
|
|
456
|
+
const result = binder.resolveDeclarationByKey(
|
|
457
|
+
globalScope,
|
|
458
|
+
memberRefkey(typeKey, "staticProp"),
|
|
459
|
+
).value!;
|
|
460
|
+
|
|
461
|
+
expect(result.symbol).toBe(staticProp);
|
|
462
|
+
expect(result.lexicalDeclaration).toBe(typeSymbol);
|
|
463
|
+
expect(result.memberPath).toEqual([staticProp]);
|
|
464
|
+
});
|
|
465
|
+
|
|
466
|
+
it("string member when member symbol changes", async () => {
|
|
467
|
+
const globalScope = createScope("global");
|
|
468
|
+
const [typeSymbol, typeKey] = createSymbol("MyType", globalScope);
|
|
469
|
+
const [staticProp] = createSymbol("staticProp", typeSymbol.staticMembers);
|
|
470
|
+
|
|
471
|
+
// resolve a member of type
|
|
472
|
+
const result = binder.resolveDeclarationByKey(
|
|
473
|
+
globalScope,
|
|
474
|
+
memberRefkey(typeKey, "staticProp"),
|
|
475
|
+
);
|
|
476
|
+
|
|
477
|
+
expect(result.value!.symbol).toBe(staticProp);
|
|
478
|
+
expect(result.value!.lexicalDeclaration).toBe(typeSymbol);
|
|
479
|
+
expect(result.value!.memberPath).toEqual([staticProp]);
|
|
480
|
+
|
|
481
|
+
staticProp.delete();
|
|
482
|
+
|
|
483
|
+
expect(result.value).toBe(undefined);
|
|
484
|
+
|
|
485
|
+
const [staticProp2] = createSymbol("staticProp", typeSymbol.staticMembers);
|
|
486
|
+
expect(result.value!.symbol).toBe(staticProp2);
|
|
487
|
+
expect(result.value!.lexicalDeclaration).toBe(typeSymbol);
|
|
488
|
+
expect(result.value!.memberPath).toEqual([staticProp2]);
|
|
489
|
+
});
|
|
490
|
+
|
|
450
491
|
it("nested member", () => {
|
|
451
492
|
const globalScope = createScope("global");
|
|
452
493
|
const [typeSymbol, typeKey] = createSymbol("MyType", globalScope);
|
|
@@ -472,7 +513,7 @@ describe("resolving type members by refkey", () => {
|
|
|
472
513
|
// resolve from a member refkey
|
|
473
514
|
const result2 = binder.resolveDeclarationByKey(
|
|
474
515
|
globalScope,
|
|
475
|
-
memberRefkey(
|
|
516
|
+
memberRefkey(typeKey, staticPropKey, nestedKey),
|
|
476
517
|
).value!;
|
|
477
518
|
|
|
478
519
|
expect(result2.symbol).toBe(nestedProp);
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Children,
|
|
3
|
+
Declaration,
|
|
4
|
+
For,
|
|
5
|
+
Namekey,
|
|
6
|
+
namekey,
|
|
7
|
+
Output,
|
|
8
|
+
OutputSymbol,
|
|
9
|
+
shallowReactive,
|
|
10
|
+
} from "@alloy-js/core";
|
|
11
|
+
|
|
12
|
+
export interface TestWrapper {
|
|
13
|
+
Wrapper: (props: { children: Children }) => Children;
|
|
14
|
+
defkey: (name: string) => Namekey;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Generic test wrapper creator.
|
|
19
|
+
*/
|
|
20
|
+
export function createTestWrapper<
|
|
21
|
+
SymbolT extends OutputSymbol,
|
|
22
|
+
ScopeT extends { spaces: any },
|
|
23
|
+
>(opts: {
|
|
24
|
+
filePath: string;
|
|
25
|
+
useScope: () => ScopeT | undefined;
|
|
26
|
+
makeSymbol: (nk: Namekey, scope: ScopeT) => SymbolT;
|
|
27
|
+
SourceFile: (props: { path: string; children: Children }) => any;
|
|
28
|
+
}): TestWrapper {
|
|
29
|
+
const seen = shallowReactive(new Map<string, Namekey>());
|
|
30
|
+
const created = new Map<Namekey, SymbolT>();
|
|
31
|
+
|
|
32
|
+
function defkey(name: string): Namekey {
|
|
33
|
+
const existing = seen.get(name);
|
|
34
|
+
if (existing) return existing;
|
|
35
|
+
const nk = namekey(name, {
|
|
36
|
+
ignoreNamePolicy: true,
|
|
37
|
+
ignoreNameConflict: true,
|
|
38
|
+
});
|
|
39
|
+
seen.set(name, nk);
|
|
40
|
+
return nk;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function createSymbol(nk: Namekey) {
|
|
44
|
+
const existing = created.get(nk);
|
|
45
|
+
if (existing) return existing;
|
|
46
|
+
const scope = opts.useScope();
|
|
47
|
+
if (!scope) {
|
|
48
|
+
throw new Error(`No SourceFile scope when declaring symbol: ${nk.name}`);
|
|
49
|
+
}
|
|
50
|
+
const sym = opts.makeSymbol(nk, scope);
|
|
51
|
+
created.set(nk, sym);
|
|
52
|
+
return sym;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function Wrapper(props: { children: Children }) {
|
|
56
|
+
const SF = opts.SourceFile;
|
|
57
|
+
return (
|
|
58
|
+
<Output>
|
|
59
|
+
<SF path={opts.filePath}>
|
|
60
|
+
<For each={[...seen.values()]} joiner="">
|
|
61
|
+
{(nk) => <Declaration symbol={createSymbol(nk)} />}
|
|
62
|
+
</For>
|
|
63
|
+
{props.children}
|
|
64
|
+
</SF>
|
|
65
|
+
</Output>
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return { Wrapper, defkey } as const;
|
|
70
|
+
}
|
package/testing/index.ts
CHANGED