mirror of
https://github.com/facebook/react.git
synced 2026-11-18 20:15:56 +00:00
Merge pull request #1122 from spicyj/gh-1120
Strip calls to warning() in __DEV__
This commit is contained in:
commit
c79974db3a
4 files changed
+38
-19
No files matched your search
+1
-1
@@ -73,6 +73,6 @@
|
||||
},
|
||||
"preferGlobal": true,
|
||||
"commonerConfig": {
|
||||
"version": 3
|
||||
"version": 4
|
||||
}
|
||||
}
|
||||
Vendored
+7
-7
@@ -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;
|
||||
Vendored
+19
-11
@@ -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;
|
||||
Vendored
+11
@@ -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)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user