* Assert whether a prop is valid. * * @param {Object} prop * @param {*} value * @param {Vue} vm
(prop, value, vm)
| 6246 | */ |
| 6247 | |
| 6248 | function assertProp(prop, value, vm) { |
| 6249 | if (!prop.options.required && ( // non-required |
| 6250 | prop.raw === null || // abscent |
| 6251 | value == null) // null or undefined |
| 6252 | ) { |
| 6253 | return true; |
| 6254 | } |
| 6255 | var options = prop.options; |
| 6256 | var type = options.type; |
| 6257 | var valid = !type; |
| 6258 | var expectedTypes = []; |
| 6259 | if (type) { |
| 6260 | if (!isArray(type)) { |
| 6261 | type = [type]; |
| 6262 | } |
| 6263 | for (var i = 0; i < type.length && !valid; i++) { |
| 6264 | var assertedType = assertType(value, type[i]); |
| 6265 | expectedTypes.push(assertedType.expectedType); |
| 6266 | valid = assertedType.valid; |
| 6267 | } |
| 6268 | } |
| 6269 | if (!valid) { |
| 6270 | if ('development' !== 'production') { |
| 6271 | warn('Invalid prop: type check failed for prop "' + prop.name + '".' + ' Expected ' + expectedTypes.map(formatType).join(', ') + ', got ' + formatValue(value) + '.', vm); |
| 6272 | } |
| 6273 | return false; |
| 6274 | } |
| 6275 | var validator = options.validator; |
| 6276 | if (validator) { |
| 6277 | if (!validator(value)) { |
| 6278 | 'development' !== 'production' && warn('Invalid prop: custom validator check failed for prop "' + prop.name + '".', vm); |
| 6279 | return false; |
| 6280 | } |
| 6281 | } |
| 6282 | return true; |
| 6283 | } |
| 6284 | |
| 6285 | /** |
| 6286 | * Force parsing value with coerce option. |
no test coverage detected