2019-10-22 23:26:48 +08:00
|
|
|
import { Data } from '../component'
|
2020-07-16 08:12:49 +08:00
|
|
|
import { Slots, RawSlots } 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'
|
2020-07-16 08:12:49 +08:00
|
|
|
import { PatchFlags, SlotFlags } from '@vue/shared'
|
2020-02-07 14:06:51 +08:00
|
|
|
import { warn } from '../warning'
|
2019-09-28 08:29:20 +08:00
|
|
|
|
2020-05-01 05:04:35 +08:00
|
|
|
/**
|
|
|
|
* Compiler runtime helper for rendering <slot/>
|
2020-06-11 02:57:21 +08:00
|
|
|
* @private
|
2020-05-01 05:04:35 +08:00
|
|
|
*/
|
2019-09-28 08:29:20 +08:00
|
|
|
export function renderSlot(
|
2020-02-25 12:05:35 +08:00
|
|
|
slots: Slots,
|
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
|
2020-04-23 04:52:41 +08:00
|
|
|
// the compiler and guaranteed to be a function returning an array
|
|
|
|
fallback?: () => VNodeArrayChildren
|
2019-10-04 00:03:14 +08:00
|
|
|
): VNode {
|
2020-02-07 14:06:51 +08:00
|
|
|
let slot = slots[name]
|
|
|
|
|
2020-02-25 12:05:35 +08:00
|
|
|
if (__DEV__ && slot && slot.length > 1) {
|
2020-02-07 14:06:51 +08: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-04 00:03:14 +08:00
|
|
|
return (
|
|
|
|
openBlock(),
|
|
|
|
createBlock(
|
|
|
|
Fragment,
|
|
|
|
{ key: props.key },
|
2020-04-23 04:52:41 +08:00
|
|
|
slot ? slot(props) : fallback ? fallback() : [],
|
2020-07-16 08:12:49 +08:00
|
|
|
(slots as RawSlots)._ === SlotFlags.STABLE
|
2020-07-14 00:36:41 +08:00
|
|
|
? PatchFlags.STABLE_FRAGMENT
|
|
|
|
: PatchFlags.BAIL
|
2019-10-04 00:03:14 +08:00
|
|
|
)
|
|
|
|
)
|
2019-09-28 08:29:20 +08:00
|
|
|
}
|