]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(compiler-core): should not remove slot node with `v-else` (#11150)
author_Kerman <kermanx@qq.com>
Sat, 22 Jun 2024 09:08:39 +0000 (17:08 +0800)
committerGitHub <noreply@github.com>
Sat, 22 Jun 2024 09:08:39 +0000 (17:08 +0800)
packages/compiler-core/__tests__/transforms/vSlot.spec.ts
packages/compiler-core/src/transforms/vSlot.ts

index aa7b600ccbebf9354bbe0823a3968631d4a6c1d3..3afcf0fc0536674bf8e469ec6dfecb37d90ee055 100644 (file)
@@ -696,6 +696,7 @@ describe('compiler: transform component slots', () => {
     expect((root as any).children[0].codegenNode.patchFlag).toMatch(
       PatchFlags.DYNAMIC_SLOTS + '',
     )
+    expect((root as any).children[0].children.length).toBe(3)
     expect(generate(root).code).toMatchSnapshot()
   })
 
index 1b95e6f71dbfa2c61f1fa648d3ff5f255a2bf305..db367f39c0c2a6adc9d3a7c3ac5f3c64e04a41f9 100644 (file)
@@ -226,10 +226,7 @@ export function buildSlots(
           break
         }
       }
-      if (prev && isTemplateNode(prev) && findDir(prev, 'if')) {
-        // remove node
-        children.splice(i, 1)
-        i--
+      if (prev && isTemplateNode(prev) && findDir(prev, /^(else-)?if$/)) {
         __TEST__ && assert(dynamicSlots.length > 0)
         // attach this slot to previous conditional
         let conditional = dynamicSlots[