File tree Expand file tree Collapse file tree 2 files changed +61
-1
lines changed
src/core/instance/render-helpers
test/unit/features/component Expand file tree Collapse file tree 2 files changed +61
-1
lines changed Original file line number Diff line number Diff line change 1
1
/* @flow */
2
2
3
- import { extend , warn } from 'core/util/index'
3
+ import { extend , warn , isObject } from 'core/util/index'
4
4
5
5
/**
6
6
* Runtime helper for rendering <slot>
@@ -15,6 +15,12 @@ export function renderSlot (
15
15
if ( scopedSlotFn ) { // scoped slot
16
16
props = props || { }
17
17
if ( bindObject ) {
18
+ if ( process . env . NODE_ENV !== 'production' && ! isObject ( bindObject ) ) {
19
+ warn (
20
+ 'slot v-bind without argument expects an Object' ,
21
+ this
22
+ )
23
+ }
18
24
props = extend ( extend ( { } , bindObject ) , props )
19
25
}
20
26
return scopedSlotFn ( props ) || fallback
Original file line number Diff line number Diff line change @@ -93,6 +93,60 @@ describe('Component scoped slot', () => {
93
93
} ) . then ( done )
94
94
} )
95
95
96
+ it ( 'should warn when using v-bind with no object' , ( ) => {
97
+ new Vue ( {
98
+ template : `
99
+ <test ref="test">
100
+ <template scope="props">
101
+ </template>
102
+ </test>
103
+ ` ,
104
+ components : {
105
+ test : {
106
+ data ( ) {
107
+ return {
108
+ text : 'some text'
109
+ }
110
+ } ,
111
+ template : `
112
+ <div>
113
+ <slot v-bind="text"></slot>
114
+ </div>
115
+ `
116
+ }
117
+ }
118
+ } ) . $mount ( )
119
+ expect ( 'slot v-bind without argument expects an Object' ) . toHaveBeenWarned ( )
120
+ } )
121
+
122
+ it ( 'should not warn when using v-bind with object' , ( ) => {
123
+ new Vue ( {
124
+ template : `
125
+ <test ref="test">
126
+ <template scope="props">
127
+ </template>
128
+ </test>
129
+ ` ,
130
+ components : {
131
+ test : {
132
+ data ( ) {
133
+ return {
134
+ foo : {
135
+ text : 'some text'
136
+ }
137
+ }
138
+ } ,
139
+ template : `
140
+ <div>
141
+ <slot v-bind="foo"></slot>
142
+ </div>
143
+ `
144
+ }
145
+ }
146
+ } ) . $mount ( )
147
+ expect ( 'slot v-bind without argument expects an Object' ) . not . toHaveBeenWarned ( )
148
+ } )
149
+
96
150
it ( 'named scoped slot' , done => {
97
151
const vm = new Vue ( {
98
152
template : `
You can’t perform that action at this time.
0 commit comments