22
33import { compileToFunctions } from 'vue-template-compiler'
44import { throwError } from 'shared/util'
5-
6- function isValidSlot ( slot : any ) : boolean {
7- return Array . isArray ( slot ) || ( slot !== null && typeof slot === 'object' ) || typeof slot === 'string'
8- }
5+ import { validateSlots } from './validate-slots'
96
107function createFunctionalSlots ( slots = { } , h ) {
118 if ( Array . isArray ( slots . default ) ) {
@@ -19,18 +16,12 @@ function createFunctionalSlots (slots = {}, h) {
1916 Object . keys ( slots ) . forEach ( slotType => {
2017 if ( Array . isArray ( slots [ slotType ] ) ) {
2118 slots [ slotType ] . forEach ( slot => {
22- if ( ! isValidSlot ( slot ) ) {
23- throwError ( 'slots[key] must be a Component, string or an array of Components' )
24- }
2519 const component = typeof slot === 'string' ? compileToFunctions ( slot ) : slot
2620 const newSlot = h ( component )
2721 newSlot . data . slot = slotType
2822 children . push ( newSlot )
2923 } )
3024 } else {
31- if ( ! isValidSlot ( slots [ slotType ] ) ) {
32- throwError ( 'slots[key] must be a Component, string or an array of Components' )
33- }
3425 const component = typeof slots [ slotType ] === 'string' ? compileToFunctions ( slots [ slotType ] ) : slots [ slotType ]
3526 const slot = h ( component )
3627 slot . data . slot = slotType
@@ -44,6 +35,9 @@ export default function createFunctionalComponent (component: Component, mountin
4435 if ( mountingOptions . context && typeof mountingOptions . context !== 'object' ) {
4536 throwError ( 'mount.context must be an object' )
4637 }
38+ if ( mountingOptions . slots ) {
39+ validateSlots ( mountingOptions . slots )
40+ }
4741
4842 return {
4943 render ( h : Function ) {
0 commit comments