From: daiwei Date: Thu, 12 Jun 2025 09:22:18 +0000 (+0800) Subject: test(compiler-vapor): add test for v-if + v-if / v-else[-if] scenario X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F13399%2Fhead;p=thirdparty%2Fvuejs%2Fcore.git test(compiler-vapor): add test for v-if + v-if / v-else[-if] scenario --- 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 16ab6ae372..c41dc9226c 100644 --- a/packages/compiler-vapor/__tests__/transforms/__snapshots__/vIf.spec.ts.snap +++ b/packages/compiler-vapor/__tests__/transforms/__snapshots__/vIf.spec.ts.snap @@ -134,3 +134,29 @@ export function render(_ctx) { return n0 }" `; + +exports[`compiler: v-if > v-if + v-if / v-else[-if] 1`] = ` +"import { setInsertionState as _setInsertionState, createIf as _createIf, template as _template } from 'vue'; +const t0 = _template("foo") +const t1 = _template("bar") +const t2 = _template("baz") +const t3 = _template("
", true) + +export function render(_ctx) { + const n8 = t3() + _setInsertionState(n8) + const n0 = _createIf(() => (_ctx.foo), () => { + const n2 = t0() + return n2 + }) + _setInsertionState(n8) + const n3 = _createIf(() => (_ctx.bar), () => { + const n5 = t1() + return n5 + }, () => { + const n7 = t2() + return n7 + }) + return n8 +}" +`; diff --git a/packages/compiler-vapor/__tests__/transforms/vIf.spec.ts b/packages/compiler-vapor/__tests__/transforms/vIf.spec.ts index 66cdf7b930..f51988e2e4 100644 --- a/packages/compiler-vapor/__tests__/transforms/vIf.spec.ts +++ b/packages/compiler-vapor/__tests__/transforms/vIf.spec.ts @@ -215,6 +215,17 @@ describe('compiler: v-if', () => { }) }) + test('v-if + v-if / v-else[-if]', () => { + const { code } = compileWithVIf( + `
+ foo + bar + baz +
`, + ) + expect(code).toMatchSnapshot() + }) + test('comment between branches', () => { const { code, ir } = compileWithVIf(`
diff --git a/packages/compiler-vapor/src/transforms/vIf.ts b/packages/compiler-vapor/src/transforms/vIf.ts index e69d1901b4..bae9f1aa23 100644 --- a/packages/compiler-vapor/src/transforms/vIf.ts +++ b/packages/compiler-vapor/src/transforms/vIf.ts @@ -68,8 +68,10 @@ export function processIf( if ( siblings[i].operation && siblings[i].operation!.type === IRNodeTypes.IF - ) + ) { lastIfNode = siblings[i].operation + break + } } }