From c1ddb700a832fbc1318de6a64db2f4c3bc915cba Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E7=99=BD=E9=9B=BE=E4=B8=89=E8=AF=AD?= <32354856+baiwusanyu-c@users.noreply.github.com> Date: Tue, 28 Nov 2023 13:06:44 +0800 Subject: [PATCH] test: add dynamic root nodes and interpolation (#1) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Co-authored-by: 三咲智子 Kevin Deng --- .../__snapshots__/compile.test.ts.snap | 59 +++++++++++++++---- .../compiler-vapor/__tests__/compile.test.ts | 9 ++- 2 files changed, 54 insertions(+), 14 deletions(-) diff --git a/packages/compiler-vapor/__tests__/__snapshots__/compile.test.ts.snap b/packages/compiler-vapor/__tests__/__snapshots__/compile.test.ts.snap index 9ad83079a0..92181bc6e0 100644 --- a/packages/compiler-vapor/__tests__/__snapshots__/compile.test.ts.snap +++ b/packages/compiler-vapor/__tests__/__snapshots__/compile.test.ts.snap @@ -1,6 +1,6 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`comile > bindings 1`] = ` +exports[`compile > bindings 1`] = ` "import { template, children, createTextNode, insert, effect, setText } from 'vue/vapor'; const t0 = template('
count is .
'); export function render() { @@ -23,7 +23,7 @@ export function render() { " `; -exports[`comile > directives > v-bind > simple expression 1`] = ` +exports[`compile > directives > v-bind > simple expression 1`] = ` "import { template, children, effect, setAttr } from 'vue/vapor'; const t0 = template('
'); export function render() { @@ -39,7 +39,7 @@ export function render() { " `; -exports[`comile > directives > v-html > no expression 1`] = ` +exports[`compile > directives > v-html > no expression 1`] = ` "import { template, children, effect, setHtml } from 'vue/vapor'; const t0 = template('
'); export function render() { @@ -55,7 +55,7 @@ export function render() { " `; -exports[`comile > directives > v-html > simple expression 1`] = ` +exports[`compile > directives > v-html > simple expression 1`] = ` "import { template, children, effect, setHtml } from 'vue/vapor'; const t0 = template('
'); export function render() { @@ -71,7 +71,7 @@ export function render() { " `; -exports[`comile > directives > v-on > simple expression 1`] = ` +exports[`compile > directives > v-on > simple expression 1`] = ` "import { template, children, effect, on } from 'vue/vapor'; const t0 = template('
'); export function render() { @@ -87,7 +87,7 @@ export function render() { " `; -exports[`comile > directives > v-once > as root node 1`] = ` +exports[`compile > directives > v-once > as root node 1`] = ` "import { template, children, effect, setAttr } from 'vue/vapor'; const t0 = template('
'); export function render() { @@ -103,7 +103,7 @@ export function render() { " `; -exports[`comile > directives > v-once > basic 1`] = ` +exports[`compile > directives > v-once > basic 1`] = ` "import { template, children, createTextNode, setText, setAttr, prepend } from 'vue/vapor'; const t0 = template('
'); export function render() { @@ -125,7 +125,7 @@ export function render() { " `; -exports[`comile > directives > v-text > no expression 1`] = ` +exports[`compile > directives > v-text > no expression 1`] = ` "import { template, children, effect, setText } from 'vue/vapor'; const t0 = template('
'); export function render() { @@ -141,7 +141,7 @@ export function render() { " `; -exports[`comile > directives > v-text > simple expression 1`] = ` +exports[`compile > directives > v-text > simple expression 1`] = ` "import { template, children, effect, setText } from 'vue/vapor'; const t0 = template('
'); export function render() { @@ -157,7 +157,7 @@ export function render() { " `; -exports[`comile > dynamic root 1`] = ` +exports[`compile > dynamic root 1`] = ` "import { fragment, createTextNode, append, effect, setText } from 'vue/vapor'; export function render() { const t0 = fragment(); @@ -176,7 +176,40 @@ export function render() { " `; -exports[`comile > fragment 1`] = ` +exports[`compile > dynamic root nodes and interpolation 1`] = ` +"import { template, children, createTextNode, prepend, insert, append, effect, on, setAttr, setText } from 'vue/vapor'; +const t0 = template(''); +export function render() { + const n0 = t0(); + const { + 0: [ + n1, + { + 1: [n5], + }, + ], + } = children(n0); + const n2 = createTextNode(count); + const n3 = createTextNode(count); + const n4 = createTextNode(count); + prepend(n1, n2); + insert(n3, n1, n5); + append(n1, n4); + effect(() => { + on(n1, 'click', handleClick); + }); + effect(() => { + setAttr(n1, 'id', undefined, count); + setText(n2, undefined, count); + setText(n3, undefined, count); + setText(n4, undefined, count); + }); + return n0; +} +" +`; + +exports[`compile > fragment 1`] = ` "import { template } from 'vue/vapor'; const t0 = template('

'); export function render() { @@ -186,7 +219,7 @@ export function render() { " `; -exports[`comile > static + dynamic root 1`] = ` +exports[`compile > static + dynamic root 1`] = ` "import { template, children, createTextNode, prepend, insert, append, effect, setText } from 'vue/vapor'; const t0 = template('369'); export function render() { @@ -236,7 +269,7 @@ export function render() { " `; -exports[`comile > static template 1`] = ` +exports[`compile > static template 1`] = ` "import { template } from 'vue/vapor'; const t0 = template('

hello

'); export function render() { diff --git a/packages/compiler-vapor/__tests__/compile.test.ts b/packages/compiler-vapor/__tests__/compile.test.ts index 7d0c1d774f..ca355f2d29 100644 --- a/packages/compiler-vapor/__tests__/compile.test.ts +++ b/packages/compiler-vapor/__tests__/compile.test.ts @@ -16,7 +16,7 @@ async function compile( return code } -describe('comile', () => { +describe('compile', () => { test('static template', async () => { const code = await compile( `
@@ -33,6 +33,13 @@ describe('comile', () => { expect(code).matchSnapshot() }) + test('dynamic root nodes and interpolation', async () => { + const code = await compile( + ``, + ) + expect(code).matchSnapshot() + }) + test('static + dynamic root', async () => { const code = await compile( `{{ 1 }}{{ 2 }}3{{ 4 }}{{ 5 }}6{{ 7 }}{{ 8 }}9{{ 'A' }}{{ 'B' }}`, -- 2.47.3