]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(compiler-core): fix parsing error on comments between v-if in prod
authorEvan You <yyx990803@gmail.com>
Tue, 8 Nov 2022 15:35:35 +0000 (23:35 +0800)
committerEvan You <yyx990803@gmail.com>
Tue, 8 Nov 2022 15:35:35 +0000 (23:35 +0800)
close #6843

packages/compiler-core/__tests__/transforms/vIf.spec.ts
packages/compiler-core/src/transforms/vIf.ts

index 9ccce811486f9aeb8db336e96ba762c303595b99..225f6d6082cd951220457dd540c8c07c67d2871d 100644 (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', () => {
index 2faa16374eeb931d5d0faa9f9ace11cdabe1de76..636d9dff67320f36dd8e91e7a1ad90d5c12ec502 100644 (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
       }