forked from vuejs/vue-test-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidate-slots.js
46 lines (40 loc) · 1.15 KB
/
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
39
40
41
42
43
44
45
46
// @flow
import { throwError } from 'shared/util'
import { compileToFunctions } from 'vue-template-compiler'
function isValidSlot (slot: any): boolean {
return (
Array.isArray(slot) ||
(slot !== null && typeof slot === 'object') ||
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 => {
if (!isValidSlot(slots[key])) {
throwError(
`slots[key] must be a Component, string or an array ` + `of Components`
)
}
requiresTemplateCompiler(slots[key])
if (Array.isArray(slots[key])) {
slots[key].forEach(slotValue => {
if (!isValidSlot(slotValue)) {
throwError(
`slots[key] must be a Component, string or an array ` +
`of Components`
)
}
requiresTemplateCompiler(slotValue)
})
}
})
}