From dd3354c4c709c0d76e651bb9202158434619cb6a Mon Sep 17 00:00:00 2001 From: Evan You Date: Tue, 8 Nov 2022 23:35:35 +0800 Subject: [PATCH] fix(compiler-core): fix parsing error on comments between v-if in prod close #6843 --- .../__tests__/transforms/vIf.spec.ts | 21 +++++++++++++++++++ packages/compiler-core/src/transforms/vIf.ts | 4 ++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/packages/compiler-core/__tests__/transforms/vIf.spec.ts b/packages/compiler-core/__tests__/transforms/vIf.spec.ts index 9ccce811486..225f6d6082c 100644 --- a/packages/compiler-core/__tests__/transforms/vIf.spec.ts +++ b/packages/compiler-core/__tests__/transforms/vIf.spec.ts @@ -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( + ` + + `, + { comments: true } + ) + __DEV__ = true + }) }) test('v-on with v-if', () => { diff --git a/packages/compiler-core/src/transforms/vIf.ts b/packages/compiler-core/src/transforms/vIf.ts index 2faa16374ee..636d9dff673 100644 --- a/packages/compiler-core/src/transforms/vIf.ts +++ b/packages/compiler-core/src/transforms/vIf.ts @@ -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 }