@@ -4,35 +4,35 @@ import { compileToFunctions } from 'vue-template-compiler'
44import { throwError } from 'shared/util'
55import { validateSlots } from './validate-slots'
66
7- function createFunctionalSlots ( slots = { } , h ) {
8- if ( Array . isArray ( slots . default ) ) {
9- return slots . default . map ( h )
10- }
7+ function startsWithTag ( str ) {
8+ return str && str . trim ( ) [ 0 ] === '<'
9+ }
1110
12- if ( typeof slots . default === 'string' ) {
13- return [ h ( compileToFunctions ( slots . default ) ) ]
11+ function createVNodeForFunctionalSlot ( slot , slotType , h ) {
12+ if ( typeof slot === 'string' && ! startsWithTag ( slot ) ) {
13+ return slot
1414 }
15- const children = [ ]
16- Object . keys ( slots ) . forEach ( slotType => {
15+
16+ const component =
17+ typeof slot === 'string' ? compileToFunctions ( slot ) : slot
18+ const newSlot = h ( component )
19+ newSlot . data . slot = slotType
20+ return newSlot
21+ }
22+
23+ function createFunctionalSlots ( slots = { } , h ) {
24+ return Object . keys ( slots ) . reduce ( ( children , slotType ) => {
1725 if ( Array . isArray ( slots [ slotType ] ) ) {
18- slots [ slotType ] . forEach ( slot => {
19- const component =
20- typeof slot === 'string' ? compileToFunctions ( slot ) : slot
21- const newSlot = h ( component )
22- newSlot . data . slot = slotType
23- children . push ( newSlot )
24- } )
25- } else {
26- const component =
27- typeof slots [ slotType ] === 'string'
28- ? compileToFunctions ( slots [ slotType ] )
29- : slots [ slotType ]
30- const slot = h ( component )
31- slot . data . slot = slotType
32- children . push ( slot )
26+ const mappedSlots = slots [ slotType ]
27+ . map ( slot => createVNodeForFunctionalSlot ( slot , slotType , h ) )
28+
29+ return children . concat ( mappedSlots )
3330 }
34- } )
35- return children
31+
32+ return children . concat (
33+ createVNodeForFunctionalSlot ( slots [ slotType ] , slotType , h )
34+ )
35+ } , [ ] )
3636}
3737
3838export default function createFunctionalComponent (
0 commit comments