@alloy-js/core 0.2.0 → 0.4.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 +18 -0
- package/dist/src/binder.d.ts +28 -5
- package/dist/src/binder.d.ts.map +1 -1
- package/dist/src/binder.js +107 -7
- package/dist/src/binder.js.map +1 -1
- package/dist/src/components/Declaration.d.ts +1 -1
- 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 +1 -1
- 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 +1 -1
- package/dist/src/components/MemberDeclaration.d.ts.map +1 -1
- package/dist/src/components/MemberDeclaration.js.map +1 -1
- package/dist/src/components/MemberScope.d.ts +1 -1
- package/dist/src/components/MemberScope.d.ts.map +1 -1
- 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 +5 -3
- package/dist/src/components/Output.js.map +1 -1
- package/dist/src/components/Scope.d.ts +1 -1
- 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 +1 -1
- 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 +16 -1
- package/dist/src/components/SourceFile.d.ts.map +1 -1
- package/dist/src/components/SourceFile.js +14 -2
- package/dist/src/components/SourceFile.js.map +1 -1
- 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.map +1 -1
- package/dist/src/context/member-declaration.js +2 -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 +2 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +2 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/jsx-runtime.d.ts +6 -2
- package/dist/src/jsx-runtime.d.ts.map +1 -1
- package/dist/src/jsx-runtime.js +8 -6
- 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 +3 -3
- 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/utils.d.ts +2 -7
- 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 +8 -5
- package/src/binder.ts +181 -6
- 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 +3 -2
- package/src/components/Scope.tsx +1 -1
- package/src/components/SourceDirectory.tsx +1 -1
- package/src/components/SourceFile.tsx +28 -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 +2 -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 +2 -1
- package/src/jsx-runtime.ts +19 -8
- package/src/render.ts +8 -8
- package/src/slot.ts +90 -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 +589 -56
- package/test/components/slot.test.tsx +172 -0
- package/test/components/source-file.test.tsx +28 -0
- package/test/rendering/basic.test.tsx +1 -1
- package/test/symbols.test.ts +102 -0
- package/testing/render.ts +1 -1
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { it } from "vitest";
|
|
2
|
+
import { Output } from "../../src/components/Output.jsx";
|
|
3
|
+
import { SourceFile } from "../../src/components/SourceFile.jsx";
|
|
4
|
+
import {
|
|
5
|
+
Declaration,
|
|
6
|
+
Name,
|
|
7
|
+
OutputSymbol,
|
|
8
|
+
Ref,
|
|
9
|
+
refkey,
|
|
10
|
+
Scope,
|
|
11
|
+
useBinder,
|
|
12
|
+
} from "../../src/index.js";
|
|
13
|
+
import { render } from "../../src/render.js";
|
|
14
|
+
import { defineSlot, rename, replace } from "../../src/slot.js";
|
|
15
|
+
import "../../testing/extend-expect.js";
|
|
16
|
+
|
|
17
|
+
it("works with string keys", () => {
|
|
18
|
+
interface FunctionSlotProps extends FunctionComponentProps {
|
|
19
|
+
additionalProp: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const FunctionSlot = defineSlot<FunctionSlotProps>(
|
|
23
|
+
(query: { name: string }) => query.name,
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
interface FunctionComponentProps {
|
|
27
|
+
name: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function MyFunctionComponent(props: FunctionComponentProps) {
|
|
31
|
+
const FunctionSlotInstance = FunctionSlot.create(
|
|
32
|
+
props.name,
|
|
33
|
+
{ ...props, additionalProp: "hi" },
|
|
34
|
+
<>
|
|
35
|
+
function {props.name}() {"{"}
|
|
36
|
+
console.log("hello world");
|
|
37
|
+
{"}"}
|
|
38
|
+
</>,
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
return <FunctionSlotInstance />;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// extension.tsx
|
|
45
|
+
replace(FunctionSlot.find({ name: "foo" }), (props: any) => {
|
|
46
|
+
return <>
|
|
47
|
+
// original
|
|
48
|
+
{ props.original }
|
|
49
|
+
</>;
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const tree = render(
|
|
53
|
+
<Output>
|
|
54
|
+
<SourceFile path="test.ts" filetype="ts">
|
|
55
|
+
<MyFunctionComponent name="foo" />
|
|
56
|
+
</SourceFile>
|
|
57
|
+
</Output>,
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
console.log(tree.contents[0].contents);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("works with symbols", () => {
|
|
64
|
+
interface FunctionSlotProps extends FunctionComponentProps {
|
|
65
|
+
additionalProp: string;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const FunctionSlot = defineSlot<FunctionSlotProps>((query: {
|
|
69
|
+
fqn: string;
|
|
70
|
+
}) => {
|
|
71
|
+
const binder = useBinder();
|
|
72
|
+
return binder.resolveFQN(query.fqn);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
interface FunctionComponentProps {
|
|
76
|
+
name: string;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function MyFunctionComponent(props: FunctionComponentProps) {
|
|
80
|
+
const binder = useBinder();
|
|
81
|
+
const sym = binder.createSymbol({
|
|
82
|
+
name: props.name,
|
|
83
|
+
refkey: refkey(),
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
const FunctionSlotInstance = FunctionSlot.create(
|
|
87
|
+
sym,
|
|
88
|
+
{ ...props, additionalProp: "hi" },
|
|
89
|
+
<Declaration symbol={sym}>
|
|
90
|
+
function <Name />() {"{"}
|
|
91
|
+
console.log("hello world");
|
|
92
|
+
{"}"}
|
|
93
|
+
</Declaration>,
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
return <FunctionSlotInstance />;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// extension.tsx
|
|
100
|
+
replace(FunctionSlot.find({ fqn: "foo.bar" }), (props: any) => {
|
|
101
|
+
return <>
|
|
102
|
+
// original
|
|
103
|
+
{ props.original }
|
|
104
|
+
</>;
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
const tree = render(
|
|
108
|
+
<Output>
|
|
109
|
+
<SourceFile path="test.ts" filetype="ts">
|
|
110
|
+
<Scope name="foo">
|
|
111
|
+
<MyFunctionComponent name="bar" />
|
|
112
|
+
</Scope>
|
|
113
|
+
</SourceFile>
|
|
114
|
+
</Output>,
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
console.log(tree.contents[0].contents);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it("can rename", () => {
|
|
121
|
+
interface FunctionSlotProps extends FunctionComponentProps {
|
|
122
|
+
additionalProp: string;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const FunctionSlot = defineSlot<FunctionSlotProps>((query: {
|
|
126
|
+
fqn: string;
|
|
127
|
+
}) => {
|
|
128
|
+
const binder = useBinder();
|
|
129
|
+
return binder.resolveFQN(query.fqn);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
interface FunctionComponentProps {
|
|
133
|
+
name: string;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function MyFunctionComponent(props: FunctionComponentProps) {
|
|
137
|
+
const binder = useBinder();
|
|
138
|
+
const sym = binder.createSymbol({
|
|
139
|
+
name: props.name,
|
|
140
|
+
refkey: refkey(),
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
const FunctionSlotInstance = FunctionSlot.create(
|
|
144
|
+
sym,
|
|
145
|
+
{ ...props, additionalProp: "hi" },
|
|
146
|
+
<Declaration symbol={sym}>
|
|
147
|
+
function <Name />() {"{"}
|
|
148
|
+
console.log("hello world");
|
|
149
|
+
{"}"}
|
|
150
|
+
</Declaration>,
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
return <FunctionSlotInstance />;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
rename(() => {
|
|
157
|
+
const binder = useBinder();
|
|
158
|
+
return binder.resolveFQN("foo.bar") as Ref<OutputSymbol | undefined>;
|
|
159
|
+
}, "bazxxx");
|
|
160
|
+
|
|
161
|
+
const tree = render(
|
|
162
|
+
<Output>
|
|
163
|
+
<SourceFile path="test.ts" filetype="ts">
|
|
164
|
+
<Scope name="foo">
|
|
165
|
+
<MyFunctionComponent name="bar" />
|
|
166
|
+
</Scope>
|
|
167
|
+
</SourceFile>
|
|
168
|
+
</Output>,
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
console.log(tree.contents[0].contents);
|
|
172
|
+
});
|
|
@@ -43,3 +43,31 @@ it("has reactive context", () => {
|
|
|
43
43
|
|
|
44
44
|
expect(tree.contents[1].contents).toEqual("hi.txt contents.txt");
|
|
45
45
|
});
|
|
46
|
+
|
|
47
|
+
it("can change its indent level", () => {
|
|
48
|
+
function Nested() {
|
|
49
|
+
return <>
|
|
50
|
+
base
|
|
51
|
+
indented
|
|
52
|
+
</>;
|
|
53
|
+
}
|
|
54
|
+
expect(
|
|
55
|
+
<Output>
|
|
56
|
+
<SourceFile path="hi.txt" filetype="text" indent=" ">
|
|
57
|
+
hello
|
|
58
|
+
there
|
|
59
|
+
|
|
60
|
+
<Nested />
|
|
61
|
+
<Nested />
|
|
62
|
+
</SourceFile>
|
|
63
|
+
</Output>,
|
|
64
|
+
).toRenderTo(`
|
|
65
|
+
hello
|
|
66
|
+
there
|
|
67
|
+
|
|
68
|
+
base
|
|
69
|
+
indented
|
|
70
|
+
base
|
|
71
|
+
indented
|
|
72
|
+
`);
|
|
73
|
+
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Children } from "@alloy-js/core/jsx-runtime";
|
|
2
1
|
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { Children } from "../../src/jsx-runtime.js";
|
|
3
3
|
import "../../testing/extend-expect.js";
|
|
4
4
|
describe("string nodes", () => {
|
|
5
5
|
it("renders string nodes", () => {
|
package/test/symbols.test.ts
CHANGED
|
@@ -404,3 +404,105 @@ describe("instantiating members", () => {
|
|
|
404
404
|
).toBeDefined();
|
|
405
405
|
});
|
|
406
406
|
});
|
|
407
|
+
|
|
408
|
+
describe("symbol name resolution", () => {
|
|
409
|
+
it("resolves static symbols", () => {
|
|
410
|
+
const binder = createOutputBinder();
|
|
411
|
+
const {
|
|
412
|
+
symbols: { static: staticSym },
|
|
413
|
+
} = createScopeTree(binder, {
|
|
414
|
+
root: {
|
|
415
|
+
symbols: {
|
|
416
|
+
root: {
|
|
417
|
+
flags:
|
|
418
|
+
OutputSymbolFlags.InstanceMemberContainer |
|
|
419
|
+
OutputSymbolFlags.StaticMemberContainer,
|
|
420
|
+
staticMembers: {
|
|
421
|
+
static: {
|
|
422
|
+
flags: OutputSymbolFlags.StaticMember,
|
|
423
|
+
},
|
|
424
|
+
},
|
|
425
|
+
},
|
|
426
|
+
},
|
|
427
|
+
},
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
const result = binder.resolveFQN("root.root.static");
|
|
431
|
+
expect(result.value).toEqual(staticSym);
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
it("resolves static symbols that are added later", () => {
|
|
435
|
+
const binder = createOutputBinder();
|
|
436
|
+
const result = binder.resolveFQN("root.root.static");
|
|
437
|
+
expect(result.value).toBeUndefined();
|
|
438
|
+
|
|
439
|
+
const {
|
|
440
|
+
symbols: { static: staticSym },
|
|
441
|
+
} = createScopeTree(binder, {
|
|
442
|
+
root: {
|
|
443
|
+
symbols: {
|
|
444
|
+
root: {
|
|
445
|
+
flags:
|
|
446
|
+
OutputSymbolFlags.InstanceMemberContainer |
|
|
447
|
+
OutputSymbolFlags.StaticMemberContainer,
|
|
448
|
+
staticMembers: {
|
|
449
|
+
static: {
|
|
450
|
+
flags: OutputSymbolFlags.StaticMember,
|
|
451
|
+
},
|
|
452
|
+
},
|
|
453
|
+
},
|
|
454
|
+
},
|
|
455
|
+
},
|
|
456
|
+
});
|
|
457
|
+
|
|
458
|
+
expect(result.value).toEqual(staticSym);
|
|
459
|
+
});
|
|
460
|
+
|
|
461
|
+
it("resolves instance symbols", () => {
|
|
462
|
+
const binder = createOutputBinder();
|
|
463
|
+
const {
|
|
464
|
+
symbols: { instance },
|
|
465
|
+
} = createScopeTree(binder, {
|
|
466
|
+
root: {
|
|
467
|
+
symbols: {
|
|
468
|
+
root: {
|
|
469
|
+
flags: OutputSymbolFlags.InstanceMemberContainer,
|
|
470
|
+
instanceMembers: {
|
|
471
|
+
instance: {
|
|
472
|
+
flags: OutputSymbolFlags.InstanceMember,
|
|
473
|
+
},
|
|
474
|
+
},
|
|
475
|
+
},
|
|
476
|
+
},
|
|
477
|
+
},
|
|
478
|
+
});
|
|
479
|
+
|
|
480
|
+
const result = binder.resolveFQN("root.root#instance");
|
|
481
|
+
expect(result.value).toEqual(instance);
|
|
482
|
+
});
|
|
483
|
+
|
|
484
|
+
it("resolves instance symbols that are added later", () => {
|
|
485
|
+
const binder = createOutputBinder();
|
|
486
|
+
const result = binder.resolveFQN("root.root#instance");
|
|
487
|
+
expect(result.value).toBeUndefined();
|
|
488
|
+
|
|
489
|
+
const {
|
|
490
|
+
symbols: { instance },
|
|
491
|
+
} = createScopeTree(binder, {
|
|
492
|
+
root: {
|
|
493
|
+
symbols: {
|
|
494
|
+
root: {
|
|
495
|
+
flags: OutputSymbolFlags.InstanceMemberContainer,
|
|
496
|
+
instanceMembers: {
|
|
497
|
+
instance: {
|
|
498
|
+
flags: OutputSymbolFlags.InstanceMember,
|
|
499
|
+
},
|
|
500
|
+
},
|
|
501
|
+
},
|
|
502
|
+
},
|
|
503
|
+
},
|
|
504
|
+
});
|
|
505
|
+
|
|
506
|
+
expect(result.value).toEqual(instance);
|
|
507
|
+
});
|
|
508
|
+
});
|
package/testing/render.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RenderTextTree, renderTree } from "@alloy-js/core";
|
|
2
|
-
import { Children } from "
|
|
2
|
+
import { Children } from "../src/jsx-runtime.js";
|
|
3
3
|
|
|
4
4
|
export function printTree(tree: RenderTextTree) {
|
|
5
5
|
return (tree as any).flat(Infinity).join("");
|