@samitouri / QOS-React-2 / commits / 4e5543965d

Flip console.warn to use warning module so users can intercept all warnings by shimming the warning module.

The two remaining console.warns are: /Users/jsproch/react/src/test/mock-modules.js: 19 return mocks.generateFromMetadata(mocks.getMetadata(exports)); 20 } catch (err) { 21: console.warn(err); 22 return exports; 23 } /Users/jsproch/react/src/vendor/core/warning.js: 39 var argIndex = 0; 40 var message = 'Warning: ' + format.replace(/%s/g, () => args[argIndex++]); 41: console.warn(message); 42 try { 43 // --- Welcome to debugging React ---

Jim committed Feb 10, 2015 at 13:42 UTC 4e5543965d9d126415791750a2056d14277f3cdc
9 files changed +53 -59
src/addons/transitions/ReactCSSTransitionGroupChild.js
+6 -3
@@ -18,6 +18,7 @@ var CSSCore = require('CSSCore');
18 var ReactTransitionEvents = require('ReactTransitionEvents');
19
20 var onlyChild = require('onlyChild');
21 +var warning = require('warning');
22
23 // We don't remove the element from the DOM until we receive an animationend or
24 // transitionend event. If the user screws up and forgets to add an animation
@@ -31,11 +32,13 @@ var noEventListener = null;
32
33 if (__DEV__) {
34 noEventListener = function() {
34 - console.warn(
35 + warning(
36 + false,
37 'transition(): tried to perform an animation without ' +
38 'an animationend or transitionend event after timeout (' +
37 - NO_EVENT_TIMEOUT + 'ms). You should either disable this ' +
38 - 'transition in JS or add a CSS animation/transition.'
39 + '%sms). You should either disable this ' +
40 + 'transition in JS or add a CSS animation/transition.',
41 + NO_EVENT_TIMEOUT
42 );
43 };
44 }
src/browser/ui/ReactDOMComponent.js
+11 -14
@@ -29,7 +29,6 @@ var escapeTextContentForBrowser = require('escapeTextContentForBrowser');
29 var invariant = require('invariant');
30 var isEventSupported = require('isEventSupported');
31 var keyOf = require('keyOf');
32 -var monitorCodeUse = require('monitorCodeUse');
32 var warning = require('warning');
33
34 var deleteListener = ReactBrowserEventEmitter.deleteListener;
@@ -74,14 +73,13 @@ function assertValidProps(props) {
73 'Directly setting property `innerHTML` is not permitted. ' +
74 'For more information, lookup documentation on `dangerouslySetInnerHTML`.'
75 );
77 - if (props.contentEditable && props.children != null) {
78 - console.warn(
79 - 'A component is `contentEditable` and contains `children` managed by ' +
80 - 'React. It is now your responsibility to guarantee that none of ' +
81 - 'those nodes are unexpectedly modified or duplicated. This is ' +
82 - 'probably not intentional.'
83 - );
84 - }
76 + warning(
77 + !props.contentEditable || props.children == null,
78 + 'A component is `contentEditable` and contains `children` managed by ' +
79 + 'React. It is now your responsibility to guarantee that none of ' +
80 + 'those nodes are unexpectedly modified or duplicated. This is ' +
81 + 'probably not intentional.'
82 + );
83 }
84 invariant(
85 props.style == null || typeof props.style === 'object',
@@ -95,11 +93,10 @@ function putListener(id, registrationName, listener, transaction) {
93 if (__DEV__) {
94 // IE8 has no API for event capturing and the `onScroll` event doesn't
95 // bubble.
98 - if (registrationName === 'onScroll' &&
99 - !isEventSupported('scroll', true)) {
100 - monitorCodeUse('react_no_scroll_event');
101 - console.warn('This browser doesn\'t support the `onScroll` event');
102 - }
96 + warning(
97 + registrationName !== 'onScroll' || isEventSupported('scroll', true),
98 + 'This browser doesn\'t support the `onScroll` event'
99 + );
100 }
101 var container = ReactMount.findReactContainerForID(id);
102 if (container) {
src/browser/ui/ReactMount.js
+8 -4
@@ -473,7 +473,8 @@ var ReactMount = {
473 var rootElementSibling = reactRootElement;
474 while (rootElementSibling) {
475 if (ReactMount.isRenderedByReact(rootElementSibling)) {
476 - console.warn(
476 + warning(
477 + false,
478 'render(): Target node has markup rendered by React, but there ' +
479 'are unrelated nodes as well. This is most commonly caused by ' +
480 'white-space inserted around server-rendered markup.'
@@ -648,7 +649,8 @@ var ReactMount = {
649 // warning is when the container is empty.
650 rootElementsByReactRootID[reactRootID] = containerChild;
651 } else {
651 - console.warn(
652 + warning(
653 + false,
654 'ReactMount: Root element has been removed from its original ' +
655 'container. New container:', rootElement.parentNode
656 );
@@ -828,7 +830,8 @@ var ReactMount = {
830 );
831
832 if (__DEV__) {
831 - console.warn(
833 + warning(
834 + false,
835 'React attempted to reuse markup in a container but the ' +
836 'checksum was invalid. This generally means that you are ' +
837 'using server rendering and the markup generated on the ' +
@@ -836,7 +839,8 @@ var ReactMount = {
839 'new markup to compensate which works but you have lost many ' +
840 'of the benefits of server rendering. Instead, figure out ' +
841 'why the markup being generated is different on the client ' +
839 - 'or server:\n' + difference
842 + 'or server:\n%s',
843 + difference
844 );
845 }
846 }
src/browser/ui/__tests__/ReactDOMComponent-test.js
+1 -1
@@ -494,7 +494,7 @@ describe('ReactDOMComponent', function() {
494 ReactTestUtils.renderIntoDocument(<div onScroll={function(){}} />);
495 expect(console.warn.calls.length).toBe(1);
496 expect(console.warn.mostRecentCall.args[0]).toBe(
497 - 'This browser doesn\'t support the `onScroll` event'
497 + 'Warning: This browser doesn\'t support the `onScroll` event'
498 );
499 });
500 });
src/classic/class/ReactClass.js
+16 -19
@@ -24,7 +24,6 @@ var assign = require('Object.assign');
24 var invariant = require('invariant');
25 var keyMirror = require('keyMirror');
26 var keyOf = require('keyOf');
27 -var monitorCodeUse = require('monitorCodeUse');
27 var warning = require('warning');
28
29 var MIXINS_KEY = keyOf({mixins: null});
@@ -659,17 +658,19 @@ function bindAutoBindMethod(component, method) {
658 // ignore the value of "this" that the user is trying to use, so
659 // let's warn.
660 if (newThis !== component && newThis !== null) {
662 - monitorCodeUse('react_bind_warning', { component: componentName });
663 - console.warn(
661 + warning(
662 + false,
663 'bind(): React component methods may only be bound to the ' +
665 - 'component instance. See ' + componentName
664 + 'component instance. See %s',
665 + componentName
666 );
667 } else if (!args.length) {
668 - monitorCodeUse('react_bind_warning', { component: componentName });
669 - console.warn(
668 + warning(
669 + false,
670 'bind(): You are binding a component method to the component. ' +
671 'React does this for you automatically in a high-performance ' +
672 - 'way, so you can safely remove this call. See ' + componentName
672 + 'way, so you can safely remove this call. See ',
673 + componentName
674 );
675 return boundMethod;
676 }
@@ -874,18 +875,14 @@ var ReactClass = {
875 );
876
877 if (__DEV__) {
877 - if (Constructor.prototype.componentShouldUpdate) {
878 - monitorCodeUse(
879 - 'react_component_should_update_warning',
880 - { component: spec.displayName }
881 - );
882 - console.warn(
883 - (spec.displayName || 'A component') + ' has a method called ' +
884 - 'componentShouldUpdate(). Did you mean shouldComponentUpdate()? ' +
885 - 'The name is phrased as a question because the function is ' +
886 - 'expected to return a value.'
887 - );
888 - }
878 + warning(
879 + !Constructor.prototype.componentShouldUpdate,
880 + '%s has a method called ' +
881 + 'componentShouldUpdate(). Did you mean shouldComponentUpdate()? ' +
882 + 'The name is phrased as a question because the function is ' +
883 + 'expected to return a value.',
884 + spec.displayName || 'A component'
885 + );
886 }
887
888 // Reduce time spent doing lookups by setting these on the prototype.
src/classic/class/__tests__/ReactClass-test.js
+2 -2
@@ -170,7 +170,7 @@ describe('ReactClass-spec', function() {
170 });
171 expect(console.warn.argsForCall.length).toBe(1);
172 expect(console.warn.argsForCall[0][0]).toBe(
173 - 'A component has a method called componentShouldUpdate(). Did you ' +
173 + 'Warning: A component has a method called componentShouldUpdate(). Did you ' +
174 'mean shouldComponentUpdate()? The name is phrased as a question ' +
175 'because the function is expected to return a value.'
176 );
@@ -185,7 +185,7 @@ describe('ReactClass-spec', function() {
185 });
186 expect(console.warn.argsForCall.length).toBe(2);
187 expect(console.warn.argsForCall[1][0]).toBe(
188 - 'NamedComponent has a method called componentShouldUpdate(). Did you ' +
188 + 'Warning: NamedComponent has a method called componentShouldUpdate(). Did you ' +
189 'mean shouldComponentUpdate()? The name is phrased as a question ' +
190 'because the function is expected to return a value.'
191 );
src/classic/element/ReactElementValidator.js
+2 -8
@@ -26,7 +26,6 @@ var ReactCurrentOwner = require('ReactCurrentOwner');
26 var ReactNativeComponent = require('ReactNativeComponent');
27
28 var getIteratorFn = require('getIteratorFn');
29 -var monitorCodeUse = require('monitorCodeUse');
29 var invariant = require('invariant');
30 var warning = require('warning');
31
@@ -157,22 +156,17 @@ function warnAndMonitorForKeyUse(warningID, message, element, parentType) {
156 // Usually the current owner is the offender, but if it accepts children as a
157 // property, it may be the creator of the child that's responsible for
158 // assigning it a key.
160 - var childOwnerName = null;
159 if (element &&
160 element._owner &&
161 element._owner !== ReactCurrentOwner.current) {
162 // Name of the component that originally created this child.
165 - childOwnerName = getName(element._owner);
163 + var childOwnerName = getName(element._owner);
164
165 message += ` It was passed a child from ${childOwnerName}.`;
166 }
167
168 message += ' See http://fb.me/react-warning-keys for more information.';
171 - monitorCodeUse(warningID, {
172 - component: useName,
173 - componentOwner: childOwnerName
174 - });
175 - console.warn(message);
169 + warning(false, '%s', warningID + ': ' + message);
170 }
171
172 /**
src/core/ReactCompositeComponent.js
+6 -7
@@ -588,13 +588,12 @@ var ReactCompositeComponentMixin = {
588 inst.shouldComponentUpdate(nextProps, nextState, nextContext);
589
590 if (__DEV__) {
591 - if (typeof shouldUpdate === 'undefined') {
592 - console.warn(
593 - (this.getName() || 'ReactCompositeComponent') +
594 - '.shouldComponentUpdate(): Returned undefined instead of a ' +
595 - 'boolean value. Make sure to return true or false.'
596 - );
597 - }
591 + warning(
592 + typeof shouldUpdate !== 'undefined',
593 + '%s.shouldComponentUpdate(): Returned undefined instead of a ' +
594 + 'boolean value. Make sure to return true or false.',
595 + this.getName() || 'ReactCompositeComponent'
596 + );
597 }
598
599 if (shouldUpdate) {
src/core/__tests__/ReactCompositeComponent-test.js
+1 -1
@@ -490,7 +490,7 @@ describe('ReactCompositeComponent', function() {
490
491 expect(console.warn.argsForCall.length).toBe(1);
492 expect(console.warn.argsForCall[0][0]).toBe(
493 - 'Component.shouldComponentUpdate(): Returned undefined instead of a ' +
493 + 'Warning: Component.shouldComponentUpdate(): Returned undefined instead of a ' +
494 'boolean value. Make sure to return true or false.'
495 );
496 });