--- /dev/null
+// 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
+}"
+`;
// 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'
--- /dev/null
+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()
+ })
+})
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',
// 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')
}