Skip to content

Commit

Permalink
fix: remove get children when no dynamic node
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz committed Nov 24, 2023
1 parent b70aa0a commit 74031ba
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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
}"
`;
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
24 changes: 24 additions & 0 deletions packages/compiler-vapor/__tests__/compile.test.ts
Original file line number Diff line number Diff line change
@@ -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()
})
})
Original file line number Diff line number Diff line change
@@ -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',
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler-vapor/src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
Expand Down

0 comments on commit 74031ba

Please sign in to comment.