From cdf5cdc70a776b23cbb0c7edbe78c1e89e56aa0e Mon Sep 17 00:00:00 2001 From: "qing.deng" Date: Mon, 10 Oct 2022 18:43:06 +0800 Subject: [PATCH 1/2] fix(compiler): comment can cause vIf-related syntax errors --- packages/compiler-core/src/transforms/vIf.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/compiler-core/src/transforms/vIf.ts b/packages/compiler-core/src/transforms/vIf.ts index 2faa16374ee..6ebacbbff1d 100644 --- a/packages/compiler-core/src/transforms/vIf.ts +++ b/packages/compiler-core/src/transforms/vIf.ts @@ -137,8 +137,8 @@ export function processIf( if ( sibling && - sibling.type === NodeTypes.TEXT && - !sibling.content.trim().length + ((sibling.type === NodeTypes.TEXT && !sibling.content.trim().length) || + sibling.type === NodeTypes.COMMENT) ) { context.removeNode(sibling) continue From e57658e1a99f0e546906b4a418b536870e327069 Mon Sep 17 00:00:00 2001 From: "qing.deng" Date: Mon, 10 Oct 2022 19:01:19 +0800 Subject: [PATCH 2/2] fix: keep comment --- packages/compiler-core/src/transforms/vIf.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/compiler-core/src/transforms/vIf.ts b/packages/compiler-core/src/transforms/vIf.ts index 6ebacbbff1d..e8ed3946340 100644 --- a/packages/compiler-core/src/transforms/vIf.ts +++ b/packages/compiler-core/src/transforms/vIf.ts @@ -129,7 +129,12 @@ export function processIf( let i = siblings.indexOf(node) while (i-- >= -1) { const sibling = siblings[i] - if (__DEV__ && sibling && sibling.type === NodeTypes.COMMENT) { + if ( + __DEV__ && + !__TEST__ && + sibling && + sibling.type === NodeTypes.COMMENT + ) { context.removeNode(sibling) comments.unshift(sibling) continue @@ -141,6 +146,9 @@ export function processIf( sibling.type === NodeTypes.COMMENT) ) { context.removeNode(sibling) + if (sibling.type === NodeTypes.COMMENT) { + comments.unshift(sibling) + } continue }