fix(compiler-core): fix parsing error on comments between v-if in prod

close #6843
This commit is contained in:
Evan You 2022-11-08 23:35:35 +08:00
parent 64e6d9221d
commit dd3354c4c7
2 changed files with 23 additions and 2 deletions

View File

@ -712,6 +712,27 @@ describe('compiler: v-if', () => {
expect(b1.children[3].type).toBe(NodeTypes.ELEMENT)
expect((b1.children[3] as ElementNode).tag).toBe(`p`)
})
// #6843
test('should parse correctly with comments: true in prod', () => {
__DEV__ = false
parseWithIfTransform(
`
<template v-if="ok">
<!--comment1-->
<div v-if="ok2">
<!--comment2-->
</div>
<!--comment3-->
<b v-else/>
<!--comment4-->
<p/>
</template>
`,
{ comments: true }
)
__DEV__ = true
})
})
test('v-on with v-if', () => {

View File

@ -129,9 +129,9 @@ export function processIf(
let i = siblings.indexOf(node)
while (i-- >= -1) {
const sibling = siblings[i]
if (__DEV__ && sibling && sibling.type === NodeTypes.COMMENT) {
if (sibling && sibling.type === NodeTypes.COMMENT) {
context.removeNode(sibling)
comments.unshift(sibling)
__DEV__ && comments.unshift(sibling)
continue
}