MCPcopy
hub / github.com/fanmingming/live / assertProp

Function assertProp

m3u8/vue.js:1681–1728  ·  view source on GitHub ↗

* Assert whether a prop is valid.

(
    prop,
    name,
    value,
    vm,
    absent
  )

Source from the content-addressed store, hash-verified

1679 * Assert whether a prop is valid.
1680 */
1681 function assertProp (
1682 prop,
1683 name,
1684 value,
1685 vm,
1686 absent
1687 ) {
1688 if (prop.required && absent) {
1689 warn(
1690 'Missing required prop: "' + name + '"',
1691 vm
1692 );
1693 return
1694 }
1695 if (value == null && !prop.required) {
1696 return
1697 }
1698 var type = prop.type;
1699 var valid = !type || type === true;
1700 var expectedTypes = [];
1701 if (type) {
1702 if (!Array.isArray(type)) {
1703 type = [type];
1704 }
1705 for (var i = 0; i < type.length && !valid; i++) {
1706 var assertedType = assertType(value, type[i]);
1707 expectedTypes.push(assertedType.expectedType || '');
1708 valid = assertedType.valid;
1709 }
1710 }
1711
1712 if (!valid) {
1713 warn(
1714 getInvalidTypeMessage(name, value, expectedTypes),
1715 vm
1716 );
1717 return
1718 }
1719 var validator = prop.validator;
1720 if (validator) {
1721 if (!validator(value)) {
1722 warn(
1723 'Invalid prop: custom validator check failed for prop "' + name + '".',
1724 vm
1725 );
1726 }
1727 }
1728 }
1729
1730 var simpleCheckRE = /^(String|Number|Boolean|Function|Symbol)$/;
1731

Callers 1

validatePropFunction · 0.85

Calls 3

warnFunction · 0.85
assertTypeFunction · 0.85
getInvalidTypeMessageFunction · 0.85

Tested by

no test coverage detected