@alloy-js/core 0.5.0 → 0.6.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 +44 -0
- package/babel.config.cjs +4 -1
- package/dist/src/binder.d.ts +5 -0
- package/dist/src/binder.d.ts.map +1 -1
- package/dist/src/binder.js +14 -0
- package/dist/src/binder.js.map +1 -1
- package/dist/src/code.d.ts +2 -2
- package/dist/src/code.d.ts.map +1 -1
- package/dist/src/code.js +4 -4
- package/dist/src/code.js.map +1 -1
- package/dist/src/components/Block.d.ts +25 -0
- package/dist/src/components/Block.d.ts.map +1 -0
- package/dist/src/components/Block.js +25 -0
- package/dist/src/components/Block.js.map +1 -0
- package/dist/src/components/Declaration.d.ts.map +1 -1
- package/dist/src/components/Declaration.js +4 -0
- package/dist/src/components/Declaration.js.map +1 -1
- package/dist/src/components/For.d.ts +44 -0
- package/dist/src/components/For.d.ts.map +1 -0
- package/dist/src/components/For.js +41 -0
- package/dist/src/components/For.js.map +1 -0
- package/dist/src/components/Indent.d.ts +5 -9
- package/dist/src/components/Indent.d.ts.map +1 -1
- package/dist/src/components/Indent.js +7 -18
- package/dist/src/components/Indent.js.map +1 -1
- package/dist/src/components/List.d.ts +38 -0
- package/dist/src/components/List.d.ts.map +1 -0
- package/dist/src/components/List.js +40 -0
- package/dist/src/components/List.js.map +1 -0
- package/dist/src/components/MemberDeclaration.d.ts.map +1 -1
- package/dist/src/components/MemberDeclaration.js.map +1 -1
- package/dist/src/components/MemberName.js +1 -1
- package/dist/src/components/MemberName.js.map +1 -1
- package/dist/src/components/MemberScope.d.ts.map +1 -1
- package/dist/src/components/MemberScope.js.map +1 -1
- package/dist/src/components/Name.js +1 -1
- package/dist/src/components/Name.js.map +1 -1
- package/dist/src/components/Output.d.ts +2 -1
- package/dist/src/components/Output.d.ts.map +1 -1
- package/dist/src/components/Output.js +9 -1
- package/dist/src/components/Output.js.map +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/Show.d.ts +8 -0
- package/dist/src/components/Show.d.ts.map +1 -0
- package/dist/src/components/Show.js +4 -0
- package/dist/src/components/Show.js.map +1 -0
- package/dist/src/components/SourceDirectory.d.ts.map +1 -1
- package/dist/src/components/SourceDirectory.js +1 -0
- package/dist/src/components/SourceDirectory.js.map +1 -1
- package/dist/src/components/SourceFile.d.ts +2 -6
- package/dist/src/components/SourceFile.d.ts.map +1 -1
- package/dist/src/components/SourceFile.js +6 -13
- package/dist/src/components/SourceFile.js.map +1 -1
- package/dist/src/components/StatementList.d.ts +9 -0
- package/dist/src/components/StatementList.d.ts.map +1 -0
- package/dist/src/components/StatementList.js +17 -0
- package/dist/src/components/StatementList.js.map +1 -0
- package/dist/src/components/Switch.d.ts +41 -0
- package/dist/src/components/Switch.d.ts.map +1 -0
- package/dist/src/components/Switch.js +41 -0
- package/dist/src/components/Switch.js.map +1 -0
- package/dist/src/components/Wrap.d.ts +20 -0
- package/dist/src/components/Wrap.d.ts.map +1 -0
- package/dist/src/components/Wrap.js +15 -0
- package/dist/src/components/Wrap.js.map +1 -0
- package/dist/src/components/index.d.ts +8 -1
- package/dist/src/components/index.d.ts.map +1 -1
- package/dist/src/components/index.js +7 -0
- package/dist/src/components/index.js.map +1 -1
- package/dist/src/components/stc/index.d.ts +77 -6
- package/dist/src/components/stc/index.d.ts.map +1 -1
- package/dist/src/components/stc/index.js +17 -1
- package/dist/src/components/stc/index.js.map +1 -1
- package/dist/src/context/index.d.ts +0 -1
- package/dist/src/context/index.d.ts.map +1 -1
- package/dist/src/context/index.js +0 -1
- package/dist/src/context/index.js.map +1 -1
- package/dist/src/context.d.ts.map +1 -1
- package/dist/src/context.js +3 -3
- package/dist/src/context.js.map +1 -1
- package/dist/src/index.browser.d.ts +3 -0
- package/dist/src/index.browser.d.ts.map +1 -0
- package/dist/src/index.browser.js +3 -0
- package/dist/src/index.browser.js.map +1 -0
- 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/jsx-runtime.d.ts +133 -8
- package/dist/src/jsx-runtime.d.ts.map +1 -1
- package/dist/src/jsx-runtime.js +102 -12
- package/dist/src/jsx-runtime.js.map +1 -1
- package/dist/src/render.d.ts +107 -132
- package/dist/src/render.d.ts.map +1 -1
- package/dist/src/render.js +269 -177
- package/dist/src/render.js.map +1 -1
- package/dist/src/stc.d.ts +14 -0
- package/dist/src/stc.d.ts.map +1 -0
- package/dist/src/stc.js +52 -0
- package/dist/src/stc.js.map +1 -0
- package/dist/src/utils.d.ts +22 -15
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +95 -59
- package/dist/src/utils.js.map +1 -1
- package/dist/test/browser-build.test.d.ts +2 -0
- package/dist/test/browser-build.test.d.ts.map +1 -0
- package/dist/test/components/block.test.d.ts +2 -0
- package/dist/test/components/block.test.d.ts.map +1 -0
- package/dist/test/components/declaration.test.d.ts +2 -0
- package/dist/test/components/declaration.test.d.ts.map +1 -0
- package/dist/test/components/list.test.d.ts +2 -0
- package/dist/test/components/list.test.d.ts.map +1 -0
- package/dist/test/components/wrap.test.d.ts +2 -0
- package/dist/test/components/wrap.test.d.ts.map +1 -0
- package/dist/test/control-flow/for.test.d.ts +2 -0
- package/dist/test/control-flow/for.test.d.ts.map +1 -0
- package/dist/test/control-flow/match.test.d.ts +2 -0
- package/dist/test/control-flow/match.test.d.ts.map +1 -0
- package/dist/test/control-flow/show.test.d.ts +2 -0
- package/dist/test/control-flow/show.test.d.ts.map +1 -0
- package/dist/test/reactivity/cleanup.test.d.ts +2 -0
- package/dist/test/reactivity/cleanup.test.d.ts.map +1 -0
- package/dist/test/reactivity/memo.test.d.ts +2 -0
- package/dist/test/reactivity/memo.test.d.ts.map +1 -0
- package/dist/test/reactivity/untrack.test.d.ts +2 -0
- package/dist/test/reactivity/untrack.test.d.ts.map +1 -0
- package/dist/test/rendering/formatting.test.d.ts +2 -0
- package/dist/test/rendering/formatting.test.d.ts.map +1 -0
- package/dist/test/rendering/memoization.test.d.ts +2 -0
- package/dist/test/rendering/memoization.test.d.ts.map +1 -0
- package/dist/test/split-props.test.d.ts +2 -0
- package/dist/test/split-props.test.d.ts.map +1 -0
- package/dist/test/stc.test.d.ts.map +1 -1
- package/dist/test/utils.test.d.ts.map +1 -1
- package/dist/testing/extend-expect.js +4 -4
- package/dist/testing/extend-expect.js.map +1 -1
- package/dist/testing/render.d.ts +2 -3
- package/dist/testing/render.d.ts.map +1 -1
- package/dist/testing/render.js +2 -4
- package/dist/testing/render.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +6 -8
- package/src/binder.ts +21 -0
- package/src/code.ts +17 -12
- package/src/components/Block.tsx +44 -0
- package/src/components/Declaration.tsx +10 -4
- package/src/components/For.tsx +81 -0
- package/src/components/Indent.tsx +20 -27
- package/src/components/List.tsx +94 -0
- package/src/components/MemberDeclaration.tsx +9 -6
- package/src/components/MemberScope.tsx +4 -2
- package/src/components/Output.tsx +25 -13
- package/src/components/Scope.tsx +4 -2
- package/src/components/Show.tsx +11 -0
- package/src/components/SourceDirectory.tsx +5 -1
- package/src/components/SourceFile.tsx +12 -16
- package/src/components/StatementList.tsx +16 -0
- package/src/components/Switch.tsx +62 -0
- package/src/components/Wrap.tsx +29 -0
- package/src/components/index.tsx +8 -1
- package/src/components/stc/index.ts +18 -1
- package/src/context/index.ts +0 -1
- package/src/context.ts +2 -3
- package/src/index.browser.ts +2 -0
- package/src/index.ts +1 -0
- package/src/jsx-runtime.ts +241 -23
- package/src/render.ts +378 -198
- package/src/stc.ts +95 -0
- package/src/utils.ts +162 -95
- package/temp/api.json +8318 -3301
- package/test/browser-build.test.ts +91 -0
- package/test/children.test.tsx +8 -10
- package/test/components/block.test.tsx +48 -0
- package/test/components/declaration.test.tsx +37 -0
- package/test/components/list.test.tsx +91 -0
- package/test/components/slot.test.tsx +31 -25
- package/test/components/source-file.test.tsx +11 -31
- package/test/components/wrap.test.tsx +42 -0
- package/test/control-flow/for.test.tsx +194 -0
- package/test/control-flow/match.test.tsx +49 -0
- package/test/control-flow/show.test.tsx +25 -0
- package/test/name-policy.test.tsx +5 -5
- package/test/reactivity/cleanup.test.tsx +91 -0
- package/test/reactivity/memo.test.tsx +17 -0
- package/test/reactivity/ref-rendering.test.tsx +3 -8
- package/test/reactivity/test.test.tsx +7 -6
- package/test/reactivity/untrack.test.ts +33 -0
- package/test/rendering/basic.test.tsx +25 -47
- package/test/rendering/code.test.tsx +3 -3
- package/test/rendering/formatting.test.tsx +487 -0
- package/test/rendering/indent.test.tsx +42 -529
- package/test/rendering/memoization.test.tsx +30 -0
- package/test/split-props.test.ts +87 -0
- package/test/stc.test.tsx +29 -8
- package/test/symbols.test.ts +73 -0
- package/test/utils.test.tsx +129 -20
- package/testing/extend-expect.ts +14 -4
- package/testing/render.ts +2 -4
- package/testing/vitest.d.ts +6 -1
- package/vitest.config.ts +1 -1
- package/dist/src/context/indent.d.ts +0 -5
- package/dist/src/context/indent.d.ts.map +0 -1
- package/dist/src/context/indent.js +0 -8
- package/dist/src/context/indent.js.map +0 -1
- package/dist/test/rendering/linebreaks.test.d.ts +0 -2
- package/dist/test/rendering/linebreaks.test.d.ts.map +0 -1
- package/src/context/indent.ts +0 -17
- package/test/rendering/linebreaks.test.tsx +0 -72
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import "@alloy-js/core/testing";
|
|
2
|
+
import { ref } from "@vue/reactivity";
|
|
3
|
+
import { expect, it } from "vitest";
|
|
4
|
+
import { Match, Switch } from "../../src/components/Switch.jsx";
|
|
5
|
+
import { printTree, renderTree } from "../../src/render.js";
|
|
6
|
+
|
|
7
|
+
it("selects the true branch", () => {
|
|
8
|
+
const template = (
|
|
9
|
+
<Switch>
|
|
10
|
+
<Match when={true}>true</Match>
|
|
11
|
+
<Match else>false</Match>
|
|
12
|
+
</Switch>
|
|
13
|
+
);
|
|
14
|
+
expect(template).toRenderTo(`true`);
|
|
15
|
+
});
|
|
16
|
+
it("selects the else branch", () => {
|
|
17
|
+
const template = (
|
|
18
|
+
<Switch>
|
|
19
|
+
<Match when={false}>true</Match>
|
|
20
|
+
<Match else>false</Match>
|
|
21
|
+
</Switch>
|
|
22
|
+
);
|
|
23
|
+
expect(template).toRenderTo(`false`);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("renders to nothing when no branch matches", () => {
|
|
27
|
+
const template = (
|
|
28
|
+
<Switch>
|
|
29
|
+
<Match when={false}>true</Match>
|
|
30
|
+
</Switch>
|
|
31
|
+
);
|
|
32
|
+
expect(template).toRenderTo(``);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("works with reactivity", () => {
|
|
36
|
+
const count = ref(0);
|
|
37
|
+
const template = (
|
|
38
|
+
<Switch>
|
|
39
|
+
<Match when={count.value % 2 === 0}>even</Match>
|
|
40
|
+
<Match else>odd</Match>
|
|
41
|
+
</Switch>
|
|
42
|
+
);
|
|
43
|
+
const tree = renderTree(template);
|
|
44
|
+
expect(printTree(tree)).toBe(`even`);
|
|
45
|
+
count.value++;
|
|
46
|
+
expect(printTree(tree)).toBe(`odd`);
|
|
47
|
+
count.value++;
|
|
48
|
+
expect(printTree(tree)).toBe(`even`);
|
|
49
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import "@alloy-js/core/testing";
|
|
2
|
+
import { ref } from "@vue/reactivity";
|
|
3
|
+
import { expect, it } from "vitest";
|
|
4
|
+
import { Show } from "../../src/components/Show.jsx";
|
|
5
|
+
import { printTree, renderTree } from "../../src/render.js";
|
|
6
|
+
|
|
7
|
+
it("selects the true branch", () => {
|
|
8
|
+
const template = <Show when={true}>true</Show>;
|
|
9
|
+
expect(template).toRenderTo(`true`);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it("works with reactivity", () => {
|
|
13
|
+
const count = ref(0);
|
|
14
|
+
const template = (
|
|
15
|
+
<Show when={count.value % 2 === 0} fallback={"odd"}>
|
|
16
|
+
even
|
|
17
|
+
</Show>
|
|
18
|
+
);
|
|
19
|
+
const tree = renderTree(template);
|
|
20
|
+
expect(printTree(tree)).toBe(`even`);
|
|
21
|
+
count.value++;
|
|
22
|
+
expect(printTree(tree)).toBe(`odd`);
|
|
23
|
+
count.value++;
|
|
24
|
+
expect(printTree(tree)).toBe(`even`);
|
|
25
|
+
});
|
|
@@ -11,9 +11,9 @@ it("is applied by output", () => {
|
|
|
11
11
|
const namer = useNamePolicy();
|
|
12
12
|
return namer!.getName("hi", "name");
|
|
13
13
|
}
|
|
14
|
-
expect(
|
|
15
|
-
<
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
);
|
|
14
|
+
expect(
|
|
15
|
+
<Output namePolicy={policy}>
|
|
16
|
+
<Foo />
|
|
17
|
+
</Output>,
|
|
18
|
+
).toRenderTo("namehi");
|
|
19
19
|
});
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { Children, effect, memo, onCleanup } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { ref } from "@vue/reactivity";
|
|
3
|
+
import { describe, expect, it } from "vitest";
|
|
4
|
+
import { renderTree } from "../../src/render.js";
|
|
5
|
+
|
|
6
|
+
describe("memo cleanup", () => {
|
|
7
|
+
it("cleans up when memo value is recomputed", () => {
|
|
8
|
+
const r = ref(1);
|
|
9
|
+
let callCount = 0;
|
|
10
|
+
const m = memo(() => {
|
|
11
|
+
onCleanup(() => {
|
|
12
|
+
callCount++;
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
return r.value;
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
expect(m()).toBe(1);
|
|
19
|
+
expect(callCount).toBe(0);
|
|
20
|
+
|
|
21
|
+
r.value = 2;
|
|
22
|
+
|
|
23
|
+
expect(m()).toBe(2);
|
|
24
|
+
expect(callCount).toBe(1);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
describe("effect cleanup", () => {
|
|
29
|
+
it("cleans up when the effect is run", () => {
|
|
30
|
+
const r = ref(1);
|
|
31
|
+
let cleanedUp = false;
|
|
32
|
+
effect(() => {
|
|
33
|
+
onCleanup(() => {
|
|
34
|
+
cleanedUp = true;
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
return r.value;
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
expect(cleanedUp).toBe(false);
|
|
41
|
+
|
|
42
|
+
r.value = 2;
|
|
43
|
+
|
|
44
|
+
expect(cleanedUp).toBe(true);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
describe("element cleanup", () => {
|
|
49
|
+
it("should clean up when the element is unmounted", () => {
|
|
50
|
+
let cleanedUp = false;
|
|
51
|
+
function Component() {
|
|
52
|
+
onCleanup(() => {
|
|
53
|
+
cleanedUp = true;
|
|
54
|
+
});
|
|
55
|
+
return "hi!";
|
|
56
|
+
}
|
|
57
|
+
const el = ref<unknown>(<Component />);
|
|
58
|
+
const template = <>{el}</>;
|
|
59
|
+
renderTree(template);
|
|
60
|
+
el.value = "";
|
|
61
|
+
expect(cleanedUp).toBe(true);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("should clean up when the element is unmounted, recursively", () => {
|
|
65
|
+
let cleanedUpC1 = false;
|
|
66
|
+
let cleanedUpC2 = false;
|
|
67
|
+
|
|
68
|
+
function C1(props: { children: Children }) {
|
|
69
|
+
onCleanup(() => {
|
|
70
|
+
cleanedUpC1 = true;
|
|
71
|
+
});
|
|
72
|
+
return props.children;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function C2() {
|
|
76
|
+
onCleanup(() => {
|
|
77
|
+
cleanedUpC2 = true;
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
const el = ref<unknown>(
|
|
81
|
+
<C1>
|
|
82
|
+
<C2></C2>
|
|
83
|
+
</C1>,
|
|
84
|
+
);
|
|
85
|
+
const template = <>{el}</>;
|
|
86
|
+
renderTree(template);
|
|
87
|
+
el.value = "";
|
|
88
|
+
expect(cleanedUpC1).toBe(true);
|
|
89
|
+
expect(cleanedUpC2).toBe(true);
|
|
90
|
+
});
|
|
91
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { memo } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { ref } from "@vue/reactivity";
|
|
3
|
+
import { expect, it } from "vitest";
|
|
4
|
+
|
|
5
|
+
it("doesn't recalculate when dependencies don't change", () => {
|
|
6
|
+
const signal = ref(0);
|
|
7
|
+
let callCount = 0;
|
|
8
|
+
const m = memo(() => {
|
|
9
|
+
callCount += 1;
|
|
10
|
+
return signal.value;
|
|
11
|
+
});
|
|
12
|
+
expect(callCount).toBe(1);
|
|
13
|
+
m();
|
|
14
|
+
expect(callCount).toBe(1);
|
|
15
|
+
m();
|
|
16
|
+
expect(callCount).toBe(1);
|
|
17
|
+
});
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
import { code, memo, renderTree } from "@alloy-js/core";
|
|
1
|
+
import { code, memo, printTree, renderTree } from "@alloy-js/core";
|
|
2
2
|
import { ref } from "@vue/reactivity";
|
|
3
3
|
import { expect, it } from "vitest";
|
|
4
|
-
import { printTree } from "../../testing/render.js";
|
|
5
4
|
|
|
6
5
|
it("handles refs in the tree", () => {
|
|
7
6
|
const r = ref(42);
|
|
8
|
-
const tree = renderTree(<>
|
|
9
|
-
The number is {r}
|
|
10
|
-
</>);
|
|
7
|
+
const tree = renderTree(<>The number is {r}</>);
|
|
11
8
|
|
|
12
9
|
expect(printTree(tree)).toBe("The number is 42");
|
|
13
10
|
r.value = 12;
|
|
@@ -28,9 +25,7 @@ it("handles refs in the tree with code", () => {
|
|
|
28
25
|
it("handles memos in the tree", () => {
|
|
29
26
|
const r = ref(42);
|
|
30
27
|
const m = memo(() => r.value + 10);
|
|
31
|
-
const tree = renderTree(<>
|
|
32
|
-
The number is {m}
|
|
33
|
-
</>);
|
|
28
|
+
const tree = renderTree(<>The number is {m}</>);
|
|
34
29
|
|
|
35
30
|
expect(printTree(tree)).toBe("The number is 52");
|
|
36
31
|
r.value = 12;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { memo, renderTree } from "@alloy-js/core";
|
|
1
|
+
import { memo, printTree, renderTree } from "@alloy-js/core";
|
|
2
2
|
import { computed, reactive, ref } from "@vue/reactivity";
|
|
3
3
|
import { expect, it } from "vitest";
|
|
4
4
|
import { mapJoin } from "../../src/utils.js";
|
|
5
|
-
import { d
|
|
5
|
+
import { d } from "../../testing/render.js";
|
|
6
6
|
|
|
7
7
|
it("splices in new nodes", () => {
|
|
8
8
|
const r = ref(["one"]);
|
|
@@ -38,10 +38,11 @@ it("works with a complex case", () => {
|
|
|
38
38
|
|
|
39
39
|
function ImportStatements(props: ImportStatementsProps) {
|
|
40
40
|
return memo(() =>
|
|
41
|
-
mapJoin(
|
|
42
|
-
|
|
43
|
-
types
|
|
44
|
-
)
|
|
41
|
+
mapJoin(
|
|
42
|
+
() => props.records,
|
|
43
|
+
(path, types) => <ImportStatement path={path} types={types} />,
|
|
44
|
+
),
|
|
45
|
+
);
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
interface ImportStatementProps {
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ref } from "@vue/reactivity";
|
|
2
|
+
import { expect, it } from "vitest";
|
|
3
|
+
import { memo, untrack } from "../../src/jsx-runtime.js";
|
|
4
|
+
|
|
5
|
+
it("ignores signals for dependency tracking", () => {
|
|
6
|
+
const signal = ref(0);
|
|
7
|
+
|
|
8
|
+
const m = memo(() => {
|
|
9
|
+
return untrack(() => signal.value);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
expect(m()).toBe(0);
|
|
13
|
+
|
|
14
|
+
signal.value = 1;
|
|
15
|
+
|
|
16
|
+
expect(m()).toBe(0);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it("doesn't affect signal changes", () => {
|
|
20
|
+
const signal = ref(0);
|
|
21
|
+
|
|
22
|
+
const m = memo(() => {
|
|
23
|
+
return signal.value;
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
expect(m()).toBe(0);
|
|
27
|
+
|
|
28
|
+
untrack(() => {
|
|
29
|
+
signal.value = 1;
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
expect(m()).toBe(1);
|
|
33
|
+
});
|
|
@@ -2,24 +2,15 @@ import { describe, expect, it } from "vitest";
|
|
|
2
2
|
import { Children } from "../../src/jsx-runtime.js";
|
|
3
3
|
import "../../testing/extend-expect.js";
|
|
4
4
|
describe("string nodes", () => {
|
|
5
|
-
it("renders string nodes", () => {
|
|
6
|
-
expect(<>
|
|
7
|
-
a
|
|
8
|
-
b
|
|
9
|
-
c
|
|
10
|
-
</>).toRenderTo(`
|
|
11
|
-
a
|
|
12
|
-
b
|
|
13
|
-
c
|
|
14
|
-
`);
|
|
15
|
-
});
|
|
16
|
-
|
|
17
5
|
it("renders string nodes with substitutions", () => {
|
|
18
6
|
const str = "hi";
|
|
19
|
-
expect(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
7
|
+
expect(
|
|
8
|
+
<>
|
|
9
|
+
a {str}
|
|
10
|
+
<hbr />
|
|
11
|
+
{str}
|
|
12
|
+
</>,
|
|
13
|
+
).toRenderTo(`
|
|
23
14
|
a hi
|
|
24
15
|
hi
|
|
25
16
|
`);
|
|
@@ -52,21 +43,11 @@ describe("component nodes", () => {
|
|
|
52
43
|
});
|
|
53
44
|
|
|
54
45
|
it("renders components on same line", () => {
|
|
55
|
-
expect(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
it("renders components on multiple lines", () => {
|
|
61
|
-
expect(<>
|
|
62
|
-
<Str /> <Str />
|
|
63
|
-
<Arr /> <Arr />
|
|
64
|
-
</>).toRenderTo(`
|
|
65
|
-
Str Str
|
|
66
|
-
Item 1
|
|
67
|
-
Item 2 Item 1
|
|
68
|
-
Item 2
|
|
69
|
-
`);
|
|
46
|
+
expect(
|
|
47
|
+
<>
|
|
48
|
+
<Str /> <Str />
|
|
49
|
+
</>,
|
|
50
|
+
).toRenderTo("Str Str");
|
|
70
51
|
});
|
|
71
52
|
});
|
|
72
53
|
|
|
@@ -85,21 +66,15 @@ describe("memo nodes", () => {
|
|
|
85
66
|
}
|
|
86
67
|
|
|
87
68
|
it("renders basic memos", () => {
|
|
88
|
-
expect(<>
|
|
89
|
-
{getStr()}
|
|
90
|
-
</>).toRenderTo("Str");
|
|
69
|
+
expect(<>{getStr()}</>).toRenderTo("Str");
|
|
91
70
|
});
|
|
92
71
|
|
|
93
72
|
it("renders component memos", () => {
|
|
94
|
-
expect(<>
|
|
95
|
-
{getFoo()}
|
|
96
|
-
</>).toRenderTo("Foo");
|
|
73
|
+
expect(<>{getFoo()}</>).toRenderTo("Foo");
|
|
97
74
|
});
|
|
98
75
|
|
|
99
76
|
it("renders array memos", () => {
|
|
100
|
-
expect(<>
|
|
101
|
-
{getArr()}
|
|
102
|
-
</>).toRenderTo("Foo\nFoo");
|
|
77
|
+
expect(<>{getArr()}</>).toRenderTo("Foo\nFoo");
|
|
103
78
|
});
|
|
104
79
|
});
|
|
105
80
|
|
|
@@ -114,10 +89,13 @@ it("renders text fragments", () => {
|
|
|
114
89
|
return "bye";
|
|
115
90
|
}
|
|
116
91
|
|
|
117
|
-
expect(
|
|
92
|
+
expect(
|
|
93
|
+
<>
|
|
118
94
|
hi
|
|
95
|
+
<hbr />
|
|
119
96
|
<Foo />
|
|
120
|
-
|
|
97
|
+
</>,
|
|
98
|
+
).toRenderTo(`
|
|
121
99
|
hi
|
|
122
100
|
bye
|
|
123
101
|
`);
|
|
@@ -148,9 +126,9 @@ it("keeps spaces between expressions", () => {
|
|
|
148
126
|
function getStr() {
|
|
149
127
|
return "getStr";
|
|
150
128
|
}
|
|
151
|
-
expect(
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
);
|
|
129
|
+
expect(
|
|
130
|
+
<>
|
|
131
|
+
a {str} {str} {getStr()} {getStr()} c
|
|
132
|
+
</>,
|
|
133
|
+
).toRenderTo("a str str getStr getStr c");
|
|
156
134
|
});
|
|
@@ -17,7 +17,7 @@ it("renders allows substitutions of elements", () => {
|
|
|
17
17
|
return "hi";
|
|
18
18
|
}
|
|
19
19
|
expect(code`
|
|
20
|
-
foo ${<Foo />} bar
|
|
20
|
+
foo ${(<Foo />)} bar
|
|
21
21
|
`).toRenderTo("foo hi bar");
|
|
22
22
|
});
|
|
23
23
|
|
|
@@ -31,7 +31,7 @@ it("renders has auto-indentation", () => {
|
|
|
31
31
|
|
|
32
32
|
const template = code`
|
|
33
33
|
if (x === 1) {
|
|
34
|
-
${<Foo />}
|
|
34
|
+
${(<Foo />)}
|
|
35
35
|
}
|
|
36
36
|
`;
|
|
37
37
|
|
|
@@ -55,7 +55,7 @@ it("handles blank lines", () => {
|
|
|
55
55
|
expect(template).toRenderTo(`
|
|
56
56
|
{
|
|
57
57
|
a
|
|
58
|
-
|
|
58
|
+
|
|
59
59
|
x
|
|
60
60
|
}
|
|
61
61
|
`);
|