2
2
3
3
import { compileToFunctions } from 'vue-template-compiler'
4
4
import { 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'
9
6
10
7
function createFunctionalSlots ( slots = { } , h ) {
11
8
if ( Array . isArray ( slots . default ) ) {
@@ -19,18 +16,12 @@ function createFunctionalSlots (slots = {}, h) {
19
16
Object . keys ( slots ) . forEach ( slotType => {
20
17
if ( Array . isArray ( slots [ slotType ] ) ) {
21
18
slots [ slotType ] . forEach ( slot => {
22
- if ( ! isValidSlot ( slot ) ) {
23
- throwError ( 'slots[key] must be a Component, string or an array of Components' )
24
- }
25
19
const component = typeof slot === 'string' ? compileToFunctions ( slot ) : slot
26
20
const newSlot = h ( component )
27
21
newSlot . data . slot = slotType
28
22
children . push ( newSlot )
29
23
} )
30
24
} else {
31
- if ( ! isValidSlot ( slots [ slotType ] ) ) {
32
- throwError ( 'slots[key] must be a Component, string or an array of Components' )
33
- }
34
25
const component = typeof slots [ slotType ] === 'string' ? compileToFunctions ( slots [ slotType ] ) : slots [ slotType ]
35
26
const slot = h ( component )
36
27
slot . data . slot = slotType
@@ -44,6 +35,9 @@ export default function createFunctionalComponent (component: Component, mountin
44
35
if ( mountingOptions . context && typeof mountingOptions . context !== 'object' ) {
45
36
throwError ( 'mount.context must be an object' )
46
37
}
38
+ if ( mountingOptions . slots ) {
39
+ validateSlots ( mountingOptions . slots )
40
+ }
47
41
48
42
return {
49
43
render ( h : Function ) {
0 commit comments