Wrap checkPropTypes in DEV conditional so it's stripped out in prod
Andrew Clark committed
Feb 22, 2017 at 14:51 UTC
0320b8ecb44f4bfac44e27ae42ced1b805fc0e98
2 files changed
+66
-66
src/isomorphic/classic/element/ReactDebugCurrentFrame.js
+22
-24
@@ -15,44 +15,42 @@
15
import type { Fiber } from 'ReactFiber';
16
import type { DebugID } from 'ReactInstanceType';
17
18
+const ReactDebugCurrentFrame = {};
19
+
20
if (__DEV__) {
21
var {
22
getStackAddendumByID,
23
getStackAddendumByWorkInProgressFiber,
24
getCurrentStackAddendum,
25
} = require('ReactComponentTreeHook');
24
-}
26
26
-const ReactDebugCurrentFrame = {
27
// Component that is being worked on
28
- current: (null : Fiber | DebugID | null),
28
+ ReactDebugCurrentFrame.current = (null : Fiber | DebugID | null);
29
30
// Element that is being cloned or created
31
- element: (null : *),
31
+ ReactDebugCurrentFrame.element = (null : *);
32
33
- getStackAddendum() : string | null {
33
+ ReactDebugCurrentFrame.getStackAddendum = function() : string | null {
34
let stack = null;
35
- if (__DEV__) {
36
- const current = ReactDebugCurrentFrame.current;
37
- const element = ReactDebugCurrentFrame.element;
38
- if (current !== null) {
39
- if (typeof current === 'number') {
40
- // DebugID from Stack.
41
- const debugID = current;
42
- stack = getStackAddendumByID(debugID);
43
- } else if (typeof current.tag === 'number') {
44
- // This is a Fiber.
45
- // The stack will only be correct if this is a work in progress
46
- // version and we're calling it during reconciliation.
47
- const workInProgress = current;
48
- stack = getStackAddendumByWorkInProgressFiber(workInProgress);
49
- }
50
- } else if (element !== null) {
51
- stack = getCurrentStackAddendum(element);
35
+ const current = ReactDebugCurrentFrame.current;
36
+ const element = ReactDebugCurrentFrame.element;
37
+ if (current !== null) {
38
+ if (typeof current === 'number') {
39
+ // DebugID from Stack.
40
+ const debugID = current;
41
+ stack = getStackAddendumByID(debugID);
42
+ } else if (typeof current.tag === 'number') {
43
+ // This is a Fiber.
44
+ // The stack will only be correct if this is a work in progress
45
+ // version and we're calling it during reconciliation.
46
+ const workInProgress = current;
47
+ stack = getStackAddendumByWorkInProgressFiber(workInProgress);
48
}
49
+ } else if (element !== null) {
50
+ stack = getCurrentStackAddendum(element);
51
}
52
return stack;
55
- },
56
-};
53
+ };
54
+}
55
56
module.exports = ReactDebugCurrentFrame;
src/isomorphic/classic/types/checkPropTypes.js
+44
-42
@@ -30,53 +30,55 @@ var loggedTypeFailures = {};
30
* @private
31
*/
32
function checkPropTypes(typeSpecs, values, location, componentName, getStack) {
33
- for (var typeSpecName in typeSpecs) {
34
- if (typeSpecs.hasOwnProperty(typeSpecName)) {
35
- var error;
36
- // Prop type validation may throw. In case they do, we don't want to
37
- // fail the render phase where it didn't fail before. So we log it.
38
- // After these have been cleaned up, we'll let them throw.
39
- try {
40
- // This is intentionally an invariant that gets caught. It's the same
41
- // behavior as without this statement except with a better message.
42
- invariant(
43
- typeof typeSpecs[typeSpecName] === 'function',
44
- '%s: %s type `%s` is invalid; it must be a function, usually from ' +
45
- 'React.PropTypes.',
33
+ if (__DEV__) {
34
+ for (var typeSpecName in typeSpecs) {
35
+ if (typeSpecs.hasOwnProperty(typeSpecName)) {
36
+ var error;
37
+ // Prop type validation may throw. In case they do, we don't want to
38
+ // fail the render phase where it didn't fail before. So we log it.
39
+ // After these have been cleaned up, we'll let them throw.
40
+ try {
41
+ // This is intentionally an invariant that gets caught. It's the same
42
+ // behavior as without this statement except with a better message.
43
+ invariant(
44
+ typeof typeSpecs[typeSpecName] === 'function',
45
+ '%s: %s type `%s` is invalid; it must be a function, usually from ' +
46
+ 'React.PropTypes.',
47
+ componentName || 'React class',
48
+ location,
49
+ typeSpecName
50
+ );
51
+ error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, ReactPropTypesSecret);
52
+ } catch (ex) {
53
+ error = ex;
54
+ }
55
+ warning(
56
+ !error || error instanceof Error,
57
+ '%s: type specification of %s `%s` is invalid; the type checker ' +
58
+ 'function must return `null` or an `Error` but returned a %s. ' +
59
+ 'You may have forgotten to pass an argument to the type checker ' +
60
+ 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' +
61
+ 'shape all require an argument).',
62
componentName || 'React class',
63
location,
48
- typeSpecName
64
+ typeSpecName,
65
+ typeof error
66
);
50
- error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, ReactPropTypesSecret);
51
- } catch (ex) {
52
- error = ex;
53
- }
54
- warning(
55
- !error || error instanceof Error,
56
- '%s: type specification of %s `%s` is invalid; the type checker ' +
57
- 'function must return `null` or an `Error` but returned a %s. ' +
58
- 'You may have forgotten to pass an argument to the type checker ' +
59
- 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' +
60
- 'shape all require an argument).',
61
- componentName || 'React class',
62
- location,
63
- typeSpecName,
64
- typeof error
65
- );
66
- if (error instanceof Error && !(error.message in loggedTypeFailures)) {
67
- // Only monitor this failure once because there tends to be a lot of the
68
- // same error.
69
- loggedTypeFailures[error.message] = true;
67
+ if (error instanceof Error && !(error.message in loggedTypeFailures)) {
68
+ // Only monitor this failure once because there tends to be a lot of the
69
+ // same error.
70
+ loggedTypeFailures[error.message] = true;
71
71
- var stack = getStack ? getStack() : '';
72
+ var stack = getStack ? getStack() : '';
73
73
- warning(
74
- false,
75
- 'Failed %s type: %s%s',
76
- location,
77
- error.message,
78
- stack != null ? stack : '',
79
- );
74
+ warning(
75
+ false,
76
+ 'Failed %s type: %s%s',
77
+ location,
78
+ error.message,
79
+ stack != null ? stack : '',
80
+ );
81
+ }
82
}
83
}
84
}