fix: remove get children when no dynamic node

This commit is contained in:
三咲智子 Kevin Deng 2023-11-24 19:57:20 +08:00
parent b70aa0a9a0
commit 74031bac34
No known key found for this signature in database
GPG Key ID: 69992F2250DFD93E
5 changed files with 50 additions and 4 deletions

View File

@ -0,0 +1,23 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`comile > bindings 1`] = `
"import { watchEffect } from 'vue'
import { template, setText } from 'vue/vapor'
const t0 = template(\`<div></div>\`)
export function render() {
const root = t0()
watchEffect(() => {
setText(n0, undefined, count.value)
})
return root
}"
`;
exports[`comile > static template 1`] = `
"import { template } from 'vue/vapor'
const t0 = template(\`<div><p>hello</p><input></div>\`)
export function render() {
const root = t0()
return root
}"
`;

View File

@ -1,6 +1,6 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`basic 1`] = `
exports[`fixtures 1`] = `
"import { defineComponent as _defineComponent } from 'vue'
import { watchEffect } from 'vue'
import { template, insert, setText, on, setHtml } from 'vue/vapor'

View File

@ -0,0 +1,24 @@
import { BindingTypes } from '@vue/compiler-dom'
import { compile } from '../src'
describe('comile', () => {
it('static template', () => {
const { code } = compile(
`<div>
<p>hello</p>
<input />
</div>`,
{},
)
expect(code).matchSnapshot()
})
it('bindings', () => {
const { code } = compile(`<div>{{ count }}</div>`, {
bindingMetadata: {
count: BindingTypes.SETUP_REF,
},
})
expect(code).matchSnapshot()
})
})

View File

@ -1,9 +1,8 @@
import * as CompilerVapor from '../src'
// import * as CompilerDOM from '@vue/compiler-dom'
import { parse, compileScript } from '@vue/compiler-sfc'
import source from './fixtures/counter.vue?raw'
test('basic', async () => {
test('fixtures', async () => {
const { descriptor } = parse(source, { compiler: CompilerVapor })
const script = compileScript(descriptor, {
id: 'counter.vue',

View File

@ -29,7 +29,7 @@ export function generate(
// TODO multiple-template
code += `const root = t0()\n`
if (ir.children[0]) {
if (ir.children[0] && Object.keys(ir.children[0].children).length) {
code += `const {${genChildren(ir.children[0].children)}} = children(root)\n`
vaporHelpers.add('children')
}