Skip to content

Commit

Permalink
fix(compiler-core): fix parsing error on comments between v-if in prod
Browse files Browse the repository at this point in the history
close #6843
  • Loading branch information
yyx990803 committed Nov 8, 2022
1 parent 64e6d92 commit dd3354c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
21 changes: 21 additions & 0 deletions packages/compiler-core/__tests__/transforms/vIf.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/compiler-core/src/transforms/vIf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit dd3354c

Please sign in to comment.