From 559eb899657b7717e2a1013cd860407cb89c2b3c Mon Sep 17 00:00:00 2001 From: Andrew Zich Date: Thu, 3 Jul 2014 13:53:41 -0700 Subject: [PATCH] make invariant show formatted actual errors in all unminified environments Because we can have !__DEV__ but unminified, we still want to see the message in those cases. --- src/vendor/core/invariant.js | 48 +++++++++++++++++------------------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/src/vendor/core/invariant.js b/src/vendor/core/invariant.js index 12649d5e61..d99f3615c9 100644 --- a/src/vendor/core/invariant.js +++ b/src/vendor/core/invariant.js @@ -29,34 +29,32 @@ * will remain to ensure logic does not differ in production. */ -var invariant = function(condition) { +var invariant = function(condition, format, a, b, c, d, e, f) { + if (__DEV__) { + if (format === undefined) { + throw new Error('invariant requires an error message argument'); + } + } + if (!condition) { - var error = new Error( - 'Minified exception occured; use the non-minified dev environment for ' + - 'the full error message and additional helpful warnings.' - ); - error.framesToPop = 1; + var error; + if (format === undefined) { + error = new Error( + 'Minified exception occurred; use the non-minified dev environment ' + + 'for the full error message and additional helpful warnings.' + ); + } else { + var args = [a, b, c, d, e, f]; + var argIndex = 0; + error = new Error( + 'Invariant Violation: ' + + format.replace(/%s/g, function() { return args[argIndex++]; }) + ); + } + + error.framesToPop = 1; // we don't care about invariant's own frame throw error; } }; -if (__DEV__) { - invariant = function(condition, format, a, b, c, d, e, f) { - if (format === undefined) { - throw new Error('invariant requires an error message argument'); - } - - if (!condition) { - var args = [a, b, c, d, e, f]; - var argIndex = 0; - var error = new Error( - 'Invariant Violation: ' + - format.replace(/%s/g, function() { return args[argIndex++]; }) - ); - error.framesToPop = 1; // we don't care about invariant's own frame - throw error; - } - }; -} - module.exports = invariant;