@@ -224,9 +224,10 @@ export function initProp (vm, prop, value) {
224
224
if ( value === undefined ) {
225
225
value = getPropDefaultValue ( vm , prop . options )
226
226
}
227
- if ( assertProp ( prop , value ) ) {
228
- defineReactive ( vm , key , value )
227
+ if ( ! assertProp ( prop , value , vm ) ) {
228
+ value = undefined
229
229
}
230
+ defineReactive ( vm , key , value )
230
231
}
231
232
232
233
/**
@@ -265,9 +266,10 @@ function getPropDefaultValue (vm, options) {
265
266
*
266
267
* @param {Object } prop
267
268
* @param {* } value
269
+ * @param {Vue } vm
268
270
*/
269
271
270
- export function assertProp ( prop , value ) {
272
+ export function assertProp ( prop , value , vm ) {
271
273
if (
272
274
! prop . options . required && ( // non-required
273
275
prop . raw === null || // abscent
@@ -304,20 +306,22 @@ export function assertProp (prop, value) {
304
306
}
305
307
}
306
308
if ( ! valid ) {
307
- process . env . NODE_ENV !== 'production' && warn (
308
- 'Invalid prop: type check failed for ' +
309
- prop . path + '="' + prop . raw + '".' +
310
- ' Expected ' + formatType ( expectedType ) +
311
- ', got ' + formatValue ( value ) + '.'
312
- )
309
+ if ( process . env . NODE_ENV !== 'production' ) {
310
+ warn (
311
+ 'Invalid prop: type check failed for prop "' + prop . name + '"' +
312
+ ( vm . $options . name ? ' on component <' + hyphenate ( vm . $options . name ) + '>.' : '.' ) +
313
+ ' Expected ' + formatType ( expectedType ) +
314
+ ', got ' + formatValue ( value ) + '.'
315
+ )
316
+ }
313
317
return false
314
318
}
315
319
var validator = options . validator
316
320
if ( validator ) {
317
321
if ( ! validator ( value ) ) {
318
322
process . env . NODE_ENV !== 'production' && warn (
319
- 'Invalid prop: custom validator check failed for ' +
320
- prop . path + '=" ' + prop . raw + '"'
323
+ 'Invalid prop: custom validator check failed for prop "' + prop . name + '" ' +
324
+ ( vm . $options . name ? ' on component < ' + hyphenate ( vm . $options . name ) + '>.' : '.' )
321
325
)
322
326
return false
323
327
}
0 commit comments