forked from vuejs/vue-test-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidate-slots.js
38 lines (33 loc) · 981 Bytes
/
validate-slots.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// @flow
import { throwError } from 'shared/util'
import { compileToFunctions } from 'vue-template-compiler'
import { isVueComponent } from './validators'
function isValidSlot (slot: any): boolean {
return (
isVueComponent(slot) ||
typeof slot === 'string'
)
}
function requiresTemplateCompiler (slot: any): void {
if (typeof slot === 'string' && !compileToFunctions) {
throwError(
`vueTemplateCompiler is undefined, you must pass ` +
`precompiled components if vue-template-compiler is ` +
`undefined`
)
}
}
export function validateSlots (slots: SlotsObject): void {
Object.keys(slots).forEach(key => {
const slot = Array.isArray(slots[key]) ? slots[key] : [slots[key]]
slot.forEach(slotValue => {
if (!isValidSlot(slotValue)) {
throwError(
`slots[key] must be a Component, string or an array ` +
`of Components`
)
}
requiresTemplateCompiler(slotValue)
})
})
}