@alloy-js/core 0.21.0-dev.1 → 0.21.0-dev.10
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/pretty-string/pretty-string.d.ts +47 -0
- package/dist/src/pretty-string/pretty-string.d.ts.map +1 -0
- package/dist/src/pretty-string/pretty-string.js +100 -0
- package/dist/src/pretty-string/pretty-string.js.map +1 -0
- package/dist/src/pretty-string/pretty-string.test.d.ts +2 -0
- package/dist/src/pretty-string/pretty-string.test.d.ts.map +1 -0
- package/dist/src/pretty-string/pretty-string.test.js +38 -0
- package/dist/src/pretty-string/pretty-string.test.js.map +1 -0
- package/dist/src/refkey.d.ts +12 -8
- package/dist/src/refkey.d.ts.map +1 -1
- package/dist/src/refkey.js +40 -12
- package/dist/src/refkey.js.map +1 -1
- package/dist/src/render.d.ts.map +1 -1
- package/dist/src/render.js +10 -4
- package/dist/src/render.js.map +1 -1
- package/dist/src/runtime/component.d.ts +22 -2
- package/dist/src/runtime/component.d.ts.map +1 -1
- package/dist/src/runtime/component.js +18 -0
- 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/src/tracer.d.ts.map +1 -1
- package/dist/src/tracer.js +2 -2
- package/dist/src/tracer.js.map +1 -1
- package/dist/test/refkey.test.js +11 -1
- package/dist/test/refkey.test.js.map +1 -1
- package/dist/test/rendering/basic.test.js +22 -0
- package/dist/test/rendering/basic.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/pretty-string/pretty-string.test.ts +47 -0
- package/src/pretty-string/pretty-string.ts +130 -0
- package/src/refkey.ts +67 -26
- package/src/render.ts +11 -3
- package/src/runtime/component.ts +33 -1
- package/src/symbols/output-symbol.ts +40 -0
- package/src/tracer.ts +2 -5
- package/temp/api.json +728 -86
- package/test/refkey.test.ts +12 -1
- package/test/rendering/basic.test.tsx +35 -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
package/test/refkey.test.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { expect, it } from "vitest";
|
|
2
|
-
import { refkey } from "../src/refkey.js";
|
|
2
|
+
import { refkey, REFKEYABLE, Refkeyable } from "../src/refkey.js";
|
|
3
3
|
|
|
4
4
|
it("is stable when called with same values", () => {
|
|
5
5
|
const obj = {};
|
|
@@ -30,3 +30,14 @@ it("can be called with no args and returns a fresh key", () => {
|
|
|
30
30
|
const key2 = refkey();
|
|
31
31
|
expect(key1).not.toBe(key2);
|
|
32
32
|
});
|
|
33
|
+
|
|
34
|
+
it("unwraps refkeyables", () => {
|
|
35
|
+
const obj = {};
|
|
36
|
+
const rk1 = refkey(obj);
|
|
37
|
+
const refkeyable: Refkeyable = {
|
|
38
|
+
[REFKEYABLE]() {
|
|
39
|
+
return rk1;
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
expect(refkey(refkeyable)).toBe(rk1);
|
|
43
|
+
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { Children } from "../../src/runtime/component.js";
|
|
2
|
+
import { Children, RENDERABLE } from "../../src/runtime/component.js";
|
|
3
3
|
import "../../testing/extend-expect.js";
|
|
4
4
|
describe("string nodes", () => {
|
|
5
5
|
it("renders string nodes with substitutions", () => {
|
|
@@ -49,6 +49,40 @@ describe("component nodes", () => {
|
|
|
49
49
|
</>,
|
|
50
50
|
).toRenderTo("Str Str");
|
|
51
51
|
});
|
|
52
|
+
|
|
53
|
+
it("renders custom elements", () => {
|
|
54
|
+
const customElement = {
|
|
55
|
+
[RENDERABLE]() {
|
|
56
|
+
return (
|
|
57
|
+
<>
|
|
58
|
+
<Str /> <Str />
|
|
59
|
+
</>
|
|
60
|
+
);
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
expect(customElement).toRenderTo("Str Str");
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("renders nested custom elements", () => {
|
|
68
|
+
const e1 = {
|
|
69
|
+
[RENDERABLE]() {
|
|
70
|
+
return <Str />;
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const e2 = {
|
|
75
|
+
[RENDERABLE]() {
|
|
76
|
+
return (
|
|
77
|
+
<>
|
|
78
|
+
{e1} {e1}
|
|
79
|
+
</>
|
|
80
|
+
);
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
expect(e2).toRenderTo("Str Str");
|
|
85
|
+
});
|
|
52
86
|
});
|
|
53
87
|
|
|
54
88
|
describe("memo nodes", () => {
|
|
@@ -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