feat(compiler): transform slot outlets

This commit is contained in:
Evan You
2019-09-27 20:29:20 -04:00
parent d900c13efb
commit ee66ce78b7
10 changed files with 480 additions and 28 deletions

View File

@@ -1,10 +1,16 @@
import { ComponentInternalInstance, currentInstance } from './component'
import { VNode, NormalizedChildren, normalizeVNode, VNodeChild } from './vnode'
import {
VNode,
NormalizedChildren,
normalizeVNode,
VNodeChild,
VNodeChildren
} from './vnode'
import { isArray, isFunction } from '@vue/shared'
import { ShapeFlags } from './shapeFlags'
import { warn } from './warning'
export type Slot = (...args: any[]) => VNode[]
export type Slot = (...args: any[]) => VNodeChildren
export type Slots = Readonly<{
[name: string]: Slot
}>

View File

@@ -0,0 +1,12 @@
import { Slot } from '../componentSlots'
import { VNodeChildren } 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
}

View File

@@ -42,6 +42,7 @@ export { resolveComponent, resolveDirective } from './helpers/resolveAssets'
export { renderList } from './helpers/renderList'
export { toString } from './helpers/toString'
export { toHandlers } from './helpers/toHandlers'
export { renderSlot } from './helpers/renderSlot'
export { capitalize, camelize } from '@vue/shared'
// Internal, for integration with runtime compiler