2019-10-22 23:26:48 +08:00
|
|
|
import { Data } from '../component'
|
2019-09-28 08:29:20 +08:00
|
|
|
import { Slot } from '../componentSlots'
|
2019-10-04 00:03:14 +08:00
|
|
|
import {
|
2020-01-29 11:58:02 +08:00
|
|
|
VNodeArrayChildren,
|
2019-10-04 00:03:14 +08:00
|
|
|
openBlock,
|
|
|
|
createBlock,
|
|
|
|
Fragment,
|
|
|
|
VNode
|
|
|
|
} from '../vnode'
|
2019-10-04 03:09:09 +08:00
|
|
|
import { PatchFlags } from '@vue/shared'
|
2020-02-07 14:06:51 +08:00
|
|
|
import { warn } from '../warning'
|
2019-09-28 08:29:20 +08:00
|
|
|
|
|
|
|
export function renderSlot(
|
2019-10-04 02:29:12 +08:00
|
|
|
slots: Record<string, Slot>,
|
2019-10-04 03:09:09 +08:00
|
|
|
name: string,
|
2019-10-22 23:26:48 +08:00
|
|
|
props: Data = {},
|
2019-09-28 08:29:20 +08:00
|
|
|
// this is not a user-facing function, so the fallback is always generated by
|
2019-10-05 22:48:54 +08:00
|
|
|
// the compiler and guaranteed to be an array
|
2020-01-29 11:58:02 +08:00
|
|
|
fallback?: VNodeArrayChildren
|
2019-10-04 00:03:14 +08:00
|
|
|
): VNode {
|
2020-02-07 14:06:51 +08:00
|
|
|
let slot = slots[name]
|
|
|
|
|
|
|
|
if (__DEV__ && slot.length > 1) {
|
|
|
|
warn(
|
|
|
|
`SSR-optimized slot function detected in a non-SSR-optimized render ` +
|
|
|
|
`function. You need to mark this component with $dynamic-slots in the ` +
|
|
|
|
`parent template.`
|
|
|
|
)
|
|
|
|
slot = () => []
|
|
|
|
}
|
|
|
|
|
2019-10-04 00:03:14 +08:00
|
|
|
return (
|
|
|
|
openBlock(),
|
|
|
|
createBlock(
|
|
|
|
Fragment,
|
|
|
|
{ key: props.key },
|
2019-10-04 03:09:09 +08:00
|
|
|
slot ? slot(props) : fallback || [],
|
2020-02-13 02:45:35 +08:00
|
|
|
slots._ ? 0 : PatchFlags.BAIL
|
2019-10-04 00:03:14 +08:00
|
|
|
)
|
|
|
|
)
|
2019-09-28 08:29:20 +08:00
|
|
|
}
|