fix(compiler-core): allow spaces between if-else branches (#2305)
fix #2299
This commit is contained in:
parent
25d53f09bb
commit
89c5909a6f
@ -606,6 +606,27 @@ describe('compiler: v-if', () => {
|
|||||||
expect(branch1.props).toMatchObject(createObjectMatcher({ key: `[0]` }))
|
expect(branch1.props).toMatchObject(createObjectMatcher({ key: `[0]` }))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('with spaces between branches', () => {
|
||||||
|
const {
|
||||||
|
node: { codegenNode }
|
||||||
|
} = parseWithIfTransform(
|
||||||
|
`<div v-if="ok"/> <div v-else-if="no"/> <div v-else/>`
|
||||||
|
)
|
||||||
|
expect(codegenNode.consequent).toMatchObject({
|
||||||
|
tag: `"div"`,
|
||||||
|
props: createObjectMatcher({ key: `[0]` })
|
||||||
|
})
|
||||||
|
const branch = codegenNode.alternate as ConditionalExpression
|
||||||
|
expect(branch.consequent).toMatchObject({
|
||||||
|
tag: `"div"`,
|
||||||
|
props: createObjectMatcher({ key: `[1]` })
|
||||||
|
})
|
||||||
|
expect(branch.alternate).toMatchObject({
|
||||||
|
tag: `"div"`,
|
||||||
|
props: createObjectMatcher({ key: `[2]` })
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
test('with comments', () => {
|
test('with comments', () => {
|
||||||
const { node } = parseWithIfTransform(`
|
const { node } = parseWithIfTransform(`
|
||||||
<template v-if="ok">
|
<template v-if="ok">
|
||||||
|
@ -130,6 +130,16 @@ export function processIf(
|
|||||||
comments.unshift(sibling)
|
comments.unshift(sibling)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
sibling &&
|
||||||
|
sibling.type === NodeTypes.TEXT &&
|
||||||
|
!sibling.content.trim().length
|
||||||
|
) {
|
||||||
|
context.removeNode(sibling)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
if (sibling && sibling.type === NodeTypes.IF) {
|
if (sibling && sibling.type === NodeTypes.IF) {
|
||||||
// move the node to the if node's branches
|
// move the node to the if node's branches
|
||||||
context.removeNode()
|
context.removeNode()
|
||||||
|
Loading…
Reference in New Issue
Block a user