feat(compiler): render <slot/> as block fragments
This commit is contained in:
@@ -1,12 +1,25 @@
|
||||
import { Slot } from '../componentSlots'
|
||||
import { VNodeChildren } from '../vnode'
|
||||
import {
|
||||
VNodeChildren,
|
||||
openBlock,
|
||||
createBlock,
|
||||
Fragment,
|
||||
VNode
|
||||
} from '../vnode'
|
||||
|
||||
export function renderSlot(
|
||||
slot: Slot | undefined,
|
||||
props: any = {},
|
||||
// this is not a user-facing function, so the fallback is always generated by
|
||||
// the compiler.
|
||||
fallback?: string | VNodeChildren
|
||||
): string | VNodeChildren | null {
|
||||
return slot ? slot() : fallback || null
|
||||
// the compiler and gurunteed to be an array
|
||||
fallback?: VNodeChildren
|
||||
): VNode {
|
||||
return (
|
||||
openBlock(),
|
||||
createBlock(
|
||||
Fragment,
|
||||
{ key: props.key },
|
||||
slot ? slot(props) : fallback || []
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user