11// @flow
22
3- import { createSlotVNodes } from './add-slots'
3+ import Vue from 'vue'
4+ import { compileToFunctions } from 'vue-template-compiler'
5+ import { createSlotVNodes } from './create-slot-vnodes'
46import addMocks from './add-mocks'
57import { addEventLogger } from './log-events'
68import { createComponentStubs } from 'shared/stub-components'
@@ -12,7 +14,65 @@ import { componentNeedsCompiling } from 'shared/validators'
1214import { validateSlots } from './validate-slots'
1315import createScopedSlots from './create-scoped-slots'
1416
15- export default function createInstance (
17+ const _renderSlot = Vue . prototype . _t
18+
19+ function createVNodes (
20+ vm : Component ,
21+ slotValue : Component | string
22+ ) : Array < VNode > {
23+ if ( typeof slotValue === 'string' ) {
24+ const compiledResult = compileToFunctions ( `<div>${ slotValue } {{ }}</div>` )
25+ const _staticRenderFns = vm . _renderProxy . $options . staticRenderFns
26+ vm . _renderProxy . $options . staticRenderFns = compiledResult . staticRenderFns
27+ const elem = compiledResult . render . call (
28+ vm . _renderProxy , vm . $createElement
29+ ) . children
30+ vm . _renderProxy . $options . staticRenderFns = _staticRenderFns
31+ return elem
32+ }
33+ return [ vm . $createElement ( slotValue ) ]
34+ }
35+
36+ export function createRenderSlot (
37+ options : Object
38+ ) : (
39+ name : string ,
40+ fallback : ?Array < VNode > ,
41+ props : ?Object ,
42+ bindObject : ?Object
43+ ) = > ?Array < VNode > {
44+ return function renderSlot (
45+ name : string ,
46+ fallback : ?Array < VNode > ,
47+ props : ?Object ,
48+ bindObject : ?Object
49+ ) : ?Array < VNode > {
50+ if ( createVNodes && options . slots && options . slots [ name ] ) {
51+ const slotsValue = options . slots [ name ]
52+ if ( Array . isArray ( slotsValue ) ) {
53+ this . $slots [ name ] = [ ]
54+ for ( let i = 0 ; i < slotsValue . length ; i ++ ) {
55+ const _slotValue = slotsValue [ i ]
56+ if ( typeof _slotValue === 'string' ) {
57+ const slots = createVNodes ( this , _slotValue )
58+ if ( Array . isArray ( slots ) ) {
59+ this . $slots [ name ] . push ( ...slots )
60+ } else {
61+ this . $slots [ name ] . push ( slots )
62+ }
63+ } else {
64+ this . $slots [ name ] . push ( this . $createElement ( _slotValue ) )
65+ }
66+ }
67+ } else {
68+ this . $slots [ name ] = createVNodes ( this , slotsValue )
69+ }
70+ }
71+ return _renderSlot . call ( this , name, fallback, props, bindObject)
72+ }
73+ }
74+
75+ export function createInstance (
1676 component : Component ,
1777 options : Options ,
1878 _Vue : Component ,
0 commit comments