1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | 'use strict';
|
9 |
|
10 | var printWarning = function() {};
|
11 |
|
12 | if (process.env.NODE_ENV !== 'production') {
|
13 | var ReactPropTypesSecret = require('./lib/ReactPropTypesSecret');
|
14 | var loggedTypeFailures = {};
|
15 | var has = Function.call.bind(Object.prototype.hasOwnProperty);
|
16 |
|
17 | printWarning = function(text) {
|
18 | var message = 'Warning: ' + text;
|
19 | if (typeof console !== 'undefined') {
|
20 | console.error(message);
|
21 | }
|
22 | try {
|
23 |
|
24 |
|
25 |
|
26 | throw new Error(message);
|
27 | } catch (x) {}
|
28 | };
|
29 | }
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 | function checkPropTypes(typeSpecs, values, location, componentName, getStack) {
|
43 | if (process.env.NODE_ENV !== 'production') {
|
44 | for (var typeSpecName in typeSpecs) {
|
45 | if (has(typeSpecs, typeSpecName)) {
|
46 | var error;
|
47 |
|
48 |
|
49 |
|
50 | try {
|
51 |
|
52 |
|
53 | if (typeof typeSpecs[typeSpecName] !== 'function') {
|
54 | var err = Error(
|
55 | (componentName || 'React class') + ': ' + location + ' type `' + typeSpecName + '` is invalid; ' +
|
56 | 'it must be a function, usually from the `prop-types` package, but received `' + typeof typeSpecs[typeSpecName] + '`.'
|
57 | );
|
58 | err.name = 'Invariant Violation';
|
59 | throw err;
|
60 | }
|
61 | error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, ReactPropTypesSecret);
|
62 | } catch (ex) {
|
63 | error = ex;
|
64 | }
|
65 | if (error && !(error instanceof Error)) {
|
66 | printWarning(
|
67 | (componentName || 'React class') + ': type specification of ' +
|
68 | location + ' `' + typeSpecName + '` is invalid; the type checker ' +
|
69 | 'function must return `null` or an `Error` but returned a ' + typeof error + '. ' +
|
70 | 'You may have forgotten to pass an argument to the type checker ' +
|
71 | 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' +
|
72 | 'shape all require an argument).'
|
73 | );
|
74 | }
|
75 | if (error instanceof Error && !(error.message in loggedTypeFailures)) {
|
76 |
|
77 |
|
78 | loggedTypeFailures[error.message] = true;
|
79 |
|
80 | var stack = getStack ? getStack() : '';
|
81 |
|
82 | printWarning(
|
83 | 'Failed ' + location + ' type: ' + error.message + (stack != null ? stack : '')
|
84 | );
|
85 | }
|
86 | }
|
87 | }
|
88 | }
|
89 | }
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 | checkPropTypes.resetWarningCache = function() {
|
97 | if (process.env.NODE_ENV !== 'production') {
|
98 | loggedTypeFailures = {};
|
99 | }
|
100 | }
|
101 |
|
102 | module.exports = checkPropTypes;
|