]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
test: counter
author三咲智子 Kevin Deng <sxzz@sxzz.moe>
Thu, 23 Nov 2023 15:46:21 +0000 (23:46 +0800)
committer三咲智子 Kevin Deng <sxzz@sxzz.moe>
Thu, 23 Nov 2023 15:46:21 +0000 (23:46 +0800)
packages/compiler-vapor/__tests__/__snapshots__/basic.test.ts.snap
packages/compiler-vapor/__tests__/basic.test.ts
packages/compiler-vapor/__tests__/fixtures/counter.vue
packages/compiler-vapor/src/compile.ts
packages/compiler-vapor/src/transform.ts

index 133efc32cd81392e4f9a25820cd2052fa6f4b2ac..c00e8dbc719579c477eca2d1eea8c367e409919d 100644 (file)
@@ -2,16 +2,35 @@
 
 exports[`basic 1`] = `
 "import { defineComponent as _defineComponent } from 'vue'
-import { template } from 'vue/vapor'
-const t0 = template(\`<h1 id=\\"title\\">Counter</h1>\`)
+import { watchEffect } from 'vue'
+import { template, setAttr, setText, children, on, insert } from 'vue/vapor'
+const t0 = template(\`<h1 id=\\"title\\">Counter</h1><p>Count: </p><p>Double: </p><button>Increment</button>\`)
+import { ref, computed } from 'vue'
+
 
 export default /*#__PURE__*/_defineComponent({
   setup(__props) {
 
-console.log('script')
+const count = ref(0)
+const double = computed(() => count.value * 2)
+
+const increment = () => count.value++
 
 return (() => {
 const root = t0()
+const n1 = document.createTextNode(count.value)
+insert(n1, n0)
+const n3 = document.createTextNode(double.value)
+insert(n3, n2)
+watchEffect(() => {
+setText(n1, undefined, count.value)
+})
+watchEffect(() => {
+setText(n3, undefined, double.value)
+})
+watchEffect(() => {
+on(n4, \\"click\\", increment)
+})
 return root
 })();
 }
index f39764732f1f74c6fac6f2b5a50e1c25a7568763..dc83c2e706ca17c6550e25d10050a6983495c084 100644 (file)
@@ -8,7 +8,7 @@ test('basic', async () => {
   const script = compileScript(descriptor, {
     id: 'counter.vue',
     inlineTemplate: true,
-    templateOptions: { compiler: CompilerVapor }
+    templateOptions: { compiler: CompilerVapor },
   })
   expect(script.content).matchSnapshot()
 })
index 4aeca3bf64453b713cb6d20e17aa682274a4d577..9415168d7dc682754f9c38ea2036e89fe9a9886c 100644 (file)
@@ -1,7 +1,15 @@
 <script setup lang="ts">
-console.log('script')
+import { ref, computed } from 'vue'
+
+const count = ref(0)
+const double = computed(() => count.value * 2)
+
+const increment = () => count.value++
 </script>
 
 <template>
   <h1 id="title">Counter</h1>
+  <p>Count: {{ count }}</p>
+  <p>Double: {{ double }}</p>
+  <button @click="increment">Increment</button>
 </template>
index bda0210a9cca4dee21c41e176274858d3f6ac798..3c50396d4bebded677af62b15b6ee1701823c967 100644 (file)
@@ -2,7 +2,7 @@ import {
   CodegenResult,
   CompilerOptions,
   RootNode,
-  baseParse
+  baseParse,
 } from '@vue/compiler-dom'
 import { isString } from '@vue/shared'
 import { transform } from './transform'
@@ -11,7 +11,7 @@ import { generate } from './generate'
 // code/AST -> IR -> JS codegen
 export function compile(
   template: string | RootNode,
-  options: CompilerOptions
+  options: CompilerOptions,
 ): CodegenResult {
   const ast = isString(template) ? baseParse(template, options) : template
   const ir = transform(ast, options)
index 35f1d1b6cc8776ccaad8c14e2385d0fc5a61d728..a8c5774570b6f36b1769c99c1694c064eead730c 100644 (file)
@@ -198,8 +198,6 @@ export function transform(
   ctx.registerTemplate()
   ir.children = ctx.children
 
-  console.log(JSON.stringify(ir, undefined, 2))
-
   return ir
 }