2019-10-02 23:10:41 -04:00
|
|
|
import { Slot } from '../componentSlots'
|
|
|
|
import { isArray } from '@vue/shared'
|
|
|
|
|
|
|
|
interface CompiledSlotDescriptor {
|
|
|
|
name: string
|
|
|
|
fn: Slot
|
|
|
|
}
|
|
|
|
|
2020-04-30 17:04:35 -04:00
|
|
|
/**
|
|
|
|
* Compiler runtime helper for creating dynamic slots object
|
2020-06-10 14:57:21 -04:00
|
|
|
* @private
|
2020-04-30 17:04:35 -04:00
|
|
|
*/
|
2019-10-02 23:10:41 -04:00
|
|
|
export function createSlots(
|
|
|
|
slots: Record<string, Slot>,
|
2020-02-26 21:43:27 -05:00
|
|
|
dynamicSlots: (
|
|
|
|
| CompiledSlotDescriptor
|
|
|
|
| CompiledSlotDescriptor[]
|
2021-07-19 18:24:18 -04:00
|
|
|
| undefined
|
|
|
|
)[]
|
2019-10-02 23:10:41 -04:00
|
|
|
): Record<string, Slot> {
|
|
|
|
for (let i = 0; i < dynamicSlots.length; i++) {
|
|
|
|
const slot = dynamicSlots[i]
|
|
|
|
// array of dynamic slot generated by <template v-for="..." #[...]>
|
|
|
|
if (isArray(slot)) {
|
|
|
|
for (let j = 0; j < slot.length; j++) {
|
2019-10-06 19:19:44 -05:00
|
|
|
slots[slot[j].name] = slot[j].fn
|
2019-10-02 23:10:41 -04:00
|
|
|
}
|
2020-02-26 21:43:27 -05:00
|
|
|
} else if (slot) {
|
2019-10-02 23:10:41 -04:00
|
|
|
// conditional single slot generated by <template v-if="..." #foo>
|
|
|
|
slots[slot.name] = slot.fn
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return slots
|
|
|
|
}
|