Skip to content

Commit 89c5909

Browse files
authored
fix(compiler-core): allow spaces between if-else branches (#2305)
fix #2299
1 parent 25d53f0 commit 89c5909

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

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

+21
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,27 @@ describe('compiler: v-if', () => {
606606
expect(branch1.props).toMatchObject(createObjectMatcher({ key: `[0]` }))
607607
})
608608

609+
test('with spaces between branches', () => {
610+
const {
611+
node: { codegenNode }
612+
} = parseWithIfTransform(
613+
`<div v-if="ok"/> <div v-else-if="no"/> <div v-else/>`
614+
)
615+
expect(codegenNode.consequent).toMatchObject({
616+
tag: `"div"`,
617+
props: createObjectMatcher({ key: `[0]` })
618+
})
619+
const branch = codegenNode.alternate as ConditionalExpression
620+
expect(branch.consequent).toMatchObject({
621+
tag: `"div"`,
622+
props: createObjectMatcher({ key: `[1]` })
623+
})
624+
expect(branch.alternate).toMatchObject({
625+
tag: `"div"`,
626+
props: createObjectMatcher({ key: `[2]` })
627+
})
628+
})
629+
609630
test('with comments', () => {
610631
const { node } = parseWithIfTransform(`
611632
<template v-if="ok">

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

+10
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,16 @@ export function processIf(
130130
comments.unshift(sibling)
131131
continue
132132
}
133+
134+
if (
135+
sibling &&
136+
sibling.type === NodeTypes.TEXT &&
137+
!sibling.content.trim().length
138+
) {
139+
context.removeNode(sibling)
140+
continue
141+
}
142+
133143
if (sibling && sibling.type === NodeTypes.IF) {
134144
// move the node to the if node's branches
135145
context.removeNode()

0 commit comments

Comments
 (0)