From: daiwei Date: Tue, 25 Nov 2025 09:06:32 +0000 (+0800) Subject: test(compiler-vapor): add test for v-if with v-once X-Git-Tag: v3.6.0-alpha.6~36 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a32650abf6ea8bc02c800a0d860df65afe342a1f;p=thirdparty%2Fvuejs%2Fcore.git test(compiler-vapor): add test for v-if with v-once --- diff --git a/packages/compiler-vapor/__tests__/transforms/__snapshots__/vIf.spec.ts.snap b/packages/compiler-vapor/__tests__/transforms/__snapshots__/vIf.spec.ts.snap index ea76190cd0..608e4bac51 100644 --- a/packages/compiler-vapor/__tests__/transforms/__snapshots__/vIf.spec.ts.snap +++ b/packages/compiler-vapor/__tests__/transforms/__snapshots__/vIf.spec.ts.snap @@ -293,3 +293,18 @@ export function render(_ctx) { return [n0, n6] }" `; + +exports[`compiler: v-if > v-if with v-once 1`] = ` +"import { txt as _txt, toDisplayString as _toDisplayString, setText as _setText, createIf as _createIf, template as _template } from 'vue'; +const t0 = _template("
", true) + +export function render(_ctx) { + const n0 = _createIf(() => (_ctx.ok), () => { + const n2 = t0() + const x2 = _txt(n2) + _setText(x2, _toDisplayString(_ctx.msg)) + return n2 + }, null, true) + return n0 +}" +`; diff --git a/packages/compiler-vapor/__tests__/transforms/vIf.spec.ts b/packages/compiler-vapor/__tests__/transforms/vIf.spec.ts index 3bd39fc948..728b3f9c41 100644 --- a/packages/compiler-vapor/__tests__/transforms/vIf.spec.ts +++ b/packages/compiler-vapor/__tests__/transforms/vIf.spec.ts @@ -204,7 +204,14 @@ describe('compiler: v-if', () => { expect(ir.block.returns).toEqual([0, 3]) }) - test.todo('v-if with v-once') + test('v-if with v-once', () => { + const { code, ir, helpers } = compileWithVIf( + `
{{ msg }}
`, + ) + expect(code).matchSnapshot() + expect(helpers).contains('createIf') + expect([...ir.template.keys()]).toEqual(['
']) + }) test('component v-if', () => { const { code, ir, helpers } = compileWithVIf(