Merge pull request #1122 from spicyj/gh-1120

Strip calls to warning() in __DEV__
This commit is contained in:
Paul O’Shannessy committed 2014-02-17 19:44:53 -08:00
commit c79974db3a
4 files changed
+38 -19

No files matched your search

+1 -1
View File
@@ -73,6 +73,6 @@
},
"preferGlobal": true,
"commonerConfig": {
"version": 3
"version": 4
}
}
+7 -7
View File
@@ -16,6 +16,8 @@
* @providesModule invariant
*/
"use strict";
/**
* Use invariant() to assert state which your program assumes to be true.
*
@@ -27,7 +29,7 @@
* will remain to ensure logic does not differ in production.
*/
function invariant(condition) {
var invariant = function(condition) {
if (!condition) {
var error = new Error(
'Minified exception occured; use the non-minified dev environment for ' +
@@ -36,12 +38,10 @@ function invariant(condition) {
error.framesToPop = 1;
throw error;
}
}
module.exports = invariant;
};
if (__DEV__) {
var invariantDev = function(condition, format, a, b, c, d, e, f) {
invariant = function(condition, format, a, b, c, d, e, f) {
if (format === undefined) {
throw new Error('invariant requires an error message argument');
}
@@ -57,6 +57,6 @@ if (__DEV__) {
throw error;
}
};
module.exports = invariantDev;
}
module.exports = invariant;
+19 -11
View File
@@ -16,6 +16,9 @@
* @providesModule warning
*/
"use strict";
var emptyFunction = require('emptyFunction');
/**
* Similar to invariant but only logs a warning if the condition is not met.
@@ -23,18 +26,23 @@
* paths. Removing the logging code for production environments will keep the
* same logic and follow the same code paths.
*/
function warning(condition, format, ...args) {
if (format === undefined) {
throw new Error(
'`warning(condition, format, ...args)` requires a warning ' +
'message argument'
);
}
if (!condition) {
var argIndex = 0;
console.warn('Warning: ' + format.replace(/%s/g, () => args[argIndex++]));
}
var warning = emptyFunction;
if (__DEV__) {
warning = function(condition, format, ...args) {
if (format === undefined) {
throw new Error(
'`warning(condition, format, ...args)` requires a warning ' +
'message argument'
);
}
if (!condition) {
var argIndex = 0;
console.warn('Warning: ' + format.replace(/%s/g, () => args[argIndex++]));
}
};
}
module.exports = warning;
+11
View File
@@ -81,6 +81,17 @@ function transform(ast, constants) {
)
);
return false;
} else if (namedTypes.Identifier.check(node.callee) &&
node.callee.name === 'warning') {
// Eliminate warning(condition, ...) statements based on NODE_ENV
// (dead code removal will remove the extra bytes).
this.replace(
builders.conditionalExpression(
DEV_EXPRESSION,
node,
builders.literal(null)
)
);
}
}
});