Răsfoiți Sursa

fix: ensure generated scoped slot code is compatible with 2.5

fix #9545
Evan You 7 ani în urmă
părinte
comite
7ec4627902

+ 2 - 2
src/compiler/codegen/index.js

@@ -409,9 +409,9 @@ function genScopedSlots (
     .join(',')
     .join(',')
 
 
   return `scopedSlots:_u([${generatedSlots}]${
   return `scopedSlots:_u([${generatedSlots}]${
-    needsForceUpdate ? `,true` : ``
+    needsForceUpdate ? `,null,true` : ``
   }${
   }${
-    !needsForceUpdate && needsKey ? `,false,${hash(generatedSlots)}` : ``
+    !needsForceUpdate && needsKey ? `,null,false,${hash(generatedSlots)}` : ``
   })`
   })`
 }
 }
 
 

+ 6 - 5
src/core/instance/render-helpers/resolve-scoped-slots.js

@@ -2,15 +2,16 @@
 
 
 export function resolveScopedSlots (
 export function resolveScopedSlots (
   fns: ScopedSlotsData, // see flow/vnode
   fns: ScopedSlotsData, // see flow/vnode
-  hasDynamicKeys: boolean,
-  contentHashKey: number,
-  res?: Object
+  res?: Object,
+  // the following are added in 2.6
+  hasDynamicKeys?: boolean,
+  contentHashKey?: number
 ): { [key: string]: Function, $stable: boolean } {
 ): { [key: string]: Function, $stable: boolean } {
   res = res || { $stable: !hasDynamicKeys }
   res = res || { $stable: !hasDynamicKeys }
   for (let i = 0; i < fns.length; i++) {
   for (let i = 0; i < fns.length; i++) {
     const slot = fns[i]
     const slot = fns[i]
     if (Array.isArray(slot)) {
     if (Array.isArray(slot)) {
-      resolveScopedSlots(slot, hasDynamicKeys, null, res)
+      resolveScopedSlots(slot, res, hasDynamicKeys)
     } else if (slot) {
     } else if (slot) {
       // marker for reverse proxying v-slot without scope on this.$slots
       // marker for reverse proxying v-slot without scope on this.$slots
       if (slot.proxy) {
       if (slot.proxy) {
@@ -20,7 +21,7 @@ export function resolveScopedSlots (
     }
     }
   }
   }
   if (contentHashKey) {
   if (contentHashKey) {
-    res.$key = contentHashKey
+    (res: any).$key = contentHashKey
   }
   }
   return res
   return res
 }
 }

+ 4 - 4
test/unit/modules/compiler/codegen.spec.js

@@ -232,25 +232,25 @@ describe('codegen', () => {
   it('generate dynamic scoped slot', () => {
   it('generate dynamic scoped slot', () => {
     assertCodegen(
     assertCodegen(
       '<foo><template :slot="foo" slot-scope="bar">{{ bar }}</template></foo>',
       '<foo><template :slot="foo" slot-scope="bar">{{ bar }}</template></foo>',
-      `with(this){return _c('foo',{scopedSlots:_u([{key:foo,fn:function(bar){return [_v(_s(bar))]}}],true)})}`
+      `with(this){return _c('foo',{scopedSlots:_u([{key:foo,fn:function(bar){return [_v(_s(bar))]}}],null,true)})}`
     )
     )
   })
   })
 
 
   it('generate scoped slot with multiline v-if', () => {
   it('generate scoped slot with multiline v-if', () => {
     assertCodegen(
     assertCodegen(
       '<foo><template v-if="\nshow\n" slot-scope="bar">{{ bar }}</template></foo>',
       '<foo><template v-if="\nshow\n" slot-scope="bar">{{ bar }}</template></foo>',
-      `with(this){return _c('foo',{scopedSlots:_u([{key:"default",fn:function(bar){return (\nshow\n)?[_v(_s(bar))]:undefined}}],true)})}`
+      `with(this){return _c('foo',{scopedSlots:_u([{key:"default",fn:function(bar){return (\nshow\n)?[_v(_s(bar))]:undefined}}],null,true)})}`
     )
     )
     assertCodegen(
     assertCodegen(
       '<foo><div v-if="\nshow\n" slot="foo" slot-scope="bar">{{ bar }}</div></foo>',
       '<foo><div v-if="\nshow\n" slot="foo" slot-scope="bar">{{ bar }}</div></foo>',
-      `with(this){return _c(\'foo\',{scopedSlots:_u([{key:"foo",fn:function(bar){return (\nshow\n)?_c(\'div\',{},[_v(_s(bar))]):_e()}}],true)})}`
+      `with(this){return _c(\'foo\',{scopedSlots:_u([{key:"foo",fn:function(bar){return (\nshow\n)?_c(\'div\',{},[_v(_s(bar))]):_e()}}],null,true)})}`
     )
     )
   })
   })
 
 
   it('generate scoped slot with new slot syntax', () => {
   it('generate scoped slot with new slot syntax', () => {
     assertCodegen(
     assertCodegen(
       '<foo><template v-if="show" #default="bar">{{ bar }}</template></foo>',
       '<foo><template v-if="show" #default="bar">{{ bar }}</template></foo>',
-      `with(this){return _c('foo',{scopedSlots:_u([(show)?{key:"default",fn:function(bar){return [_v(_s(bar))]}}:null],true)})}`
+      `with(this){return _c('foo',{scopedSlots:_u([(show)?{key:"default",fn:function(bar){return [_v(_s(bar))]}}:null],null,true)})}`
     )
     )
   })
   })