Strip calls to warning() in __DEV__
Fixes #1120.
Ben Alpert committed
Feb 17, 2014 at 17:28 UTC
57953769614ab767ab4b1bf47313f7a689b63492
4 files changed
+38
-19
package.json
+1
-1
@@ -73,6 +73,6 @@
73
},
74
"preferGlobal": true,
75
"commonerConfig": {
76
- "version": 3
76
+ "version": 4
77
}
78
}
src/vendor/core/invariant.js
+7
-7
@@ -16,6 +16,8 @@
16
* @providesModule invariant
17
*/
18
19
+"use strict";
20
+
21
/**
22
* Use invariant() to assert state which your program assumes to be true.
23
*
@@ -27,7 +29,7 @@
29
* will remain to ensure logic does not differ in production.
30
*/
31
30
-function invariant(condition) {
32
+var invariant = function(condition) {
33
if (!condition) {
34
var error = new Error(
35
'Minified exception occured; use the non-minified dev environment for ' +
@@ -36,12 +38,10 @@ function invariant(condition) {
38
error.framesToPop = 1;
39
throw error;
40
}
39
-}
40
-
41
-module.exports = invariant;
41
+};
42
43
if (__DEV__) {
44
- var invariantDev = function(condition, format, a, b, c, d, e, f) {
44
+ invariant = function(condition, format, a, b, c, d, e, f) {
45
if (format === undefined) {
46
throw new Error('invariant requires an error message argument');
47
}
@@ -57,6 +57,6 @@ if (__DEV__) {
57
throw error;
58
}
59
};
60
-
61
- module.exports = invariantDev;
60
}
61
+
62
+module.exports = invariant;
src/vendor/core/warning.js
+19
-11
@@ -16,6 +16,9 @@
16
* @providesModule warning
17
*/
18
19
+"use strict";
20
+
21
+var emptyFunction = require('emptyFunction');
22
23
/**
24
* Similar to invariant but only logs a warning if the condition is not met.
@@ -23,18 +26,23 @@
26
* paths. Removing the logging code for production environments will keep the
27
* same logic and follow the same code paths.
28
*/
26
-function warning(condition, format, ...args) {
27
- if (format === undefined) {
28
- throw new Error(
29
- '`warning(condition, format, ...args)` requires a warning ' +
30
- 'message argument'
31
- );
32
- }
29
34
- if (!condition) {
35
- var argIndex = 0;
36
- console.warn('Warning: ' + format.replace(/%s/g, () => args[argIndex++]));
37
- }
30
+var warning = emptyFunction;
31
+
32
+if (__DEV__) {
33
+ warning = function(condition, format, ...args) {
34
+ if (format === undefined) {
35
+ throw new Error(
36
+ '`warning(condition, format, ...args)` requires a warning ' +
37
+ 'message argument'
38
+ );
39
+ }
40
+
41
+ if (!condition) {
42
+ var argIndex = 0;
43
+ console.warn('Warning: ' + format.replace(/%s/g, () => args[argIndex++]));
44
+ }
45
+ };
46
}
47
48
module.exports = warning;
vendor/constants.js
+11
@@ -81,6 +81,17 @@ function transform(ast, constants) {
81
)
82
);
83
return false;
84
+ } else if (namedTypes.Identifier.check(node.callee) &&
85
+ node.callee.name === 'warning') {
86
+ // Eliminate warning(condition, ...) statements based on NODE_ENV
87
+ // (dead code removal will remove the extra bytes).
88
+ this.replace(
89
+ builders.conditionalExpression(
90
+ DEV_EXPRESSION,
91
+ node,
92
+ builders.literal(null)
93
+ )
94
+ );
95
}
96
}
97
});