@alloy-js/core 0.10.0 → 0.12.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 +28 -0
- package/dist/src/binder.d.ts.map +1 -1
- package/dist/src/binder.js +100 -19
- package/dist/src/code.js +1 -2
- package/dist/src/components/Block.js +2 -5
- package/dist/src/components/Declaration.js +2 -4
- package/dist/src/components/For.d.ts +2 -2
- package/dist/src/components/For.d.ts.map +1 -1
- package/dist/src/components/For.js +1 -2
- package/dist/src/components/Indent.js +2 -4
- package/dist/src/components/List.js +2 -5
- package/dist/src/components/MemberDeclaration.js +2 -4
- package/dist/src/components/MemberName.js +1 -2
- package/dist/src/components/MemberScope.js +2 -4
- package/dist/src/components/Name.js +1 -2
- package/dist/src/components/Output.js +2 -4
- package/dist/src/components/Prose.js +1 -2
- package/dist/src/components/ReferenceOrContent.d.ts +8 -0
- package/dist/src/components/ReferenceOrContent.d.ts.map +1 -0
- package/dist/src/components/ReferenceOrContent.js +11 -0
- package/dist/src/components/Scope.js +2 -4
- package/dist/src/components/Show.js +1 -2
- package/dist/src/components/SourceDirectory.js +2 -4
- package/dist/src/components/SourceFile.js +2 -5
- package/dist/src/components/StatementList.js +2 -4
- package/dist/src/components/Switch.d.ts +1 -1
- package/dist/src/components/Switch.d.ts.map +1 -1
- package/dist/src/components/Switch.js +1 -2
- package/dist/src/components/Wrap.js +2 -4
- package/dist/src/components/index.d.ts +1 -0
- package/dist/src/components/index.d.ts.map +1 -1
- package/dist/src/components/index.js +2 -2
- package/dist/src/components/stc/index.d.ts +1 -0
- package/dist/src/components/stc/index.d.ts.map +1 -1
- package/dist/src/components/stc/index.js +2 -2
- package/dist/src/components/stc/sti.js +1 -2
- package/dist/src/context/assignment.js +1 -2
- package/dist/src/context/binder.js +1 -2
- package/dist/src/context/declaration.js +1 -2
- package/dist/src/context/index.js +1 -2
- package/dist/src/context/member-declaration.js +1 -2
- package/dist/src/context/member-scope.js +1 -2
- package/dist/src/context/name-policy.js +1 -2
- package/dist/src/context/scope.js +1 -2
- package/dist/src/context/source-directory.js +1 -2
- package/dist/src/context/source-file.js +1 -2
- package/dist/src/context.js +1 -2
- package/dist/src/debug.js +13 -15
- package/dist/src/index.browser.js +1 -2
- package/dist/src/index.js +1 -2
- package/dist/src/jsx-runtime.d.ts +1 -1
- package/dist/src/jsx-runtime.d.ts.map +1 -1
- package/dist/src/jsx-runtime.js +10 -5
- package/dist/src/name-policy.js +1 -2
- package/dist/src/refkey.js +1 -2
- package/dist/src/render.d.ts.map +1 -1
- package/dist/src/render.js +6 -2
- package/dist/src/scheduler.d.ts +8 -0
- package/dist/src/scheduler.d.ts.map +1 -0
- package/dist/src/scheduler.js +17 -0
- package/dist/src/slot.js +1 -2
- package/dist/src/stc.js +1 -2
- package/dist/src/sti.js +1 -2
- package/dist/src/tap.js +1 -2
- package/dist/src/tsdoc-metadata.json +1 -1
- package/dist/src/utils.js +2 -4
- package/dist/src/write-output.browser.js +1 -2
- package/dist/src/write-output.js +1 -2
- package/dist/test/browser-build.test.js +85 -0
- package/dist/test/children.test.js +27 -0
- package/dist/test/components/block.test.js +45 -0
- package/dist/test/components/declaration.test.js +32 -0
- package/dist/test/components/list.test.js +86 -0
- package/dist/test/components/prose.test.js +25 -0
- package/dist/test/components/reference-or-content.test.d.ts +2 -0
- package/dist/test/components/reference-or-content.test.d.ts.map +1 -0
- package/dist/test/components/reference-or-content.test.js +149 -0
- package/dist/test/components/slot.test.js +134 -0
- package/dist/test/components/source-file.test.js +64 -0
- package/dist/test/components/wrap.test.js +35 -0
- package/dist/test/control-flow/for.test.js +219 -0
- package/dist/test/control-flow/match.test.js +67 -0
- package/dist/test/control-flow/show.test.js +29 -0
- package/dist/test/name-policy.test.js +19 -0
- package/dist/test/props-with-defaults.test.js +93 -0
- package/dist/test/reactivity/circular-reactives.test.d.ts +2 -0
- package/dist/test/reactivity/circular-reactives.test.d.ts.map +1 -0
- package/dist/test/reactivity/circular-reactives.test.js +31 -0
- package/dist/test/reactivity/cleanup.test.js +82 -0
- package/dist/test/reactivity/memo.test.js +16 -0
- package/dist/test/reactivity/ref-rendering.test.js +37 -0
- package/dist/test/reactivity/test.test.js +61 -0
- package/dist/test/reactivity/untrack.test.js +26 -0
- package/dist/test/refkey.test.js +25 -0
- package/dist/test/rendering/basic.test.js +96 -0
- package/dist/test/rendering/code.test.js +55 -0
- package/dist/test/rendering/formatting.test.js +402 -0
- package/dist/test/rendering/indent.test.js +90 -0
- package/dist/test/rendering/memoization.test.js +27 -0
- package/dist/test/rendering/refkeys.test.js +32 -0
- package/dist/test/split-props.test.js +77 -0
- package/dist/test/stc.test.js +34 -0
- package/dist/test/symbols.test.js +877 -0
- package/dist/test/utils.test.d.ts.map +1 -1
- package/dist/test/utils.test.js +223 -0
- package/dist/testing/extend-expect.js +1 -2
- package/dist/testing/index.js +1 -2
- package/dist/testing/render.js +1 -2
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +14 -22
- package/src/binder.ts +100 -17
- package/src/components/For.tsx +6 -6
- package/src/components/ReferenceOrContent.tsx +22 -0
- package/src/components/index.tsx +1 -0
- package/src/components/stc/index.ts +1 -0
- package/src/debug.ts +12 -13
- package/src/jsx-runtime.ts +24 -14
- package/src/render.ts +5 -0
- package/src/scheduler.ts +24 -0
- package/temp/api.json +216 -15
- package/test/components/declaration.test.tsx +2 -0
- package/test/components/list.test.tsx +0 -1
- package/test/components/reference-or-content.test.tsx +138 -0
- package/test/control-flow/for.test.tsx +34 -4
- package/test/reactivity/circular-reactives.test.tsx +32 -0
- package/test/reactivity/cleanup.test.tsx +5 -0
- package/test/reactivity/untrack.test.ts +3 -0
- package/test/rendering/memoization.test.tsx +2 -0
- package/test/symbols.test.ts +392 -13
- package/test/utils.test.tsx +2 -0
- package/babel.config.cjs +0 -4
- package/dist/src/binder.js.map +0 -1
- package/dist/src/code.js.map +0 -1
- package/dist/src/components/Block.js.map +0 -1
- package/dist/src/components/Declaration.js.map +0 -1
- package/dist/src/components/For.js.map +0 -1
- package/dist/src/components/Indent.js.map +0 -1
- package/dist/src/components/List.js.map +0 -1
- package/dist/src/components/MemberDeclaration.js.map +0 -1
- package/dist/src/components/MemberName.js.map +0 -1
- package/dist/src/components/MemberScope.js.map +0 -1
- package/dist/src/components/Name.js.map +0 -1
- package/dist/src/components/Output.js.map +0 -1
- package/dist/src/components/Prose.js.map +0 -1
- package/dist/src/components/Scope.js.map +0 -1
- package/dist/src/components/Show.js.map +0 -1
- package/dist/src/components/SourceDirectory.js.map +0 -1
- package/dist/src/components/SourceFile.js.map +0 -1
- package/dist/src/components/StatementList.js.map +0 -1
- package/dist/src/components/Switch.js.map +0 -1
- package/dist/src/components/Wrap.js.map +0 -1
- package/dist/src/components/index.js.map +0 -1
- package/dist/src/components/stc/index.js.map +0 -1
- package/dist/src/components/stc/sti.js.map +0 -1
- package/dist/src/context/assignment.js.map +0 -1
- package/dist/src/context/binder.js.map +0 -1
- package/dist/src/context/declaration.js.map +0 -1
- package/dist/src/context/index.js.map +0 -1
- package/dist/src/context/member-declaration.js.map +0 -1
- package/dist/src/context/member-scope.js.map +0 -1
- package/dist/src/context/name-policy.js.map +0 -1
- package/dist/src/context/scope.js.map +0 -1
- package/dist/src/context/source-directory.js.map +0 -1
- package/dist/src/context/source-file.js.map +0 -1
- package/dist/src/context.js.map +0 -1
- package/dist/src/debug.js.map +0 -1
- package/dist/src/index.browser.js.map +0 -1
- package/dist/src/index.js.map +0 -1
- package/dist/src/jsx-runtime.js.map +0 -1
- package/dist/src/name-policy.js.map +0 -1
- package/dist/src/refkey.js.map +0 -1
- package/dist/src/render.js.map +0 -1
- package/dist/src/slot.js.map +0 -1
- package/dist/src/stc.js.map +0 -1
- package/dist/src/sti.js.map +0 -1
- package/dist/src/tap.js.map +0 -1
- package/dist/src/utils.js.map +0 -1
- package/dist/src/write-output.browser.js.map +0 -1
- package/dist/src/write-output.js.map +0 -1
- package/dist/testing/extend-expect.js.map +0 -1
- package/dist/testing/index.js.map +0 -1
- package/dist/testing/render.js.map +0 -1
- package/dist/testing/vitest.d.js.map +0 -1
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { createComponent as _$createComponent, createIntrinsic as _$createIntrinsic, memo as _$memo } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { expect, it } from "vitest";
|
|
3
|
+
import { List, printTree, ref, renderTree } from "../../src/index.js";
|
|
4
|
+
import "../../testing/extend-expect.js";
|
|
5
|
+
import { d } from "../../testing/render.js";
|
|
6
|
+
it("creates a list with default options", () => {
|
|
7
|
+
const template = _$createIntrinsic("group", {
|
|
8
|
+
get children() {
|
|
9
|
+
return _$createComponent(List, {
|
|
10
|
+
get children() {
|
|
11
|
+
return [["1"], ["2"], ["3"]];
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
expect(template).toRenderTo(`
|
|
17
|
+
1
|
|
18
|
+
2
|
|
19
|
+
3
|
|
20
|
+
`);
|
|
21
|
+
});
|
|
22
|
+
it("creates a list with some options", () => {
|
|
23
|
+
expect(_$createIntrinsic("group", {
|
|
24
|
+
get children() {
|
|
25
|
+
return _$createComponent(List, {
|
|
26
|
+
comma: true,
|
|
27
|
+
line: true,
|
|
28
|
+
get children() {
|
|
29
|
+
return [["1"], ["2"], ["3"]];
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
})).toRenderTo(`1, 2, 3`);
|
|
34
|
+
});
|
|
35
|
+
it("creates a list item for substitutions", () => {
|
|
36
|
+
expect(_$createIntrinsic("group", {
|
|
37
|
+
get children() {
|
|
38
|
+
return _$createComponent(List, {
|
|
39
|
+
comma: true,
|
|
40
|
+
line: true,
|
|
41
|
+
get children() {
|
|
42
|
+
return [1, 2, 3];
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
})).toRenderTo(`1, 2, 3`);
|
|
47
|
+
});
|
|
48
|
+
it("doesn't create list items for undefined, null, and boolean values", () => {
|
|
49
|
+
expect(_$createIntrinsic("group", {
|
|
50
|
+
get children() {
|
|
51
|
+
return _$createComponent(List, {
|
|
52
|
+
comma: true,
|
|
53
|
+
line: true,
|
|
54
|
+
get children() {
|
|
55
|
+
return [false, 1, true, 2, null, 3, undefined];
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
})).toRenderTo(`1, 2, 3`);
|
|
60
|
+
});
|
|
61
|
+
it("is useful for statements", () => {
|
|
62
|
+
function Statement() {
|
|
63
|
+
return "console.log(true)";
|
|
64
|
+
}
|
|
65
|
+
const includeStatement = ref(false);
|
|
66
|
+
const tree = renderTree(_$createComponent(List, {
|
|
67
|
+
semicolon: true,
|
|
68
|
+
hardline: true,
|
|
69
|
+
ender: true,
|
|
70
|
+
get children() {
|
|
71
|
+
return [_$createComponent(Statement, {}), _$memo(() => _$memo(() => !!includeStatement.value)() && _$createComponent(Statement, {})), _$createComponent(Statement, {})];
|
|
72
|
+
}
|
|
73
|
+
}));
|
|
74
|
+
expect(printTree(tree)).toEqual(d`
|
|
75
|
+
console.log(true);
|
|
76
|
+
console.log(true);
|
|
77
|
+
|
|
78
|
+
`);
|
|
79
|
+
includeStatement.value = true;
|
|
80
|
+
expect(printTree(tree)).toEqual(d`
|
|
81
|
+
console.log(true);
|
|
82
|
+
console.log(true);
|
|
83
|
+
console.log(true);
|
|
84
|
+
|
|
85
|
+
`);
|
|
86
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { createComponent as _$createComponent, createIntrinsic as _$createIntrinsic } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
import { Prose } from "../../src/components/Prose.js";
|
|
4
|
+
import "../../testing/extend-expect.js";
|
|
5
|
+
import { d } from "../../testing/render.js";
|
|
6
|
+
describe("Prose", () => {
|
|
7
|
+
it("formats properly", () => {
|
|
8
|
+
const template = [_$createComponent(Prose, {
|
|
9
|
+
children: "This is a long paragraph that should end up being broken into multiple lines."
|
|
10
|
+
}), _$createIntrinsic("hbr", {}), _$createIntrinsic("hbr", {}), _$createComponent(Prose, {
|
|
11
|
+
children: "This is another paragraph. There should be a couple breaks in front of it."
|
|
12
|
+
})];
|
|
13
|
+
expect(template).toRenderTo(d`
|
|
14
|
+
This is a long paragraph that
|
|
15
|
+
should end up being broken
|
|
16
|
+
into multiple lines.
|
|
17
|
+
|
|
18
|
+
This is another paragraph.
|
|
19
|
+
There should be a couple
|
|
20
|
+
breaks in front of it.
|
|
21
|
+
`, {
|
|
22
|
+
printWidth: 30
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reference-or-content.test.d.ts","sourceRoot":"","sources":["../../../test/components/reference-or-content.test.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { describe, expect, it, vi } from "vitest";
|
|
3
|
+
import { createTap, Declaration, List, Output, ReferenceOrContent, refkey, resolve, Scope, SourceFile, useBinder } from "../../src/index.js";
|
|
4
|
+
import { d, renderToString } from "../../testing/render.js";
|
|
5
|
+
function TestWrapper(props) {
|
|
6
|
+
const GetBinder = createTap(() => useBinder());
|
|
7
|
+
function Reference(props) {
|
|
8
|
+
const result = resolve(props.refkey);
|
|
9
|
+
return result.value.targetDeclaration.name;
|
|
10
|
+
}
|
|
11
|
+
return _$createComponent(Output, {
|
|
12
|
+
get children() {
|
|
13
|
+
return _$createComponent(SourceFile, {
|
|
14
|
+
path: "test.txt",
|
|
15
|
+
filetype: "txt",
|
|
16
|
+
reference: Reference,
|
|
17
|
+
get children() {
|
|
18
|
+
return [_$createComponent(GetBinder, {}), _$createComponent(Scope, {
|
|
19
|
+
get children() {
|
|
20
|
+
return _$createComponent(List, {
|
|
21
|
+
get children() {
|
|
22
|
+
return props.children;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
})];
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
describe("render the reference name if a declaration exists", () => {
|
|
33
|
+
it("declaration is before", () => {
|
|
34
|
+
const rk1 = refkey();
|
|
35
|
+
const template = _$createComponent(TestWrapper, {
|
|
36
|
+
get children() {
|
|
37
|
+
return [_$createComponent(Declaration, {
|
|
38
|
+
name: "A",
|
|
39
|
+
refkey: rk1,
|
|
40
|
+
children: "Declare A"
|
|
41
|
+
}), _$createComponent(ReferenceOrContent, {
|
|
42
|
+
refkey: rk1,
|
|
43
|
+
children: "No Reference A"
|
|
44
|
+
})];
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
expect(renderToString(template)).toEqual(d`
|
|
48
|
+
Declare A
|
|
49
|
+
A
|
|
50
|
+
`);
|
|
51
|
+
});
|
|
52
|
+
it("declaration is after", () => {
|
|
53
|
+
const rk1 = refkey();
|
|
54
|
+
const template = _$createComponent(TestWrapper, {
|
|
55
|
+
get children() {
|
|
56
|
+
return [_$createComponent(ReferenceOrContent, {
|
|
57
|
+
refkey: rk1,
|
|
58
|
+
children: "No Reference A"
|
|
59
|
+
}), _$createComponent(Declaration, {
|
|
60
|
+
name: "A",
|
|
61
|
+
refkey: rk1,
|
|
62
|
+
children: "Declare A"
|
|
63
|
+
})];
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
expect(renderToString(template)).toEqual(d`
|
|
67
|
+
A
|
|
68
|
+
Declare A
|
|
69
|
+
`);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
it("render content if there is not declaration attached to symbol", () => {
|
|
73
|
+
const rk1 = refkey();
|
|
74
|
+
const template = _$createComponent(TestWrapper, {
|
|
75
|
+
get children() {
|
|
76
|
+
return _$createComponent(ReferenceOrContent, {
|
|
77
|
+
refkey: rk1,
|
|
78
|
+
children: "No Reference A"
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
expect(renderToString(template)).toEqual(d`
|
|
83
|
+
No Reference A
|
|
84
|
+
`);
|
|
85
|
+
});
|
|
86
|
+
it("mixed", () => {
|
|
87
|
+
const rk1 = refkey();
|
|
88
|
+
const rk2 = refkey();
|
|
89
|
+
const template = _$createComponent(TestWrapper, {
|
|
90
|
+
get children() {
|
|
91
|
+
return [_$createComponent(Declaration, {
|
|
92
|
+
name: "A",
|
|
93
|
+
refkey: rk1,
|
|
94
|
+
children: "Declare A"
|
|
95
|
+
}), _$createComponent(ReferenceOrContent, {
|
|
96
|
+
refkey: rk1,
|
|
97
|
+
children: "No Reference A"
|
|
98
|
+
}), _$createComponent(ReferenceOrContent, {
|
|
99
|
+
refkey: rk2,
|
|
100
|
+
children: "No Reference B"
|
|
101
|
+
})];
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
expect(renderToString(template)).toEqual(d`
|
|
105
|
+
Declare A
|
|
106
|
+
A
|
|
107
|
+
No Reference B
|
|
108
|
+
`);
|
|
109
|
+
});
|
|
110
|
+
it("resolve ref via source file reference", () => {
|
|
111
|
+
const rk1 = refkey();
|
|
112
|
+
const GetBinder = createTap(() => useBinder());
|
|
113
|
+
const Reference = vi.fn(props => {
|
|
114
|
+
const result = resolve(props.refkey);
|
|
115
|
+
return `ViaRef.${result.value.targetDeclaration.name}`;
|
|
116
|
+
});
|
|
117
|
+
const template = _$createComponent(Output, {
|
|
118
|
+
get children() {
|
|
119
|
+
return _$createComponent(SourceFile, {
|
|
120
|
+
path: "test.txt",
|
|
121
|
+
filetype: "txt",
|
|
122
|
+
reference: Reference,
|
|
123
|
+
get children() {
|
|
124
|
+
return [_$createComponent(GetBinder, {}), _$createComponent(Scope, {
|
|
125
|
+
get children() {
|
|
126
|
+
return _$createComponent(List, {
|
|
127
|
+
get children() {
|
|
128
|
+
return [_$createComponent(Declaration, {
|
|
129
|
+
name: "A",
|
|
130
|
+
refkey: rk1,
|
|
131
|
+
children: "Declare A"
|
|
132
|
+
}), _$createComponent(ReferenceOrContent, {
|
|
133
|
+
refkey: rk1,
|
|
134
|
+
children: "No Reference A"
|
|
135
|
+
})];
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
})];
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
expect(renderToString(template)).toEqual(d`
|
|
145
|
+
Declare A
|
|
146
|
+
ViaRef.A
|
|
147
|
+
`);
|
|
148
|
+
expect(Reference).toHaveBeenCalledTimes(1);
|
|
149
|
+
});
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { memo as _$memo, createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { it } from "vitest";
|
|
3
|
+
import { Output } from "../../src/components/Output.js";
|
|
4
|
+
import { SourceFile } from "../../src/components/SourceFile.js";
|
|
5
|
+
import { Declaration, Name, refkey, Scope, useBinder } from "../../src/index.js";
|
|
6
|
+
import { render } from "../../src/render.js";
|
|
7
|
+
import { defineSlot, rename, replace } from "../../src/slot.js";
|
|
8
|
+
import "../../testing/extend-expect.js";
|
|
9
|
+
it("works with string keys", () => {
|
|
10
|
+
const FunctionSlot = defineSlot(query => query.name);
|
|
11
|
+
function MyFunctionComponent(props) {
|
|
12
|
+
const FunctionSlotInstance = FunctionSlot.create(props.name, {
|
|
13
|
+
...props,
|
|
14
|
+
additionalProp: "hi"
|
|
15
|
+
}, ["function ", _$memo(() => props.name), "() ", "{", "console.log(\"hello world\");", "}"]);
|
|
16
|
+
return _$createComponent(FunctionSlotInstance, {});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// extension.tsx
|
|
20
|
+
replace(FunctionSlot.find({
|
|
21
|
+
name: "foo"
|
|
22
|
+
}), props => {
|
|
23
|
+
return ["// original", _$memo(() => props.original)];
|
|
24
|
+
});
|
|
25
|
+
const tree = render(_$createComponent(Output, {
|
|
26
|
+
get children() {
|
|
27
|
+
return _$createComponent(SourceFile, {
|
|
28
|
+
path: "test.ts",
|
|
29
|
+
filetype: "ts",
|
|
30
|
+
get children() {
|
|
31
|
+
return _$createComponent(MyFunctionComponent, {
|
|
32
|
+
name: "foo"
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}));
|
|
38
|
+
console.log(tree.contents[0].contents);
|
|
39
|
+
});
|
|
40
|
+
it("works with symbols", () => {
|
|
41
|
+
const FunctionSlot = defineSlot(query => {
|
|
42
|
+
const binder = useBinder();
|
|
43
|
+
return binder.resolveFQN(query.fqn);
|
|
44
|
+
});
|
|
45
|
+
function MyFunctionComponent(props) {
|
|
46
|
+
const binder = useBinder();
|
|
47
|
+
const sym = binder.createSymbol({
|
|
48
|
+
name: props.name,
|
|
49
|
+
refkey: refkey()
|
|
50
|
+
});
|
|
51
|
+
const FunctionSlotInstance = FunctionSlot.create(sym, {
|
|
52
|
+
...props,
|
|
53
|
+
additionalProp: "hi"
|
|
54
|
+
}, _$createComponent(Declaration, {
|
|
55
|
+
symbol: sym,
|
|
56
|
+
get children() {
|
|
57
|
+
return ["function ", _$createComponent(Name, {}), "() ", "{", "console.log(\"hello world\");", "}"];
|
|
58
|
+
}
|
|
59
|
+
}));
|
|
60
|
+
return _$createComponent(FunctionSlotInstance, {});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// extension.tsx
|
|
64
|
+
replace(FunctionSlot.find({
|
|
65
|
+
fqn: "foo.bar"
|
|
66
|
+
}), props => {
|
|
67
|
+
return ["// original", _$memo(() => props.original)];
|
|
68
|
+
});
|
|
69
|
+
const tree = render(_$createComponent(Output, {
|
|
70
|
+
get children() {
|
|
71
|
+
return _$createComponent(SourceFile, {
|
|
72
|
+
path: "test.ts",
|
|
73
|
+
filetype: "ts",
|
|
74
|
+
get children() {
|
|
75
|
+
return _$createComponent(Scope, {
|
|
76
|
+
name: "foo",
|
|
77
|
+
get children() {
|
|
78
|
+
return _$createComponent(MyFunctionComponent, {
|
|
79
|
+
name: "bar"
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}));
|
|
87
|
+
console.log(tree.contents[0].contents);
|
|
88
|
+
});
|
|
89
|
+
it("can rename", () => {
|
|
90
|
+
const FunctionSlot = defineSlot(query => {
|
|
91
|
+
const binder = useBinder();
|
|
92
|
+
return binder.resolveFQN(query.fqn);
|
|
93
|
+
});
|
|
94
|
+
function MyFunctionComponent(props) {
|
|
95
|
+
const binder = useBinder();
|
|
96
|
+
const sym = binder.createSymbol({
|
|
97
|
+
name: props.name,
|
|
98
|
+
refkey: refkey()
|
|
99
|
+
});
|
|
100
|
+
const FunctionSlotInstance = FunctionSlot.create(sym, {
|
|
101
|
+
...props,
|
|
102
|
+
additionalProp: "hi"
|
|
103
|
+
}, _$createComponent(Declaration, {
|
|
104
|
+
symbol: sym,
|
|
105
|
+
get children() {
|
|
106
|
+
return ["function ", _$createComponent(Name, {}), "() ", "{", "console.log(\"hello world\");", "}"];
|
|
107
|
+
}
|
|
108
|
+
}));
|
|
109
|
+
return _$createComponent(FunctionSlotInstance, {});
|
|
110
|
+
}
|
|
111
|
+
rename(() => {
|
|
112
|
+
const binder = useBinder();
|
|
113
|
+
return binder.resolveFQN("foo.bar");
|
|
114
|
+
}, "bazxxx");
|
|
115
|
+
const tree = render(_$createComponent(Output, {
|
|
116
|
+
get children() {
|
|
117
|
+
return _$createComponent(SourceFile, {
|
|
118
|
+
path: "test.ts",
|
|
119
|
+
filetype: "ts",
|
|
120
|
+
get children() {
|
|
121
|
+
return _$createComponent(Scope, {
|
|
122
|
+
name: "foo",
|
|
123
|
+
get children() {
|
|
124
|
+
return _$createComponent(MyFunctionComponent, {
|
|
125
|
+
name: "bar"
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
}));
|
|
133
|
+
console.log(tree.contents[0].contents);
|
|
134
|
+
});
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { createComponent as _$createComponent, memo as _$memo } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { computed, Output, render, renderTree, SourceFile, useContext } from "@alloy-js/core";
|
|
3
|
+
import { expect, it } from "vitest";
|
|
4
|
+
import { SourceDirectoryContext } from "../../src/context/source-directory.js";
|
|
5
|
+
import "../../testing/extend-expect.js";
|
|
6
|
+
import { d } from "../../testing/render.js";
|
|
7
|
+
it("tracks its content", () => {
|
|
8
|
+
let context;
|
|
9
|
+
function Test() {
|
|
10
|
+
context = useContext(SourceDirectoryContext);
|
|
11
|
+
}
|
|
12
|
+
const _ = renderTree(_$createComponent(Output, {
|
|
13
|
+
get children() {
|
|
14
|
+
return [_$createComponent(Test, {}), _$createComponent(SourceFile, {
|
|
15
|
+
path: "hi.txt",
|
|
16
|
+
filetype: "text",
|
|
17
|
+
children: "hello!"
|
|
18
|
+
})];
|
|
19
|
+
}
|
|
20
|
+
}));
|
|
21
|
+
expect(context.contents.length).toEqual(1);
|
|
22
|
+
});
|
|
23
|
+
it("has reactive context", () => {
|
|
24
|
+
function TrackContents() {
|
|
25
|
+
const sdContext = useContext(SourceDirectoryContext);
|
|
26
|
+
const allFiles = computed(() => {
|
|
27
|
+
return sdContext.contents.map(v => v.path).join(" ");
|
|
28
|
+
});
|
|
29
|
+
return _$createComponent(SourceFile, {
|
|
30
|
+
path: "contents.txt",
|
|
31
|
+
filetype: "text",
|
|
32
|
+
get children() {
|
|
33
|
+
return allFiles.value;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
const tree = render(_$createComponent(Output, {
|
|
38
|
+
get children() {
|
|
39
|
+
return [_$createComponent(SourceFile, {
|
|
40
|
+
path: "hi.txt",
|
|
41
|
+
filetype: "text",
|
|
42
|
+
children: "hello!"
|
|
43
|
+
}), _$createComponent(TrackContents, {})];
|
|
44
|
+
}
|
|
45
|
+
}));
|
|
46
|
+
expect(tree.contents[1].contents).toEqual("hi.txt contents.txt");
|
|
47
|
+
});
|
|
48
|
+
it("Includes header", () => {
|
|
49
|
+
const header = ["# This is a header"];
|
|
50
|
+
const tree = render(_$createComponent(Output, {
|
|
51
|
+
get children() {
|
|
52
|
+
return _$createComponent(SourceFile, {
|
|
53
|
+
path: "hi.txt",
|
|
54
|
+
filetype: "text",
|
|
55
|
+
header: header,
|
|
56
|
+
children: "hello!"
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}));
|
|
60
|
+
expect(tree.contents[0].contents).toEqual(d`
|
|
61
|
+
# This is a header
|
|
62
|
+
hello!
|
|
63
|
+
`);
|
|
64
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { memo as _$memo, createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { ref } from "@vue/reactivity";
|
|
3
|
+
import { expect, it } from "vitest";
|
|
4
|
+
import { Wrap } from "../../src/components/Wrap.js";
|
|
5
|
+
import { printTree, renderTree } from "../../src/render.js";
|
|
6
|
+
import "../../testing/extend-expect.js";
|
|
7
|
+
function Wrapper(props) {
|
|
8
|
+
return ["[", _$memo(() => props.children), "]"];
|
|
9
|
+
}
|
|
10
|
+
it("conditionally wraps", () => {
|
|
11
|
+
const template = [_$createComponent(Wrap, {
|
|
12
|
+
when: true,
|
|
13
|
+
"with": Wrapper,
|
|
14
|
+
children: "testing"
|
|
15
|
+
}), _$createComponent(Wrap, {
|
|
16
|
+
when: false,
|
|
17
|
+
"with": Wrapper,
|
|
18
|
+
children: "testing"
|
|
19
|
+
})];
|
|
20
|
+
expect(template).toRenderTo(`[testing]testing`);
|
|
21
|
+
});
|
|
22
|
+
it("works reactively", () => {
|
|
23
|
+
const doWrap = ref(false);
|
|
24
|
+
const template = [_$createComponent(Wrap, {
|
|
25
|
+
get when() {
|
|
26
|
+
return doWrap.value;
|
|
27
|
+
},
|
|
28
|
+
"with": Wrapper,
|
|
29
|
+
children: "testing"
|
|
30
|
+
})];
|
|
31
|
+
const tree = renderTree(template);
|
|
32
|
+
expect(printTree(tree)).toEqual(`testing`);
|
|
33
|
+
doWrap.value = true;
|
|
34
|
+
expect(printTree(tree)).toEqual(`testing`);
|
|
35
|
+
});
|