@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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.test.d.ts","sourceRoot":"","sources":["../../test/utils.test.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.test.d.ts","sourceRoot":"","sources":["../../test/utils.test.tsx"],"names":[],"mappings":"AAMA,OAAO,6BAA6B,CAAC"}
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import { memo as _$memo, createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { computed, ref, triggerRef } from "@vue/reactivity";
|
|
3
|
+
import { describe, expect, it } from "vitest";
|
|
4
|
+
import { renderTree } from "../src/render.js";
|
|
5
|
+
import { flushJobs } from "../src/scheduler.js";
|
|
6
|
+
import { children, join, mapJoin } from "../src/utils.js";
|
|
7
|
+
import "../testing/extend-expect.js";
|
|
8
|
+
describe("mapJoin", () => {
|
|
9
|
+
it("can map a map", () => {
|
|
10
|
+
const map = new Map([["a", 1], ["b", 2]]);
|
|
11
|
+
function Foo(props) {
|
|
12
|
+
return ["Key: ", _$memo(() => props.key), ", Value: ", _$memo(() => props.value)];
|
|
13
|
+
}
|
|
14
|
+
const joined = mapJoin(() => map, (key, value) => _$createComponent(Foo, {
|
|
15
|
+
key: key,
|
|
16
|
+
value: value
|
|
17
|
+
}));
|
|
18
|
+
expect(joined()).toRenderTo(`
|
|
19
|
+
Key: a, Value: 1
|
|
20
|
+
Key: b, Value: 2
|
|
21
|
+
`);
|
|
22
|
+
});
|
|
23
|
+
it("can map an array", () => {
|
|
24
|
+
const arr = [1, 2];
|
|
25
|
+
function Foo(props) {
|
|
26
|
+
return ["Value: ", _$memo(() => props.value)];
|
|
27
|
+
}
|
|
28
|
+
const joined = mapJoin(() => arr, value => _$createComponent(Foo, {
|
|
29
|
+
value: value
|
|
30
|
+
}));
|
|
31
|
+
expect(joined()).toRenderTo(`
|
|
32
|
+
Value: 1
|
|
33
|
+
Value: 2
|
|
34
|
+
`);
|
|
35
|
+
});
|
|
36
|
+
it("can map an array reactively (without render)", () => {
|
|
37
|
+
const arr = ref([1, 2]);
|
|
38
|
+
function Foo(props) {
|
|
39
|
+
return ["Value: ", _$memo(() => props.value)];
|
|
40
|
+
}
|
|
41
|
+
const joined = mapJoin(() => arr.value, value => {
|
|
42
|
+
return _$createComponent(Foo, {
|
|
43
|
+
value: value
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
const len = computed(() => {
|
|
47
|
+
return joined().length;
|
|
48
|
+
});
|
|
49
|
+
expect(len.value).toBe(4);
|
|
50
|
+
arr.value.push(3);
|
|
51
|
+
triggerRef(arr);
|
|
52
|
+
expect(len.value).toBe(6);
|
|
53
|
+
});
|
|
54
|
+
it("can map an array reactively (with render)", () => {
|
|
55
|
+
let callCount = 0;
|
|
56
|
+
const arr = ref([1, 2]);
|
|
57
|
+
function Foo(props) {
|
|
58
|
+
callCount++;
|
|
59
|
+
return ["Value: ", _$memo(() => props.value)];
|
|
60
|
+
}
|
|
61
|
+
const joined = mapJoin(() => arr.value, value => {
|
|
62
|
+
return _$createComponent(Foo, {
|
|
63
|
+
value: value
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
renderTree(joined);
|
|
67
|
+
expect(callCount).toBe(2);
|
|
68
|
+
arr.value.push(3);
|
|
69
|
+
triggerRef(arr);
|
|
70
|
+
flushJobs();
|
|
71
|
+
expect(callCount).toBe(3);
|
|
72
|
+
});
|
|
73
|
+
it("can map a joiner", () => {
|
|
74
|
+
const arr = [1, 2];
|
|
75
|
+
function Foo(props) {
|
|
76
|
+
return ["Value: ", _$memo(() => props.value)];
|
|
77
|
+
}
|
|
78
|
+
const joined = mapJoin(() => arr, value => _$createComponent(Foo, {
|
|
79
|
+
value: value
|
|
80
|
+
}), {
|
|
81
|
+
joiner: "-"
|
|
82
|
+
});
|
|
83
|
+
expect(joined).toRenderTo(`
|
|
84
|
+
Value: 1-Value: 2
|
|
85
|
+
`);
|
|
86
|
+
});
|
|
87
|
+
it("can map an ender", () => {
|
|
88
|
+
const arr = [1, 2];
|
|
89
|
+
function Foo(props) {
|
|
90
|
+
return ["Value: ", _$memo(() => props.value)];
|
|
91
|
+
}
|
|
92
|
+
const joined = mapJoin(() => arr, value => _$createComponent(Foo, {
|
|
93
|
+
value: value
|
|
94
|
+
}), {
|
|
95
|
+
joiner: "-",
|
|
96
|
+
ender: ";"
|
|
97
|
+
});
|
|
98
|
+
expect(joined).toRenderTo(`
|
|
99
|
+
Value: 1-Value: 2;
|
|
100
|
+
`);
|
|
101
|
+
});
|
|
102
|
+
it("can map using an iterator", () => {
|
|
103
|
+
const arr = [1, 2].values();
|
|
104
|
+
function Foo(props) {
|
|
105
|
+
return ["Value: ", _$memo(() => props.value)];
|
|
106
|
+
}
|
|
107
|
+
const joined = mapJoin(() => arr, value => _$createComponent(Foo, {
|
|
108
|
+
value: value
|
|
109
|
+
}), {
|
|
110
|
+
joiner: "-",
|
|
111
|
+
ender: ";"
|
|
112
|
+
});
|
|
113
|
+
expect(joined).toRenderTo(`
|
|
114
|
+
Value: 1-Value: 2;
|
|
115
|
+
`);
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
describe("join", () => {
|
|
119
|
+
it("can join an array", () => {
|
|
120
|
+
const arr = [_$createComponent(Foo, {
|
|
121
|
+
value: 1
|
|
122
|
+
}), _$createComponent(Foo, {
|
|
123
|
+
value: 2
|
|
124
|
+
})];
|
|
125
|
+
function Foo(props) {
|
|
126
|
+
return ["Value: ", _$memo(() => props.value)];
|
|
127
|
+
}
|
|
128
|
+
const joined = join(arr);
|
|
129
|
+
expect(joined).toRenderTo(`
|
|
130
|
+
Value: 1
|
|
131
|
+
Value: 2
|
|
132
|
+
`);
|
|
133
|
+
});
|
|
134
|
+
it("can join an array with a joiner", () => {
|
|
135
|
+
const arr = [_$createComponent(Foo, {
|
|
136
|
+
value: 1
|
|
137
|
+
}), _$createComponent(Foo, {
|
|
138
|
+
value: 2
|
|
139
|
+
})];
|
|
140
|
+
function Foo(props) {
|
|
141
|
+
return ["Value: ", _$memo(() => props.value)];
|
|
142
|
+
}
|
|
143
|
+
const joined = join(arr, {
|
|
144
|
+
joiner: "-"
|
|
145
|
+
});
|
|
146
|
+
expect(joined).toRenderTo(`
|
|
147
|
+
Value: 1-Value: 2
|
|
148
|
+
`);
|
|
149
|
+
});
|
|
150
|
+
it("can join an array with an ender", () => {
|
|
151
|
+
const arr = [_$createComponent(Foo, {
|
|
152
|
+
value: 1
|
|
153
|
+
}), _$createComponent(Foo, {
|
|
154
|
+
value: 2
|
|
155
|
+
})];
|
|
156
|
+
function Foo(props) {
|
|
157
|
+
return ["Value: ", _$memo(() => props.value)];
|
|
158
|
+
}
|
|
159
|
+
const joined = join(arr, {
|
|
160
|
+
joiner: "-",
|
|
161
|
+
ender: ";"
|
|
162
|
+
});
|
|
163
|
+
expect(joined).toRenderTo(`
|
|
164
|
+
Value: 1-Value: 2;
|
|
165
|
+
`);
|
|
166
|
+
});
|
|
167
|
+
it("can join using an iterator", () => {
|
|
168
|
+
const arrIter = [_$createComponent(Foo, {
|
|
169
|
+
value: 1
|
|
170
|
+
}), _$createComponent(Foo, {
|
|
171
|
+
value: 2
|
|
172
|
+
})].values();
|
|
173
|
+
function Foo(props) {
|
|
174
|
+
return ["Value: ", _$memo(() => props.value)];
|
|
175
|
+
}
|
|
176
|
+
const joined = join(arrIter, {
|
|
177
|
+
joiner: "-",
|
|
178
|
+
ender: ";"
|
|
179
|
+
});
|
|
180
|
+
expect(joined).toRenderTo(`
|
|
181
|
+
Value: 1-Value: 2;
|
|
182
|
+
`);
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
describe("children", () => {
|
|
186
|
+
let resolvedChildren;
|
|
187
|
+
function ResolveChildren(props) {
|
|
188
|
+
resolvedChildren = children(() => props.children, {
|
|
189
|
+
preserveFragments: props.preserveFragments
|
|
190
|
+
})();
|
|
191
|
+
}
|
|
192
|
+
it("resolves a single child", () => {
|
|
193
|
+
renderTree(_$createComponent(ResolveChildren, {
|
|
194
|
+
children: "1"
|
|
195
|
+
}));
|
|
196
|
+
expect(resolvedChildren).toEqual("1");
|
|
197
|
+
});
|
|
198
|
+
it("resolves multiple children", () => {
|
|
199
|
+
renderTree(_$createComponent(ResolveChildren, {
|
|
200
|
+
get children() {
|
|
201
|
+
return ["1", "2", "3"];
|
|
202
|
+
}
|
|
203
|
+
}));
|
|
204
|
+
expect(resolvedChildren).toEqual(["1", "2", "3"]);
|
|
205
|
+
});
|
|
206
|
+
it("resolves fragments by default", () => {
|
|
207
|
+
renderTree(_$createComponent(ResolveChildren, {
|
|
208
|
+
get children() {
|
|
209
|
+
return [["1"], ["2"], ["3"]];
|
|
210
|
+
}
|
|
211
|
+
}));
|
|
212
|
+
expect(resolvedChildren).toEqual(["1", "2", "3"]);
|
|
213
|
+
});
|
|
214
|
+
it("preserves fragments if asked", () => {
|
|
215
|
+
renderTree(_$createComponent(ResolveChildren, {
|
|
216
|
+
preserveFragments: true,
|
|
217
|
+
get children() {
|
|
218
|
+
return [["1"], ["2"], ["3"]];
|
|
219
|
+
}
|
|
220
|
+
}));
|
|
221
|
+
expect(resolvedChildren).toEqual([["1"], ["2"], ["3"]]);
|
|
222
|
+
});
|
|
223
|
+
});
|
package/dist/testing/index.js
CHANGED
package/dist/testing/render.js
CHANGED