From 48c8b3565431ee54788214e9f9f62f87f3fb94cb Mon Sep 17 00:00:00 2001 From: zhangyu96 Date: Fri, 6 Aug 2021 17:28:49 +0800 Subject: [PATCH 1/2] fix(compiler-core): nested component w/ slot --- .../compiler-core/__tests__/transforms/vSlot.spec.ts | 7 +++++++ packages/compiler-core/src/transforms/vSlot.ts | 10 +++------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/packages/compiler-core/__tests__/transforms/vSlot.spec.ts b/packages/compiler-core/__tests__/transforms/vSlot.spec.ts index bb26d668931..4a7df1e8dfe 100644 --- a/packages/compiler-core/__tests__/transforms/vSlot.spec.ts +++ b/packages/compiler-core/__tests__/transforms/vSlot.spec.ts @@ -778,6 +778,13 @@ describe('compiler: transform component slots', () => { ) expect(slots).toMatchObject(toMatch) }) + + test('', () => { + const { slots } = parseWithSlots( + `` + ) + expect(slots).toMatchObject(toMatch) + }) }) describe('errors', () => { diff --git a/packages/compiler-core/src/transforms/vSlot.ts b/packages/compiler-core/src/transforms/vSlot.ts index 68aa1f67ccd..c127fb9a17f 100644 --- a/packages/compiler-core/src/transforms/vSlot.ts +++ b/packages/compiler-core/src/transforms/vSlot.ts @@ -382,15 +382,11 @@ function hasForwardedSlots(children: TemplateChildNode[]): boolean { const child = children[i] switch (child.type) { case NodeTypes.ELEMENT: - if ( - child.tagType === ElementTypes.SLOT || - ((child.tagType === ElementTypes.ELEMENT || - child.tagType === ElementTypes.TEMPLATE) && - hasForwardedSlots(child.children)) - ) { + if ( child.tagType === ElementTypes.SLOT ) { return true + } else { + return hasForwardedSlots(child.children) } - break case NodeTypes.IF: if (hasForwardedSlots(child.branches)) return true break From 9338136a851d05cdae168b25fe08ebd7dade288a Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 6 Aug 2021 22:27:07 -0400 Subject: [PATCH 2/2] Update vSlot.ts --- packages/compiler-core/src/transforms/vSlot.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/compiler-core/src/transforms/vSlot.ts b/packages/compiler-core/src/transforms/vSlot.ts index c127fb9a17f..8fc86740eb6 100644 --- a/packages/compiler-core/src/transforms/vSlot.ts +++ b/packages/compiler-core/src/transforms/vSlot.ts @@ -382,11 +382,13 @@ function hasForwardedSlots(children: TemplateChildNode[]): boolean { const child = children[i] switch (child.type) { case NodeTypes.ELEMENT: - if ( child.tagType === ElementTypes.SLOT ) { + if ( + child.tagType === ElementTypes.SLOT || + hasForwardedSlots(child.children) + ) { return true - } else { - return hasForwardedSlots(child.children) } + break case NodeTypes.IF: if (hasForwardedSlots(child.branches)) return true break