Просмотр исходного кода

fix(compiler-core): fix forwarded slots detection on template slots (#4124)

fix #4123
edison 5 лет назад
Родитель
Сommit
c23153d82e

+ 7 - 0
packages/compiler-core/__tests__/transforms/vSlot.spec.ts

@@ -771,6 +771,13 @@ describe('compiler: transform component slots', () => {
       const { slots } = parseWithSlots(`<Comp><slot v-for="a in b"/></Comp>`)
       expect(slots).toMatchObject(toMatch)
     })
+
+    test('<slot> tag w/ template', () => {
+      const { slots } = parseWithSlots(
+        `<Comp><template #default><slot/></template></Comp>`
+      )
+      expect(slots).toMatchObject(toMatch)
+    })
   })
 
   describe('errors', () => {

+ 2 - 1
packages/compiler-core/src/transforms/vSlot.ts

@@ -384,7 +384,8 @@ function hasForwardedSlots(children: TemplateChildNode[]): boolean {
       case NodeTypes.ELEMENT:
         if (
           child.tagType === ElementTypes.SLOT ||
-          (child.tagType === ElementTypes.ELEMENT &&
+          ((child.tagType === ElementTypes.ELEMENT ||
+            child.tagType === ElementTypes.TEMPLATE) &&
             hasForwardedSlots(child.children))
         ) {
           return true