@@ -182,20 +182,11 @@ function genData (el: ASTElement): string {
182
182
}
183
183
// inline-template
184
184
if ( el . inlineTemplate ) {
185
- const ast = el . children [ 0 ]
186
- if ( process . env . NODE_ENV !== 'production' && (
187
- el . children . length > 1 || ast . type !== 1
188
- ) ) {
189
- warn ( 'Inline-template components must have exactly one child element.' )
190
- }
191
- if ( ast . type === 1 ) {
192
- const inlineRenderFns = generate ( ast , currentOptions )
193
- data += `inlineTemplate:{render:function(){${
194
- inlineRenderFns . render
195
- } },staticRenderFns:[${
196
- inlineRenderFns . staticRenderFns . map ( code => `function(){${ code } }` ) . join ( ',' )
197
- } ]}`
198
- }
185
+ data += `${ genInlineTemplate ( el ) } ,`
186
+ }
187
+ // scoped slots
188
+ if ( el . scopedSlots ) {
189
+ data += `${ genScopedSlots ( el . scopedSlots ) } ,`
199
190
}
200
191
data = data . replace ( / , $ / , '' ) + '}'
201
192
// v-bind data wrap
@@ -236,6 +227,39 @@ function genDirectives (el: ASTElement): string | void {
236
227
}
237
228
}
238
229
230
+ function genInlineTemplate ( el ) {
231
+ const ast = el . children [ 0 ]
232
+ if ( process . env . NODE_ENV !== 'production' && (
233
+ el . children . length > 1 || ast . type !== 1
234
+ ) ) {
235
+ warn ( 'Inline-template components must have exactly one child element.' )
236
+ }
237
+ if ( ast . type === 1 ) {
238
+ const inlineRenderFns = generate ( ast , currentOptions )
239
+ return `inlineTemplate:{render:function(){${
240
+ inlineRenderFns . render
241
+ } },staticRenderFns:[${
242
+ inlineRenderFns . staticRenderFns . map ( code => `function(){${ code } }` ) . join ( ',' )
243
+ } ]}`
244
+ } else {
245
+ return ''
246
+ }
247
+ }
248
+
249
+ function genScopedSlots ( slots ) {
250
+ return `scopedSlots:{${
251
+ Object . keys ( slots ) . map ( key => genScopedSlot ( key , slots [ key ] ) ) . join ( ',' )
252
+ } }`
253
+ }
254
+
255
+ function genScopedSlot ( key : string , el : ASTElement ) {
256
+ return `${ key } :function(${ String ( el . attrsMap . scope ) } ){` +
257
+ `return ${ el . tag === 'template'
258
+ ? genChildren ( el ) || 'void 0'
259
+ : genElement ( el )
260
+ } }`
261
+ }
262
+
239
263
function genChildren ( el : ASTElement ) : string | void {
240
264
if ( el . children . length ) {
241
265
return '[' + el . children . map ( genNode ) . join ( ',' ) + ']'
0 commit comments