Explorar o código

fix: add slot v-bind warning (#6736)

close #6677
Dominik Rabij %!s(int64=8) %!d(string=hai) anos
pai
achega
514b90b647

+ 7 - 1
src/core/instance/render-helpers/render-slot.js

@@ -1,6 +1,6 @@
 /* @flow */
 
-import { extend, warn } from 'core/util/index'
+import { extend, warn, isObject } from 'core/util/index'
 
 /**
  * Runtime helper for rendering <slot>
@@ -15,6 +15,12 @@ export function renderSlot (
   if (scopedSlotFn) { // scoped slot
     props = props || {}
     if (bindObject) {
+      if (process.env.NODE_ENV !== 'production' && !isObject(bindObject)) {
+        warn(
+          'slot v-bind without argument expects an Object',
+          this
+        )
+      }
       props = extend(extend({}, bindObject), props)
     }
     return scopedSlotFn(props) || fallback

+ 54 - 0
test/unit/features/component/component-scoped-slot.spec.js

@@ -93,6 +93,60 @@ describe('Component scoped slot', () => {
     }).then(done)
   })
 
+  it('should warn when using v-bind with no object', () => {
+    new Vue({
+      template: `
+        <test ref="test">
+          <template scope="props">
+          </template>
+        </test>
+      `,
+      components: {
+        test: {
+          data () {
+            return {
+              text: 'some text'
+            }
+          },
+          template: `
+            <div>
+              <slot v-bind="text"></slot>
+            </div>
+          `
+        }
+      }
+    }).$mount()
+    expect('slot v-bind without argument expects an Object').toHaveBeenWarned()
+  })
+
+  it('should not warn when using v-bind with object', () => {
+    new Vue({
+      template: `
+        <test ref="test">
+          <template scope="props">
+          </template>
+        </test>
+      `,
+      components: {
+        test: {
+          data () {
+            return {
+              foo: {
+                text: 'some text'
+              }
+            }
+          },
+          template: `
+            <div>
+              <slot v-bind="foo"></slot>
+            </div>
+          `
+        }
+      }
+    }).$mount()
+    expect('slot v-bind without argument expects an Object').not.toHaveBeenWarned()
+  })
+
   it('named scoped slot', done => {
     const vm = new Vue({
       template: `