Skip to content

Commit c1ddb70

Browse files
baiwusanyu-csxzz
andauthored
test: add dynamic root nodes and interpolation (#1)
Co-authored-by: 三咲智子 Kevin Deng <[email protected]>
1 parent 8b07579 commit c1ddb70

File tree

2 files changed

+54
-14
lines changed

2 files changed

+54
-14
lines changed

packages/compiler-vapor/__tests__/__snapshots__/compile.test.ts.snap

+46-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3-
exports[`comile > bindings 1`] = `
3+
exports[`compile > bindings 1`] = `
44
"import { template, children, createTextNode, insert, effect, setText } from 'vue/vapor';
55
const t0 = template('<div>count is <!>.</div>');
66
export function render() {
@@ -23,7 +23,7 @@ export function render() {
2323
"
2424
`;
2525

26-
exports[`comile > directives > v-bind > simple expression 1`] = `
26+
exports[`compile > directives > v-bind > simple expression 1`] = `
2727
"import { template, children, effect, setAttr } from 'vue/vapor';
2828
const t0 = template('<div></div>');
2929
export function render() {
@@ -39,7 +39,7 @@ export function render() {
3939
"
4040
`;
4141

42-
exports[`comile > directives > v-html > no expression 1`] = `
42+
exports[`compile > directives > v-html > no expression 1`] = `
4343
"import { template, children, effect, setHtml } from 'vue/vapor';
4444
const t0 = template('<div></div>');
4545
export function render() {
@@ -55,7 +55,7 @@ export function render() {
5555
"
5656
`;
5757

58-
exports[`comile > directives > v-html > simple expression 1`] = `
58+
exports[`compile > directives > v-html > simple expression 1`] = `
5959
"import { template, children, effect, setHtml } from 'vue/vapor';
6060
const t0 = template('<div></div>');
6161
export function render() {
@@ -71,7 +71,7 @@ export function render() {
7171
"
7272
`;
7373

74-
exports[`comile > directives > v-on > simple expression 1`] = `
74+
exports[`compile > directives > v-on > simple expression 1`] = `
7575
"import { template, children, effect, on } from 'vue/vapor';
7676
const t0 = template('<div></div>');
7777
export function render() {
@@ -87,7 +87,7 @@ export function render() {
8787
"
8888
`;
8989

90-
exports[`comile > directives > v-once > as root node 1`] = `
90+
exports[`compile > directives > v-once > as root node 1`] = `
9191
"import { template, children, effect, setAttr } from 'vue/vapor';
9292
const t0 = template('<div></div>');
9393
export function render() {
@@ -103,7 +103,7 @@ export function render() {
103103
"
104104
`;
105105

106-
exports[`comile > directives > v-once > basic 1`] = `
106+
exports[`compile > directives > v-once > basic 1`] = `
107107
"import { template, children, createTextNode, setText, setAttr, prepend } from 'vue/vapor';
108108
const t0 = template('<div> <span></span></div>');
109109
export function render() {
@@ -125,7 +125,7 @@ export function render() {
125125
"
126126
`;
127127

128-
exports[`comile > directives > v-text > no expression 1`] = `
128+
exports[`compile > directives > v-text > no expression 1`] = `
129129
"import { template, children, effect, setText } from 'vue/vapor';
130130
const t0 = template('<div></div>');
131131
export function render() {
@@ -141,7 +141,7 @@ export function render() {
141141
"
142142
`;
143143

144-
exports[`comile > directives > v-text > simple expression 1`] = `
144+
exports[`compile > directives > v-text > simple expression 1`] = `
145145
"import { template, children, effect, setText } from 'vue/vapor';
146146
const t0 = template('<div></div>');
147147
export function render() {
@@ -157,7 +157,7 @@ export function render() {
157157
"
158158
`;
159159

160-
exports[`comile > dynamic root 1`] = `
160+
exports[`compile > dynamic root 1`] = `
161161
"import { fragment, createTextNode, append, effect, setText } from 'vue/vapor';
162162
export function render() {
163163
const t0 = fragment();
@@ -176,7 +176,40 @@ export function render() {
176176
"
177177
`;
178178

179-
exports[`comile > fragment 1`] = `
179+
exports[`compile > dynamic root nodes and interpolation 1`] = `
180+
"import { template, children, createTextNode, prepend, insert, append, effect, on, setAttr, setText } from 'vue/vapor';
181+
const t0 = template('<button>foo<!>foo</button>');
182+
export function render() {
183+
const n0 = t0();
184+
const {
185+
0: [
186+
n1,
187+
{
188+
1: [n5],
189+
},
190+
],
191+
} = children(n0);
192+
const n2 = createTextNode(count);
193+
const n3 = createTextNode(count);
194+
const n4 = createTextNode(count);
195+
prepend(n1, n2);
196+
insert(n3, n1, n5);
197+
append(n1, n4);
198+
effect(() => {
199+
on(n1, 'click', handleClick);
200+
});
201+
effect(() => {
202+
setAttr(n1, 'id', undefined, count);
203+
setText(n2, undefined, count);
204+
setText(n3, undefined, count);
205+
setText(n4, undefined, count);
206+
});
207+
return n0;
208+
}
209+
"
210+
`;
211+
212+
exports[`compile > fragment 1`] = `
180213
"import { template } from 'vue/vapor';
181214
const t0 = template('<p></p><span></span><div></div>');
182215
export function render() {
@@ -186,7 +219,7 @@ export function render() {
186219
"
187220
`;
188221

189-
exports[`comile > static + dynamic root 1`] = `
222+
exports[`compile > static + dynamic root 1`] = `
190223
"import { template, children, createTextNode, prepend, insert, append, effect, setText } from 'vue/vapor';
191224
const t0 = template('3<!>6<!>9');
192225
export function render() {
@@ -236,7 +269,7 @@ export function render() {
236269
"
237270
`;
238271

239-
exports[`comile > static template 1`] = `
272+
exports[`compile > static template 1`] = `
240273
"import { template } from 'vue/vapor';
241274
const t0 = template('<div><p>hello</p><input><span></span></div>');
242275
export function render() {

packages/compiler-vapor/__tests__/compile.test.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ async function compile(
1616
return code
1717
}
1818

19-
describe('comile', () => {
19+
describe('compile', () => {
2020
test('static template', async () => {
2121
const code = await compile(
2222
`<div>
@@ -33,6 +33,13 @@ describe('comile', () => {
3333
expect(code).matchSnapshot()
3434
})
3535

36+
test('dynamic root nodes and interpolation', async () => {
37+
const code = await compile(
38+
`<button @click="handleClick" :id="count">{{count}}foo{{count}}foo{{count}} </button>`,
39+
)
40+
expect(code).matchSnapshot()
41+
})
42+
3643
test('static + dynamic root', async () => {
3744
const code = await compile(
3845
`{{ 1 }}{{ 2 }}3{{ 4 }}{{ 5 }}6{{ 7 }}{{ 8 }}9{{ 'A' }}{{ 'B' }}`,

0 commit comments

Comments
 (0)