Skip to content

Commit 8bd6fc4

Browse files
committed
test(compiler-vapor): add test for v-if + v-if / v-else[-if] scenario
1 parent 8a6382c commit 8bd6fc4

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

packages/compiler-vapor/__tests__/transforms/__snapshots__/vIf.spec.ts.snap

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,29 @@ export function render(_ctx) {
134134
return n0
135135
}"
136136
`;
137+
138+
exports[`compiler: v-if > v-if + v-if / v-else[-if] 1`] = `
139+
"import { setInsertionState as _setInsertionState, createIf as _createIf, template as _template } from 'vue';
140+
const t0 = _template("<span>foo</span>")
141+
const t1 = _template("<span>bar</span>")
142+
const t2 = _template("<span>baz</span>")
143+
const t3 = _template("<div></div>", true)
144+
145+
export function render(_ctx) {
146+
const n8 = t3()
147+
_setInsertionState(n8)
148+
const n0 = _createIf(() => (_ctx.foo), () => {
149+
const n2 = t0()
150+
return n2
151+
})
152+
_setInsertionState(n8)
153+
const n3 = _createIf(() => (_ctx.bar), () => {
154+
const n5 = t1()
155+
return n5
156+
}, () => {
157+
const n7 = t2()
158+
return n7
159+
})
160+
return n8
161+
}"
162+
`;

packages/compiler-vapor/__tests__/transforms/vIf.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,17 @@ describe('compiler: v-if', () => {
215215
})
216216
})
217217

218+
test('v-if + v-if / v-else[-if]', () => {
219+
const { code } = compileWithVIf(
220+
`<div>
221+
<span v-if="foo">foo</span>
222+
<span v-if="bar">bar</span>
223+
<span v-else>baz</span>
224+
</div>`,
225+
)
226+
expect(code).toMatchSnapshot()
227+
})
228+
218229
test('comment between branches', () => {
219230
const { code, ir } = compileWithVIf(`
220231
<div v-if="ok"/>

packages/compiler-vapor/src/transforms/vIf.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,10 @@ export function processIf(
6868
if (
6969
siblings[i].operation &&
7070
siblings[i].operation!.type === IRNodeTypes.IF
71-
)
71+
) {
7272
lastIfNode = siblings[i].operation
73+
break
74+
}
7375
}
7476
}
7577

0 commit comments

Comments
 (0)