* dev only
( name: string, value: unknown, prop: PropOptions, props: Data, isAbsent: boolean, )
| 675 | * dev only |
| 676 | */ |
| 677 | function validateProp( |
| 678 | name: string, |
| 679 | value: unknown, |
| 680 | prop: PropOptions, |
| 681 | props: Data, |
| 682 | isAbsent: boolean, |
| 683 | ) { |
| 684 | const { type, required, validator, skipCheck } = prop |
| 685 | // required! |
| 686 | if (required && isAbsent) { |
| 687 | warn('Missing required prop: "' + name + '"') |
| 688 | return |
| 689 | } |
| 690 | // missing but optional |
| 691 | if (value == null && !required) { |
| 692 | return |
| 693 | } |
| 694 | // type check |
| 695 | if (type != null && type !== true && !skipCheck) { |
| 696 | let isValid = false |
| 697 | const types = isArray(type) ? type : [type] |
| 698 | const expectedTypes = [] |
| 699 | // value is valid as long as one of the specified types match |
| 700 | for (let i = 0; i < types.length && !isValid; i++) { |
| 701 | const { valid, expectedType } = assertType(value, types[i]) |
| 702 | expectedTypes.push(expectedType || '') |
| 703 | isValid = valid |
| 704 | } |
| 705 | if (!isValid) { |
| 706 | warn(getInvalidTypeMessage(name, value, expectedTypes)) |
| 707 | return |
| 708 | } |
| 709 | } |
| 710 | // custom validator |
| 711 | if (validator && !validator(value, props)) { |
| 712 | warn('Invalid prop: custom validator check failed for prop "' + name + '".') |
| 713 | } |
| 714 | } |
| 715 | |
| 716 | const isSimpleType = /*@__PURE__*/ makeMap( |
| 717 | 'String,Number,Boolean,Function,Symbol,BigInt', |
no test coverage detected