42 lines
		
	
	
		
			1003 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			42 lines
		
	
	
		
			1003 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| import { Data } from '../component'
 | |
| import { Slots } from '../componentSlots'
 | |
| import {
 | |
|   VNodeArrayChildren,
 | |
|   openBlock,
 | |
|   createBlock,
 | |
|   Fragment,
 | |
|   VNode
 | |
| } from '../vnode'
 | |
| import { PatchFlags } from '@vue/shared'
 | |
| import { warn } from '../warning'
 | |
| 
 | |
| export function renderSlot(
 | |
|   slots: Slots,
 | |
|   name: string,
 | |
|   props: Data = {},
 | |
|   // this is not a user-facing function, so the fallback is always generated by
 | |
|   // the compiler and guaranteed to be an array
 | |
|   fallback?: VNodeArrayChildren
 | |
| ): VNode {
 | |
|   let slot = slots[name]
 | |
| 
 | |
|   if (__DEV__ && slot && 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 = () => []
 | |
|   }
 | |
| 
 | |
|   return (
 | |
|     openBlock(),
 | |
|     createBlock(
 | |
|       Fragment,
 | |
|       { key: props.key },
 | |
|       slot ? slot(props) : fallback || [],
 | |
|       slots._ ? PatchFlags.STABLE_FRAGMENT : PatchFlags.BAIL
 | |
|     )
 | |
|   )
 | |
| }
 |