2019-10-22 15:26:48 +00:00
|
|
|
import { Data } from '../component'
|
2020-02-25 04:05:35 +00:00
|
|
|
import { Slots } from '../componentSlots'
|
2019-10-03 16:03:14 +00:00
|
|
|
import {
|
2020-01-29 03:58:02 +00:00
|
|
|
VNodeArrayChildren,
|
2019-10-03 16:03:14 +00:00
|
|
|
openBlock,
|
|
|
|
createBlock,
|
|
|
|
Fragment,
|
|
|
|
VNode
|
|
|
|
} from '../vnode'
|
2019-10-03 19:09:09 +00:00
|
|
|
import { PatchFlags } from '@vue/shared'
|
2020-02-07 06:06:51 +00:00
|
|
|
import { warn } from '../warning'
|
2019-09-28 00:29:20 +00:00
|
|
|
|
|
|
|
export function renderSlot(
|
2020-02-25 04:05:35 +00:00
|
|
|
slots: Slots,
|
2019-10-03 19:09:09 +00:00
|
|
|
name: string,
|
2019-10-22 15:26:48 +00:00
|
|
|
props: Data = {},
|
2019-09-28 00:29:20 +00:00
|
|
|
// this is not a user-facing function, so the fallback is always generated by
|
2019-10-05 14:48:54 +00:00
|
|
|
// the compiler and guaranteed to be an array
|
2020-01-29 03:58:02 +00:00
|
|
|
fallback?: VNodeArrayChildren
|
2019-10-03 16:03:14 +00:00
|
|
|
): VNode {
|
2020-02-07 06:06:51 +00:00
|
|
|
let slot = slots[name]
|
|
|
|
|
2020-02-25 04:05:35 +00:00
|
|
|
if (__DEV__ && slot && slot.length > 1) {
|
2020-02-07 06:06:51 +00:00
|
|
|
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-03 16:03:14 +00:00
|
|
|
return (
|
|
|
|
openBlock(),
|
|
|
|
createBlock(
|
|
|
|
Fragment,
|
|
|
|
{ key: props.key },
|
2019-10-03 19:09:09 +00:00
|
|
|
slot ? slot(props) : fallback || [],
|
2020-02-25 15:41:44 +00:00
|
|
|
slots._ ? PatchFlags.STABLE_FRAGMENT : PatchFlags.BAIL
|
2019-10-03 16:03:14 +00:00
|
|
|
)
|
|
|
|
)
|
2019-09-28 00:29:20 +00:00
|
|
|
}
|