Wrap warning() calls in a DEV check for RN_* builds too (#10428)
* Wrap warning() calls in a DEV check for RN_* builds too. * Wrapped several warning() imports and calls in if-DEV checks. * Removed a useless variable (allTypesByEventName) and loop from ReactNativeBridgeEventPlugin.
Brian Vaughn committed
Aug 10, 2017 at 08:41 UTC
8b1b0720cc856d6b43d35dd29e50f260c7472347
13 files changed
+70
-49
scripts/rollup/build.js
+2
@@ -124,6 +124,8 @@ function updateBabelConfig(babelOpts, bundleType) {
124
switch (bundleType) {
125
case FB_DEV:
126
case FB_PROD:
127
+ case RN_DEV:
128
+ case RN_PROD:
129
return Object.assign({}, babelOpts, {
130
plugins: babelOpts.plugins.concat([
131
// Wrap warning() calls in a __DEV__ check so they are stripped from production.
src/isomorphic/classic/element/ReactElementValidator.js
+10
-8
@@ -144,14 +144,16 @@ function validateExplicitKey(element, parentType) {
144
}
145
146
currentlyValidatingElement = element;
147
- warning(
148
- false,
149
- 'Each child in an array or iterator should have a unique "key" prop.' +
150
- '%s%s See https://fb.me/react-warning-keys for more information.%s',
151
- currentComponentErrorInfo,
152
- childOwner,
153
- getStackAddendum(),
154
- );
147
+ if (__DEV__) {
148
+ warning(
149
+ false,
150
+ 'Each child in an array or iterator should have a unique "key" prop.' +
151
+ '%s%s See https://fb.me/react-warning-keys for more information.%s',
152
+ currentComponentErrorInfo,
153
+ childOwner,
154
+ getStackAddendum(),
155
+ );
156
+ }
157
currentlyValidatingElement = null;
158
}
159
src/renderers/dom/stack/client/ReactDOMComponent.js
+4
-1
@@ -42,9 +42,12 @@ var memoizeStringOnly = require('fbjs/lib/memoizeStringOnly');
42
var omittedCloseTags = require('omittedCloseTags');
43
var validateDOMNesting = require('validateDOMNesting');
44
var voidElementTags = require('voidElementTags');
45
-var warning = require('fbjs/lib/warning');
45
var warnValidStyle = require('warnValidStyle');
46
47
+if (__DEV__) {
48
+ var warning = require('fbjs/lib/warning');
49
+}
50
+
51
var didWarnShadyDOM = false;
52
53
var Flags = ReactDOMComponentFlags;
src/renderers/native/ReactNativeBridgeEventPlugin.js
+9
-15
@@ -15,25 +15,19 @@ var EventPropagators = require('EventPropagators');
15
var SyntheticEvent = require('SyntheticEvent');
16
var UIManager = require('UIManager');
17
18
-var warning = require('fbjs/lib/warning');
19
-
18
var customBubblingEventTypes = UIManager.customBubblingEventTypes;
19
var customDirectEventTypes = UIManager.customDirectEventTypes;
20
23
-var allTypesByEventName = {};
24
-
25
-for (var bubblingTypeName in customBubblingEventTypes) {
26
- allTypesByEventName[bubblingTypeName] =
27
- customBubblingEventTypes[bubblingTypeName];
28
-}
21
+if (__DEV__) {
22
+ var warning = require('fbjs/lib/warning');
23
30
-for (var directTypeName in customDirectEventTypes) {
31
- warning(
32
- !customBubblingEventTypes[directTypeName],
33
- 'Event cannot be both direct and bubbling: %s',
34
- directTypeName,
35
- );
36
- allTypesByEventName[directTypeName] = customDirectEventTypes[directTypeName];
24
+ for (var directTypeName in customDirectEventTypes) {
25
+ warning(
26
+ !customBubblingEventTypes[directTypeName],
27
+ 'Event cannot be both direct and bubbling: %s',
28
+ directTypeName,
29
+ );
30
+ }
31
}
32
33
var ReactNativeBridgeEventPlugin = {
src/renderers/native/ReactNativeEventEmitter.js
+3
-1
@@ -18,7 +18,9 @@ var ReactNativeComponentTree = require('ReactNativeComponentTree');
18
var ReactNativeTagHandles = require('ReactNativeTagHandles');
19
var ReactGenericBatching = require('ReactGenericBatching');
20
21
-var warning = require('fbjs/lib/warning');
21
+if (__DEV__) {
22
+ var warning = require('fbjs/lib/warning');
23
+}
24
25
/**
26
* Version of `ReactBrowserEventEmitter` that works on the receiving side of a
src/renderers/native/findNodeHandle.js
+4
-1
@@ -18,7 +18,10 @@ var ReactNativeFiberRenderer = require('ReactNativeFiberRenderer');
18
var {ReactCurrentOwner} = require('ReactGlobalSharedState');
19
20
var invariant = require('fbjs/lib/invariant');
21
-var warning = require('fbjs/lib/warning');
21
+
22
+if (__DEV__) {
23
+ var warning = require('fbjs/lib/warning');
24
+}
25
26
import type {Fiber} from 'ReactFiber';
27
import type {ReactInstance} from 'ReactInstanceType';
src/renderers/shared/shared/event/eventPlugins/ResponderTouchHistoryStore.js
+9
-7
@@ -104,13 +104,15 @@ function resetTouchRecord(touchRecord: TouchRecord, touch: Touch): void {
104
105
function getTouchIdentifier({identifier}: Touch): number {
106
invariant(identifier != null, 'Touch object is missing identifier.');
107
- warning(
108
- identifier <= MAX_TOUCH_BANK,
109
- 'Touch identifier %s is greater than maximum supported %s which causes ' +
110
- 'performance issues backfilling array locations for all of the indices.',
111
- identifier,
112
- MAX_TOUCH_BANK,
113
- );
107
+ if (__DEV__) {
108
+ warning(
109
+ identifier <= MAX_TOUCH_BANK,
110
+ 'Touch identifier %s is greater than maximum supported %s which causes ' +
111
+ 'performance issues backfilling array locations for all of the indices.',
112
+ identifier,
113
+ MAX_TOUCH_BANK,
114
+ );
115
+ }
116
return identifier;
117
}
118
src/renderers/shared/stack/reconciler/ReactChildReconciler.js
+4
-1
@@ -17,7 +17,10 @@ var ReactReconciler = require('ReactReconciler');
17
var instantiateReactComponent = require('instantiateReactComponent');
18
var shouldUpdateReactComponent = require('shouldUpdateReactComponent');
19
var traverseStackChildren = require('traverseStackChildren');
20
-var warning = require('fbjs/lib/warning');
20
+
21
+if (__DEV__) {
22
+ var warning = require('fbjs/lib/warning');
23
+}
24
25
var ReactComponentTreeHook;
26
src/renderers/shared/stack/reconciler/ReactCompositeComponent.js
+1
-1
@@ -24,6 +24,7 @@ var {ReactCurrentOwner} = require('ReactGlobalSharedState');
24
if (__DEV__) {
25
var {ReactDebugCurrentFrame} = require('ReactGlobalSharedState');
26
var ReactDebugCurrentStack = require('ReactDebugCurrentStack');
27
+ var warning = require('fbjs/lib/warning');
28
var warningAboutMissingGetChildContext = {};
29
}
30
@@ -32,7 +33,6 @@ var emptyObject = require('fbjs/lib/emptyObject');
33
var invariant = require('fbjs/lib/invariant');
34
var shallowEqual = require('fbjs/lib/shallowEqual');
35
var shouldUpdateReactComponent = require('shouldUpdateReactComponent');
35
-var warning = require('fbjs/lib/warning');
36
37
function StatelessComponent(Component) {}
38
StatelessComponent.prototype.render = function() {
src/renderers/shared/stack/reconciler/ReactReconciler.js
+15
-11
@@ -14,7 +14,9 @@
14
var ReactRef = require('ReactRef');
15
var ReactInstrumentation = require('ReactInstrumentation');
16
17
-var warning = require('fbjs/lib/warning');
17
+if (__DEV__) {
18
+ var warning = require('fbjs/lib/warning');
19
+}
20
21
/**
22
* Helper to call ReactRef.attachRefs with this composite component, split out
@@ -187,16 +189,18 @@ var ReactReconciler = {
189
updateBatchNumber,
190
) {
191
if (internalInstance._updateBatchNumber !== updateBatchNumber) {
190
- // The component's enqueued batch number should always be the current
191
- // batch or the following one.
192
- warning(
193
- internalInstance._updateBatchNumber == null ||
194
- internalInstance._updateBatchNumber === updateBatchNumber + 1,
195
- 'performUpdateIfNecessary: Unexpected batch number (current %s, ' +
196
- 'pending %s)',
197
- updateBatchNumber,
198
- internalInstance._updateBatchNumber,
199
- );
192
+ if (__DEV__) {
193
+ // The component's enqueued batch number should always be the current
194
+ // batch or the following one.
195
+ warning(
196
+ internalInstance._updateBatchNumber == null ||
197
+ internalInstance._updateBatchNumber === updateBatchNumber + 1,
198
+ 'performUpdateIfNecessary: Unexpected batch number (current %s, ' +
199
+ 'pending %s)',
200
+ updateBatchNumber,
201
+ internalInstance._updateBatchNumber,
202
+ );
203
+ }
204
return;
205
}
206
if (__DEV__) {
src/renderers/shared/stack/reconciler/flattenStackChildren.js
+4
-1
@@ -14,7 +14,10 @@
14
15
var KeyEscapeUtils = require('KeyEscapeUtils');
16
var traverseStackChildren = require('traverseStackChildren');
17
-var warning = require('fbjs/lib/warning');
17
+
18
+if (__DEV__) {
19
+ var warning = require('fbjs/lib/warning');
20
+}
21
22
var ReactComponentTreeHook;
23
src/renderers/shared/stack/reconciler/instantiateReactComponent.js
+4
-1
@@ -16,7 +16,10 @@ var ReactEmptyComponent = require('ReactEmptyComponent');
16
var ReactHostComponent = require('ReactHostComponent');
17
18
var invariant = require('fbjs/lib/invariant');
19
-var warning = require('fbjs/lib/warning');
19
+
20
+if (__DEV__) {
21
+ var warning = require('fbjs/lib/warning');
22
+}
23
24
var nextDebugID = 1;
25
src/renderers/shared/stack/reconciler/traverseStackChildren.js
+1
-1
@@ -13,7 +13,6 @@
13
14
var invariant = require('fbjs/lib/invariant');
15
var KeyEscapeUtils = require('KeyEscapeUtils');
16
-var warning = require('fbjs/lib/warning');
16
17
var ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
18
var FAUX_ITERATOR_SYMBOL = '@@iterator'; // Before Symbol spec.
@@ -24,6 +23,7 @@ var REACT_ELEMENT_TYPE =
23
0xeac7;
24
25
if (__DEV__) {
26
+ var warning = require('fbjs/lib/warning');
27
var {
28
getCurrentStackAddendum,
29
} = require('ReactGlobalSharedState').ReactComponentTreeHook;