From 514b90b64770cba9f905d2dff59dfa0e064e580c Mon Sep 17 00:00:00 2001 From: Dominik Rabij Date: Fri, 6 Oct 2017 21:48:00 +0200 Subject: [PATCH] fix: add slot v-bind warning (#6736) close #6677 --- .../instance/render-helpers/render-slot.js | 8 ++- .../component/component-scoped-slot.spec.js | 54 +++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/src/core/instance/render-helpers/render-slot.js b/src/core/instance/render-helpers/render-slot.js index 3eaff882522..1a194c579e3 100644 --- a/src/core/instance/render-helpers/render-slot.js +++ b/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 @@ -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 diff --git a/test/unit/features/component/component-scoped-slot.spec.js b/test/unit/features/component/component-scoped-slot.spec.js index f4661fde403..8c17befde28 100644 --- a/test/unit/features/component/component-scoped-slot.spec.js +++ b/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: ` + + + + `, + components: { + test: { + data () { + return { + text: 'some text' + } + }, + template: ` +
+ +
+ ` + } + } + }).$mount() + expect('slot v-bind without argument expects an Object').toHaveBeenWarned() + }) + + it('should not warn when using v-bind with object', () => { + new Vue({ + template: ` + + + + `, + components: { + test: { + data () { + return { + foo: { + text: 'some text' + } + } + }, + template: ` +
+ +
+ ` + } + } + }).$mount() + expect('slot v-bind without argument expects an Object').not.toHaveBeenWarned() + }) + it('named scoped slot', done => { const vm = new Vue({ template: `