Skip to content

Commit 1b849a3

Browse files
committed
chore: update
1 parent a952b03 commit 1b849a3

File tree

4 files changed

+56
-32
lines changed

4 files changed

+56
-32
lines changed

packages/compiler-vapor/src/transform.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export class TransformContext<T extends AllNode = AllNode> {
7676

7777
inVOnce: boolean = false
7878
inVFor: number = 0
79-
inSlot: number = 0
79+
inSlot: boolean = false
8080

8181
comment: CommentNode[] = []
8282
component: Set<string> = this.ir.component

packages/compiler-vapor/src/transforms/transformSlotOutlet.ts

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
ErrorCodes,
66
NodeTypes,
77
type SimpleExpressionNode,
8-
type TemplateChildNode,
98
createCompilerError,
109
createSimpleExpression,
1110
isStaticArgOf,
@@ -100,24 +99,15 @@ export const transformSlotOutlet: NodeTransform = (node, context) => {
10099
}
101100

102101
return () => {
103-
const {
104-
block: { node: slotNode },
105-
inSlot,
106-
} = context
107-
const forwarded =
108-
inSlot !== 0 &&
109-
slotNode.type === NodeTypes.ELEMENT &&
110-
hasForwardedSlots(slotNode.children)
111-
if (forwarded) context.ir.hasForwardedSlot = true
112-
102+
if (context.inSlot) context.ir.hasForwardedSlot = true
113103
exitBlock && exitBlock()
114104
context.dynamic.operation = {
115105
type: IRNodeTypes.SLOT_OUTLET_NODE,
116106
id,
117107
name: slotName,
118108
props: irProps,
119109
fallback,
120-
forwarded,
110+
forwarded: context.inSlot,
121111
}
122112
}
123113
}
@@ -143,20 +133,3 @@ function createFallback(
143133
context.reference()
144134
return [fallback, exitBlock]
145135
}
146-
147-
function hasForwardedSlots(children: TemplateChildNode[]): boolean {
148-
for (let i = 0; i < children.length; i++) {
149-
const child = children[i]
150-
switch (child.type) {
151-
case NodeTypes.ELEMENT:
152-
if (
153-
child.tagType === ElementTypes.SLOT ||
154-
hasForwardedSlots(child.children)
155-
) {
156-
return true
157-
}
158-
break
159-
}
160-
}
161-
return false
162-
}

packages/compiler-vapor/src/transforms/vSlot.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,11 +237,11 @@ function createSlotBlock(
237237
const block: SlotBlockIRNode = newBlock(slotNode)
238238
block.props = dir && dir.exp
239239
const exitBlock = context.enterBlock(block)
240-
context.inSlot++
240+
context.inSlot = true
241241
return [
242242
block,
243243
() => {
244-
context.inSlot--
244+
context.inSlot = false
245245
exitBlock()
246246
},
247247
]

packages/runtime-vapor/__tests__/componentSlots.spec.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,5 +554,56 @@ describe('component: slots', () => {
554554
await nextTick()
555555
expect(host.innerHTML).toBe('bar<!--slot--><!--slot-->')
556556
})
557+
558+
test('mixed with non-forwarded slot', async () => {
559+
const Child = defineVaporComponent({
560+
setup() {
561+
return [createSlot('foo', null)]
562+
},
563+
})
564+
const Parent = defineVaporComponent({
565+
setup() {
566+
const createForwardedSlot = forwardedSlotCreator()
567+
const n2 = createComponent(Child, null, {
568+
foo: () => {
569+
const n0 = createForwardedSlot('foo', null)
570+
return n0
571+
},
572+
})
573+
const n3 = createSlot('default', null)
574+
return [n2, n3]
575+
},
576+
})
577+
578+
const foo = ref('foo')
579+
const { host } = define({
580+
setup() {
581+
const n2 = createComponent(
582+
Parent,
583+
null,
584+
{
585+
foo: () => {
586+
const n0 = template(' ')() as any
587+
renderEffect(() => setText(n0, foo.value))
588+
return n0
589+
},
590+
default: () => {
591+
const n3 = template(' ')() as any
592+
renderEffect(() => setText(n3, foo.value))
593+
return n3
594+
},
595+
},
596+
true,
597+
)
598+
return n2
599+
},
600+
}).render()
601+
602+
expect(host.innerHTML).toBe('foo<!--slot--><!--slot-->foo<!--slot-->')
603+
604+
foo.value = 'bar'
605+
await nextTick()
606+
expect(host.innerHTML).toBe('bar<!--slot--><!--slot-->bar<!--slot-->')
607+
})
557608
})
558609
})

0 commit comments

Comments
 (0)