]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
test(compile): add tests for v-on multi statements, v-slot, and v-for
authordaiwei <daiwei521@126.com>
Wed, 26 Nov 2025 07:25:48 +0000 (15:25 +0800)
committerdaiwei <daiwei521@126.com>
Wed, 26 Nov 2025 07:25:48 +0000 (15:25 +0800)
packages/compiler-vapor/__tests__/__snapshots__/compile.spec.ts.snap
packages/compiler-vapor/__tests__/compile.spec.ts

index 9527a9dbd6901f3b2640520a6a0d94f9746261e7..a5d422aed2a189d02727d54e3195a810b3c6d55b 100644 (file)
@@ -290,6 +290,48 @@ exports[`compile > expression parsing > v-bind 1`] = `
 "
 `;
 
+exports[`compile > expression parsing > v-for 1`] = `
+"import { createFor as _createFor, template as _template } from 'vue';
+const t0 = _template("<div></div>")
+
+export function render(_ctx) {
+  const n0 = _createFor(() => (_ctx.a.b), (_for_item0, _for_key0, _for_index0) => {
+    const n2 = t0()
+    return n2
+  })
+  return n0
+}"
+`;
+
+exports[`compile > expression parsing > v-on multi statements 1`] = `
+"import { createInvoker as _createInvoker, delegateEvents as _delegateEvents, template as _template } from 'vue';
+const t0 = _template("<div></div>", true)
+_delegateEvents("click")
+
+export function render(_ctx) {
+  const n0 = t0()
+  n0.$evtclick = _createInvoker(() => {_ctx.a++;_ctx.b++})
+  return n0
+}"
+`;
+
+exports[`compile > expression parsing > v-slot 1`] = `
+"import { resolveComponent as _resolveComponent, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, withVaporCtx as _withVaporCtx, createComponentWithFallback as _createComponentWithFallback, template as _template } from 'vue';
+const t0 = _template(" ")
+
+export function render(_ctx) {
+  const _component_Comp = _resolveComponent("Comp")
+  const n1 = _createComponentWithFallback(_component_Comp, null, {
+    "foo": _withVaporCtx((_slotProps0) => {
+      const n0 = t0()
+      _renderEffect(() => _setText(n0, _toDisplayString(_slotProps0["a"] + _slotProps0["b"])))
+      return n0
+    })
+  }, true)
+  return n1
+}"
+`;
+
 exports[`compile > fragment 1`] = `
 "import { template as _template } from 'vue';
 const t0 = _template("<p></p>")
index 58800e02c27abceca082bca2e72b9f2082b681cc..bec1bfc696a33618fbd31af4f4bf95d7f7ec3b1c 100644 (file)
@@ -85,7 +85,6 @@ describe('compile', () => {
         )
 
         expect(code).toMatchSnapshot()
-        // Waiting for TODO, There should be more here.
       })
     })
 
@@ -196,7 +195,26 @@ describe('compile', () => {
       )
     })
 
-    // TODO: add more test for expression parsing (v-on, v-slot, v-for)
+    test('v-on multi statements', () => {
+      const code = compile(`<div @click="a++;b++" />`, {
+        prefixIdentifiers: true,
+      })
+      expect(code).matchSnapshot()
+    })
+
+    test('v-slot', () => {
+      const code = compile(`<Comp #foo="{ a, b }">{{ a + b }}</Comp>`, {
+        prefixIdentifiers: true,
+      })
+      expect(code).matchSnapshot()
+    })
+
+    test('v-for', () => {
+      const code = compile(`<div v-for="({ a, b }, key, index) of a.b" />`, {
+        prefixIdentifiers: true,
+      })
+      expect(code).matchSnapshot()
+    })
   })
 
   describe('custom directive', () => {