Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add slot v-bind warning (fix #6677) #6736

Merged
merged 5 commits into from
Oct 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/core/instance/render-helpers/render-slot.js
Original file line number Diff line number Diff line change
@@ -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>
Expand All @@ -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
Expand Down
54 changes: 54 additions & 0 deletions test/unit/features/component/component-scoped-slot.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: `
Expand Down