diff --git a/src/isomorphic/classic/element/ReactDebugCurrentFrame.js b/src/isomorphic/classic/element/ReactDebugCurrentFrame.js index f2e4676aed..f4efdd672b 100644 --- a/src/isomorphic/classic/element/ReactDebugCurrentFrame.js +++ b/src/isomorphic/classic/element/ReactDebugCurrentFrame.js @@ -15,44 +15,42 @@ import type { Fiber } from 'ReactFiber'; import type { DebugID } from 'ReactInstanceType'; +const ReactDebugCurrentFrame = {}; + if (__DEV__) { var { getStackAddendumByID, getStackAddendumByWorkInProgressFiber, getCurrentStackAddendum, } = require('ReactComponentTreeHook'); -} -const ReactDebugCurrentFrame = { // Component that is being worked on - current: (null : Fiber | DebugID | null), + ReactDebugCurrentFrame.current = (null : Fiber | DebugID | null); // Element that is being cloned or created - element: (null : *), + ReactDebugCurrentFrame.element = (null : *); - getStackAddendum() : string | null { + ReactDebugCurrentFrame.getStackAddendum = function() : string | null { let stack = null; - if (__DEV__) { - const current = ReactDebugCurrentFrame.current; - const element = ReactDebugCurrentFrame.element; - if (current !== null) { - if (typeof current === 'number') { - // DebugID from Stack. - const debugID = current; - stack = getStackAddendumByID(debugID); - } else if (typeof current.tag === 'number') { - // This is a Fiber. - // The stack will only be correct if this is a work in progress - // version and we're calling it during reconciliation. - const workInProgress = current; - stack = getStackAddendumByWorkInProgressFiber(workInProgress); - } - } else if (element !== null) { - stack = getCurrentStackAddendum(element); + const current = ReactDebugCurrentFrame.current; + const element = ReactDebugCurrentFrame.element; + if (current !== null) { + if (typeof current === 'number') { + // DebugID from Stack. + const debugID = current; + stack = getStackAddendumByID(debugID); + } else if (typeof current.tag === 'number') { + // This is a Fiber. + // The stack will only be correct if this is a work in progress + // version and we're calling it during reconciliation. + const workInProgress = current; + stack = getStackAddendumByWorkInProgressFiber(workInProgress); } + } else if (element !== null) { + stack = getCurrentStackAddendum(element); } return stack; - }, -}; + }; +} module.exports = ReactDebugCurrentFrame; diff --git a/src/isomorphic/classic/types/checkPropTypes.js b/src/isomorphic/classic/types/checkPropTypes.js index 172b96842e..23ebacaf09 100644 --- a/src/isomorphic/classic/types/checkPropTypes.js +++ b/src/isomorphic/classic/types/checkPropTypes.js @@ -30,53 +30,55 @@ var loggedTypeFailures = {}; * @private */ function checkPropTypes(typeSpecs, values, location, componentName, getStack) { - for (var typeSpecName in typeSpecs) { - if (typeSpecs.hasOwnProperty(typeSpecName)) { - var error; - // Prop type validation may throw. In case they do, we don't want to - // fail the render phase where it didn't fail before. So we log it. - // After these have been cleaned up, we'll let them throw. - try { - // This is intentionally an invariant that gets caught. It's the same - // behavior as without this statement except with a better message. - invariant( - typeof typeSpecs[typeSpecName] === 'function', - '%s: %s type `%s` is invalid; it must be a function, usually from ' + - 'React.PropTypes.', + if (__DEV__) { + for (var typeSpecName in typeSpecs) { + if (typeSpecs.hasOwnProperty(typeSpecName)) { + var error; + // Prop type validation may throw. In case they do, we don't want to + // fail the render phase where it didn't fail before. So we log it. + // After these have been cleaned up, we'll let them throw. + try { + // This is intentionally an invariant that gets caught. It's the same + // behavior as without this statement except with a better message. + invariant( + typeof typeSpecs[typeSpecName] === 'function', + '%s: %s type `%s` is invalid; it must be a function, usually from ' + + 'React.PropTypes.', + componentName || 'React class', + location, + typeSpecName + ); + error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, ReactPropTypesSecret); + } catch (ex) { + error = ex; + } + 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', location, - typeSpecName + typeSpecName, + typeof error ); - error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, ReactPropTypesSecret); - } catch (ex) { - error = ex; - } - 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', - location, - typeSpecName, - typeof error - ); - if (error instanceof Error && !(error.message in loggedTypeFailures)) { - // Only monitor this failure once because there tends to be a lot of the - // same error. - loggedTypeFailures[error.message] = true; + if (error instanceof Error && !(error.message in loggedTypeFailures)) { + // Only monitor this failure once because there tends to be a lot of the + // same error. + loggedTypeFailures[error.message] = true; - var stack = getStack ? getStack() : ''; + var stack = getStack ? getStack() : ''; - warning( - false, - 'Failed %s type: %s%s', - location, - error.message, - stack != null ? stack : '', - ); + warning( + false, + 'Failed %s type: %s%s', + location, + error.message, + stack != null ? stack : '', + ); + } } } }