feat(compiler): render <slot/> as block fragments

This commit is contained in:
Evan You
2019-10-03 12:03:14 -04:00
parent fc47029ed3
commit aa9245d55c
12 changed files with 268 additions and 191 deletions

View File

@@ -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 || []
)
)
}