@samitouri / QOS-React / commits / 9993fdd957

Change formatMessage parameter to getStack

Gives us flexibility in the future to deal with the stack and the message separately.

Andrew Clark committed Feb 16, 2017 at 11:34 UTC 9993fdd957248beb8950cb3a6986ddcff7437ea0
2 files changed +13 -13
src/isomorphic/classic/types/checkPropTypes.js
+6 -5
@@ -26,10 +26,10 @@ var loggedTypeFailures = {};
26 * @param {object} values Runtime values that need to be type-checked
27 * @param {string} location e.g. "prop", "context", "child context"
28 * @param {string} componentName Name of the component for error messages.
29 - * @param {?Function} formatMessage Function that transforms the error message, to add additional info.
29 + * @param {?Function} getStack Returns the component stack.
30 * @private
31 */
32 -function checkPropTypes(typeSpecs, values, location, componentName, formatMessage) {
32 +function checkPropTypes(typeSpecs, values, location, componentName, getStack) {
33 for (var typeSpecName in typeSpecs) {
34 if (typeSpecs.hasOwnProperty(typeSpecName)) {
35 var error;
@@ -68,13 +68,14 @@ function checkPropTypes(typeSpecs, values, location, componentName, formatMessag
68 // same error.
69 loggedTypeFailures[error.message] = true;
70
71 - var message = formatMessage ? formatMessage(error.message) : error.message;
71 + var stack = getStack ? getStack() : '';
72
73 warning(
74 false,
75 - 'Failed %s type: %s',
75 + 'Failed %s type: %s%s',
76 location,
77 - message,
77 + error.message,
78 + stack,
79 );
80 }
81 }
src/shared/types/checkReactTypeSpec.js
+7 -8
@@ -38,9 +38,9 @@ function checkReactTypeSpec(
38 // only during reconciliation (begin and complete phase).
39 workInProgressOrDebugID
40 ) {
41 - function formatMessage(message) {
41 + function getStack() {
42 + let stack = '';
43 if (__DEV__) {
43 - let componentStackInfo = '';
44 if (!ReactComponentTreeHook) {
45 ReactComponentTreeHook = require('ReactComponentTreeHook');
46 }
@@ -48,23 +48,22 @@ function checkReactTypeSpec(
48 if (typeof workInProgressOrDebugID === 'number') {
49 // DebugID from Stack.
50 const debugID = workInProgressOrDebugID;
51 - componentStackInfo = ReactComponentTreeHook.getStackAddendumByID(debugID);
51 + stack = ReactComponentTreeHook.getStackAddendumByID(debugID);
52 } else if (typeof workInProgressOrDebugID.tag === 'number') {
53 // This is a Fiber.
54 // The stack will only be correct if this is a work in progress
55 // version and we're calling it during reconciliation.
56 const workInProgress = workInProgressOrDebugID;
57 - componentStackInfo = ReactComponentTreeHook.getStackAddendumByWorkInProgressFiber(workInProgress);
57 + stack = ReactComponentTreeHook.getStackAddendumByWorkInProgressFiber(workInProgress);
58 }
59 } else if (element !== null) {
60 - componentStackInfo = ReactComponentTreeHook.getCurrentStackAddendum(element);
60 + stack = ReactComponentTreeHook.getCurrentStackAddendum(element);
61 }
62 - message += componentStackInfo;
62 }
64 - return message;
63 + return stack;
64 }
65
67 - checkPropTypes(typeSpecs, values, location, componentName, formatMessage);
66 + checkPropTypes(typeSpecs, values, location, componentName, getStack);
67 }
68
69 module.exports = checkReactTypeSpec;