1 | const ReactPropTypesSecret = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED';
|
2 |
|
3 | let loggedTypeFailures = {};
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | export function resetPropWarnings() {
|
9 | loggedTypeFailures = {};
|
10 | }
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 | export function checkPropTypes(
|
25 | typeSpecs,
|
26 | values,
|
27 | location,
|
28 | componentName,
|
29 | getStack
|
30 | ) {
|
31 | Object.keys(typeSpecs).forEach(typeSpecName => {
|
32 | let error;
|
33 | try {
|
34 | error = typeSpecs[typeSpecName](
|
35 | values,
|
36 | typeSpecName,
|
37 | componentName,
|
38 | location,
|
39 | null,
|
40 | ReactPropTypesSecret
|
41 | );
|
42 | } catch (e) {
|
43 | error = e;
|
44 | }
|
45 | if (error && !(error.message in loggedTypeFailures)) {
|
46 | loggedTypeFailures[error.message] = true;
|
47 | console.error(
|
48 | `Failed ${location} type: ${error.message}${(getStack &&
|
49 | `\n${getStack()}`) ||
|
50 | ''}`
|
51 | );
|
52 | }
|
53 | });
|
54 | }
|