Skip to content

Commit 9633b9c

Browse files
committed
fix(compiler-vapor): properly locate last if node
vuejs/core#13399
1 parent 9668a0e commit 9633b9c

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

packages/compiler/src/transforms/vIf.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,13 @@ export function processIf(
6363
if (siblings) {
6464
let i = siblings.length
6565
while (i--) {
66-
if (siblings[i].operation) lastIfNode = siblings[i].operation
66+
if (
67+
siblings[i].operation &&
68+
siblings[i].operation!.type === IRNodeTypes.IF
69+
) {
70+
lastIfNode = siblings[i].operation
71+
break
72+
}
6773
}
6874
}
6975

packages/compiler/test/transforms/__snapshots__/vIf.spec.ts.snap

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,23 @@ exports[`compiler: v-if > v-if + v-else-if 1`] = `
9898
return n0
9999
"
100100
`;
101+
102+
exports[`compiler: v-if > v-if + v-if / v-else[-if] 1`] = `
103+
"
104+
const n8 = t3()
105+
_setInsertionState(n8)
106+
const n0 = _createIf(() => ("foo"), () => {
107+
const n2 = t0()
108+
return n2
109+
}, null, true)
110+
_setInsertionState(n8)
111+
const n3 = _createIf(() => ("bar"), () => {
112+
const n5 = t1()
113+
return n5
114+
}, () => {
115+
const n7 = t2()
116+
return n7
117+
}, true)
118+
return n8
119+
"
120+
`;

packages/compiler/test/transforms/vIf.spec.ts

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

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

0 commit comments

Comments
 (0)