MCPcopy Create free account
hub / github.com/Lucifier129/react-lite / checkPropTypes

Function checkPropTypes

examples/simple/react.js:9408–9434  ·  view source on GitHub ↗

* Assert that the props are valid * * @param {string} componentName Name of the component for error messages. * @param {object} propTypes Map of prop name to a ReactPropType * @param {object} props * @param {string} location e.g. "prop", "context", "child context" * @private

(componentName, propTypes, props, location)

Source from the content-addressed store, hash-verified

9406 * @private
9407 */
9408function checkPropTypes(componentName, propTypes, props, location) {
9409 for (var propName in propTypes) {
9410 if (propTypes.hasOwnProperty(propName)) {
9411 var error;
9412 // Prop type validation may throw. In case they do, we don't want to
9413 // fail the render phase where it didn't fail before. So we log it.
9414 // After these have been cleaned up, we'll let them throw.
9415 try {
9416 // This is intentionally an invariant that gets caught. It's the same
9417 // behavior as without this statement except with a better message.
9418 !(typeof propTypes[propName] === 'function') ? "development" !== 'production' ? invariant(false, '%s: %s type `%s` is invalid; it must be a function, usually from ' + 'React.PropTypes.', componentName || 'React class', ReactPropTypeLocationNames[location], propName) : invariant(false) : undefined;
9419 error = propTypes[propName](props, propName, componentName, location);
9420 } catch (ex) {
9421 error = ex;
9422 }
9423 "development" !== 'production' ? warning(!error || error instanceof Error, '%s: type specification of %s `%s` is invalid; the type checker ' + 'function must return `null` or an `Error` but returned a %s. ' + 'You may have forgotten to pass an argument to the type checker ' + 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' + 'shape all require an argument).', componentName || 'React class', ReactPropTypeLocationNames[location], propName, typeof error) : undefined;
9424 if (error instanceof Error && !(error.message in loggedTypeFailures)) {
9425 // Only monitor this failure once because there tends to be a lot of the
9426 // same error.
9427 loggedTypeFailures[error.message] = true;
9428
9429 var addendum = getDeclarationErrorAddendum();
9430 "development" !== 'production' ? warning(false, 'Failed propType: %s%s', error.message, addendum) : undefined;
9431 }
9432 }
9433 }
9434}
9435
9436/**
9437 * Given an element, validate that its props follow the propTypes definition,

Callers 1

validatePropTypesFunction · 0.85

Calls 3

invariantFunction · 0.70
warningFunction · 0.50

Tested by

no test coverage detected