From 11b22d2cc9e884715a2e5abdf043479ae7ef9552 Mon Sep 17 00:00:00 2001 From: Flarnie Marchan Date: Tue, 9 May 2017 20:09:41 +0100 Subject: [PATCH] Downgrade deprecation warnings from errors to warnings **what is the change?:** Swapping out `warning` module for a fork that uses `console.warn`. It looks like we were using the `warning` module for deprecation notices, *but* there is also a 'deprecated' module designed specifically for deprecation notices. However, we could not find any place that it was currently used. Since React's build process is not 100% clear to me, I assume it could still be used somewhere by something and just updated it along with other deprecation notices. We might consider a follow-up diff that does some clean up here; - remove 'deprecated' module if it's unused, OR - use 'deprecated' module for all our current deprecation warnings **why make this change?:** - We have had complaints about noisy warnings, in particular after introducing new deprecations - They potentially cause CI failures - Deprecations are not really time-sensitive, can ship without breaking your app, etc. For more context - https://github.com/facebook/react/issues/9395 **test plan:** `npm run test` and unit tests for the new modules and manual testing (WIP) **issue:** https://github.com/facebook/react/issues/9395 --- .../__tests__/ReactDOMFactories-test.js | 8 ++-- src/isomorphic/React.js | 12 +++--- src/isomorphic/__tests__/React-test.js | 24 +++++------ .../classic/element/ReactElementValidator.js | 5 ++- .../__tests__/ReactElementValidator-test.js | 8 ++-- .../modern/class/ReactBaseClasses.js | 4 +- .../ReactCoffeeScriptClass-test.coffee | 8 ++-- .../class/__tests__/ReactES6Class-test.js | 8 ++-- .../__tests__/ReactTypeScriptClass-test.ts | 8 ++-- .../ReactCompositeComponentState-test.js | 12 +++--- src/renderers/__tests__/ReactPerf-test.js | 16 ++++---- src/renderers/shared/ReactPerf.js | 6 +-- .../shared/fiber/ReactFiberClassComponent.js | 5 ++- .../reconciler/ReactCompositeComponent.js | 3 +- src/shared/utils/deprecated.js | 4 +- src/shared/utils/lowPriorityWarning.js | 41 +++++++++++++++++++ 16 files changed, 109 insertions(+), 63 deletions(-) create mode 100644 src/shared/utils/lowPriorityWarning.js diff --git a/src/addons/__tests__/ReactDOMFactories-test.js b/src/addons/__tests__/ReactDOMFactories-test.js index b4a7a78ceda57..641faa3f003dd 100644 --- a/src/addons/__tests__/ReactDOMFactories-test.js +++ b/src/addons/__tests__/ReactDOMFactories-test.js @@ -17,13 +17,15 @@ var {div} = require('ReactDOMFactories'); describe('ReactDOMFactories', () => { it('allow factories to be called without warnings', () => { spyOn(console, 'error'); + spyOn(console, 'warn'); var element = div(); expect(element.type).toBe('div'); expect(console.error).not.toHaveBeenCalled(); + expect(console.warn).not.toHaveBeenCalled(); }); it('warns once when accessing React.DOM methods', () => { - spyOn(console, 'error'); + spyOn(console, 'warn'); var a = React.DOM.a(); var p = React.DOM.p(); @@ -31,8 +33,8 @@ describe('ReactDOMFactories', () => { expect(a.type).toBe('a'); expect(p.type).toBe('p'); - expect(console.error).toHaveBeenCalledTimes(1); - expect(console.error.calls.first().args[0]).toContain( + expect(console.warn).toHaveBeenCalledTimes(1); + expect(console.warn.calls.first().args[0]).toContain( 'Warning: Accessing factories like React.DOM.a has been deprecated', ); }); diff --git a/src/isomorphic/React.js b/src/isomorphic/React.js index ceb52dfa68d35..8335945752b60 100644 --- a/src/isomorphic/React.js +++ b/src/isomorphic/React.js @@ -27,7 +27,7 @@ var createFactory = ReactElement.createFactory; var cloneElement = ReactElement.cloneElement; if (__DEV__) { - var warning = require('fbjs/lib/warning'); + var lowPriorityWarning = require('lowPriorityWarning'); var canDefineProperty = require('canDefineProperty'); var ReactElementValidator = require('ReactElementValidator'); createElement = ReactElementValidator.createElement; @@ -91,7 +91,7 @@ if (__DEV__) { let warnedForPropTypes = false; React.createMixin = function(mixin) { - warning( + lowPriorityWarning( warnedForCreateMixin, 'React.createMixin is deprecated and should not be used. You ' + 'can use this mixin directly instead.', @@ -104,7 +104,7 @@ if (__DEV__) { if (canDefineProperty) { Object.defineProperty(React, 'checkPropTypes', { get() { - warning( + lowPriorityWarning( warnedForCheckPropTypes, 'checkPropTypes has been moved to a separate package. ' + 'Accessing React.checkPropTypes is no longer supported ' + @@ -119,7 +119,7 @@ if (__DEV__) { Object.defineProperty(React, 'createClass', { get: function() { - warning( + lowPriorityWarning( warnedForCreateClass, 'React.createClass is no longer supported. Use a plain JavaScript ' + "class instead. If you're not yet ready to migrate, " + @@ -133,7 +133,7 @@ if (__DEV__) { Object.defineProperty(React, 'PropTypes', { get() { - warning( + lowPriorityWarning( warnedForPropTypes, 'PropTypes has been moved to a separate package. ' + 'Accessing React.PropTypes is no longer supported ' + @@ -155,7 +155,7 @@ if (__DEV__) { Object.keys(ReactDOMFactories).forEach(function(factory) { React.DOM[factory] = function(...args) { if (!warnedForFactories) { - warning( + lowPriorityWarning( false, 'Accessing factories like React.DOM.%s has been deprecated ' + 'and will be removed in the future. Use the ' + diff --git a/src/isomorphic/__tests__/React-test.js b/src/isomorphic/__tests__/React-test.js index bd5d5bc1aaa4b..86e574a859636 100644 --- a/src/isomorphic/__tests__/React-test.js +++ b/src/isomorphic/__tests__/React-test.js @@ -19,22 +19,22 @@ describe('React', () => { }); it('should log a deprecation warning once when using React.createMixin', () => { - spyOn(console, 'error'); + spyOn(console, 'warn'); React.createMixin(); React.createMixin(); - expectDev(console.error.calls.count()).toBe(1); - expectDev(console.error.calls.argsFor(0)[0]).toContain( + expectDev(console.warn.calls.count()).toBe(1); + expectDev(console.warn.calls.argsFor(0)[0]).toContain( 'React.createMixin is deprecated and should not be used', ); }); it('should warn once when attempting to access React.createClass', () => { - spyOn(console, 'error'); + spyOn(console, 'warn'); let createClass = React.createClass; createClass = React.createClass; expect(createClass).not.toBe(undefined); - expectDev(console.error.calls.count()).toBe(1); - expectDev(console.error.calls.argsFor(0)[0]).toContain( + expectDev(console.warn.calls.count()).toBe(1); + expectDev(console.warn.calls.argsFor(0)[0]).toContain( 'React.createClass is no longer supported. Use a plain JavaScript ' + "class instead. If you're not yet ready to migrate, " + 'create-react-class is available on npm as a drop-in replacement. ' + @@ -43,12 +43,12 @@ describe('React', () => { }); it('should warn once when attempting to access React.PropTypes', () => { - spyOn(console, 'error'); + spyOn(console, 'warn'); let PropTypes = React.PropTypes; PropTypes = React.PropTypes; expect(PropTypes).not.toBe(undefined); - expectDev(console.error.calls.count()).toBe(1); - expectDev(console.error.calls.argsFor(0)[0]).toContain( + expectDev(console.warn.calls.count()).toBe(1); + expectDev(console.warn.calls.argsFor(0)[0]).toContain( 'PropTypes has been moved to a separate package. ' + 'Accessing React.PropTypes is no longer supported ' + 'and will be removed completely in React 16. ' + @@ -58,12 +58,12 @@ describe('React', () => { }); it('should warn once when attempting to access React.checkPropTypes', () => { - spyOn(console, 'error'); + spyOn(console, 'warn'); let checkPropTypes = React.checkPropTypes; checkPropTypes = React.checkPropTypes; expect(checkPropTypes).not.toBe(undefined); - expectDev(console.error.calls.count()).toBe(1); - expectDev(console.error.calls.argsFor(0)[0]).toContain( + expectDev(console.warn.calls.count()).toBe(1); + expectDev(console.warn.calls.argsFor(0)[0]).toContain( 'checkPropTypes has been moved to a separate package. ' + 'Accessing React.checkPropTypes is no longer supported ' + 'and will be removed completely in React 16. ' + diff --git a/src/isomorphic/classic/element/ReactElementValidator.js b/src/isomorphic/classic/element/ReactElementValidator.js index ea919f3a35caf..30d255513f206 100644 --- a/src/isomorphic/classic/element/ReactElementValidator.js +++ b/src/isomorphic/classic/element/ReactElementValidator.js @@ -27,8 +27,9 @@ var getIteratorFn = require('getIteratorFn'); if (__DEV__) { var checkPropTypes = require('prop-types/checkPropTypes'); - var warning = require('fbjs/lib/warning'); + var lowPriorityWarning = require('lowPriorityWarning'); var ReactDebugCurrentFrame = require('ReactDebugCurrentFrame'); + var warning = require('fbjs/lib/warning'); var {getCurrentStackAddendum} = require('ReactComponentTreeHook'); } @@ -285,7 +286,7 @@ var ReactElementValidator = { Object.defineProperty(validatedFactory, 'type', { enumerable: false, get: function() { - warning( + lowPriorityWarning( false, 'Factory.type is deprecated. Access the class directly ' + 'before passing it to createFactory.', diff --git a/src/isomorphic/classic/element/__tests__/ReactElementValidator-test.js b/src/isomorphic/classic/element/__tests__/ReactElementValidator-test.js index 69bb8fd512b8d..969b4de9b6fbb 100644 --- a/src/isomorphic/classic/element/__tests__/ReactElementValidator-test.js +++ b/src/isomorphic/classic/element/__tests__/ReactElementValidator-test.js @@ -441,20 +441,20 @@ describe('ReactElementValidator', () => { }); it('should warn when accessing .type on an element factory', () => { - spyOn(console, 'error'); + spyOn(console, 'warn'); function TestComponent() { return
; } var TestFactory = React.createFactory(TestComponent); expect(TestFactory.type).toBe(TestComponent); - expectDev(console.error.calls.count()).toBe(1); - expectDev(console.error.calls.argsFor(0)[0]).toBe( + expectDev(console.warn.calls.count()).toBe(1); + expectDev(console.warn.calls.argsFor(0)[0]).toBe( 'Warning: Factory.type is deprecated. Access the class directly before ' + 'passing it to createFactory.', ); // Warn once, not again expect(TestFactory.type).toBe(TestComponent); - expectDev(console.error.calls.count()).toBe(1); + expectDev(console.warn.calls.count()).toBe(1); }); it('does not warn when using DOM node as children', () => { diff --git a/src/isomorphic/modern/class/ReactBaseClasses.js b/src/isomorphic/modern/class/ReactBaseClasses.js index 7397d8a49d8d1..4d17ace2bce56 100644 --- a/src/isomorphic/modern/class/ReactBaseClasses.js +++ b/src/isomorphic/modern/class/ReactBaseClasses.js @@ -16,7 +16,7 @@ var ReactNoopUpdateQueue = require('ReactNoopUpdateQueue'); var canDefineProperty = require('canDefineProperty'); var emptyObject = require('fbjs/lib/emptyObject'); var invariant = require('fbjs/lib/invariant'); -var warning = require('fbjs/lib/warning'); +var lowPriorityWarning = require('lowPriorityWarning'); /** * Base class helpers for the updating state of a component. @@ -108,7 +108,7 @@ if (__DEV__) { if (canDefineProperty) { Object.defineProperty(ReactComponent.prototype, methodName, { get: function() { - warning( + lowPriorityWarning( false, '%s(...) is deprecated in plain JavaScript React classes. %s', info[0], diff --git a/src/isomorphic/modern/class/__tests__/ReactCoffeeScriptClass-test.coffee b/src/isomorphic/modern/class/__tests__/ReactCoffeeScriptClass-test.coffee index 15f5e46eab758..3def0950b2c50 100644 --- a/src/isomorphic/modern/class/__tests__/ReactCoffeeScriptClass-test.coffee +++ b/src/isomorphic/modern/class/__tests__/ReactCoffeeScriptClass-test.coffee @@ -378,16 +378,16 @@ describe 'ReactCoffeeScriptClass', -> undefined it 'should throw AND warn when trying to access classic APIs', -> - spyOn console, 'error' + spyOn console, 'warn' instance = test Inner(name: 'foo'), 'DIV', 'foo' expect(-> instance.replaceState {}).toThrow() expect(-> instance.isMounted()).toThrow() - expect(console.error.calls.count()).toBe 2 - expect(console.error.calls.argsFor(0)[0]).toContain( + expect(console.warn.calls.count()).toBe 2 + expect(console.warn.calls.argsFor(0)[0]).toContain( 'replaceState(...) is deprecated in plain JavaScript React classes' ) - expect(console.error.calls.argsFor(1)[0]).toContain( + expect(console.warn.calls.argsFor(1)[0]).toContain( 'isMounted(...) is deprecated in plain JavaScript React classes' ) undefined diff --git a/src/isomorphic/modern/class/__tests__/ReactES6Class-test.js b/src/isomorphic/modern/class/__tests__/ReactES6Class-test.js index f634e1d1c58d4..29d94221a722d 100644 --- a/src/isomorphic/modern/class/__tests__/ReactES6Class-test.js +++ b/src/isomorphic/modern/class/__tests__/ReactES6Class-test.js @@ -402,15 +402,15 @@ describe('ReactES6Class', () => { }); it('should throw AND warn when trying to access classic APIs', () => { - spyOn(console, 'error'); + spyOn(console, 'warn'); var instance = test(, 'DIV', 'foo'); expect(() => instance.replaceState({})).toThrow(); expect(() => instance.isMounted()).toThrow(); - expect(console.error.calls.count()).toBe(2); - expect(console.error.calls.argsFor(0)[0]).toContain( + expect(console.warn.calls.count()).toBe(2); + expect(console.warn.calls.argsFor(0)[0]).toContain( 'replaceState(...) is deprecated in plain JavaScript React classes', ); - expect(console.error.calls.argsFor(1)[0]).toContain( + expect(console.warn.calls.argsFor(1)[0]).toContain( 'isMounted(...) is deprecated in plain JavaScript React classes', ); }); diff --git a/src/isomorphic/modern/class/__tests__/ReactTypeScriptClass-test.ts b/src/isomorphic/modern/class/__tests__/ReactTypeScriptClass-test.ts index 33085c89d9213..66d5cd33631c1 100644 --- a/src/isomorphic/modern/class/__tests__/ReactTypeScriptClass-test.ts +++ b/src/isomorphic/modern/class/__tests__/ReactTypeScriptClass-test.ts @@ -502,18 +502,18 @@ describe('ReactTypeScriptClass', function() { }); it('should throw AND warn when trying to access classic APIs', function() { - spyOn(console, 'error'); + spyOn(console, 'warn'); var instance = test( React.createElement(Inner, {name: 'foo'}), 'DIV','foo' ); expect(() => instance.replaceState({})).toThrow(); expect(() => instance.isMounted()).toThrow(); - expect((console.error).calls.count()).toBe(2); - expect((console.error).calls.argsFor(0)[0]).toContain( + expect((console.warn).calls.count()).toBe(2); + expect((console.warn).calls.argsFor(0)[0]).toContain( 'replaceState(...) is deprecated in plain JavaScript React classes' ); - expect((console.error).calls.argsFor(1)[0]).toContain( + expect((console.warn).calls.argsFor(1)[0]).toContain( 'isMounted(...) is deprecated in plain JavaScript React classes' ); }); diff --git a/src/renderers/__tests__/ReactCompositeComponentState-test.js b/src/renderers/__tests__/ReactCompositeComponentState-test.js index ddfdabe106baf..222d21187238a 100644 --- a/src/renderers/__tests__/ReactCompositeComponentState-test.js +++ b/src/renderers/__tests__/ReactCompositeComponentState-test.js @@ -405,7 +405,7 @@ describe('ReactCompositeComponent-state', () => { }); it('should treat assigning to this.state inside cWRP as a replaceState, with a warning', () => { - spyOn(console, 'error'); + spyOn(console, 'warn'); let ops = []; class Test extends React.Component { @@ -439,8 +439,8 @@ describe('ReactCompositeComponent-state', () => { 'render -- step: 3, extra: false', 'callback -- step: 3, extra: false', ]); - expect(console.error.calls.count()).toEqual(1); - expect(console.error.calls.argsFor(0)[0]).toEqual( + expect(console.warn.calls.count()).toEqual(1); + expect(console.warn.calls.argsFor(0)[0]).toEqual( 'Warning: Test.componentWillReceiveProps(): Assigning directly to ' + "this.state is deprecated (except inside a component's constructor). " + 'Use setState instead.', @@ -449,7 +449,7 @@ describe('ReactCompositeComponent-state', () => { if (ReactDOMFeatureFlags.useFiber) { it('should treat assigning to this.state inside cWM as a replaceState, with a warning', () => { - spyOn(console, 'error'); + spyOn(console, 'warn'); let ops = []; class Test extends React.Component { @@ -480,8 +480,8 @@ describe('ReactCompositeComponent-state', () => { 'render -- step: 3, extra: false', 'callback -- step: 3, extra: false', ]); - expect(console.error.calls.count()).toEqual(1); - expect(console.error.calls.argsFor(0)[0]).toEqual( + expect(console.warn.calls.count()).toEqual(1); + expect(console.warn.calls.argsFor(0)[0]).toEqual( 'Warning: Test.componentWillMount(): Assigning directly to ' + "this.state is deprecated (except inside a component's constructor). " + 'Use setState instead.', diff --git a/src/renderers/__tests__/ReactPerf-test.js b/src/renderers/__tests__/ReactPerf-test.js index a610e9523d497..9ba784a32fbe8 100644 --- a/src/renderers/__tests__/ReactPerf-test.js +++ b/src/renderers/__tests__/ReactPerf-test.js @@ -406,30 +406,30 @@ describeStack('ReactPerf', () => { it('warns once when using getMeasurementsSummaryMap', () => { var measurements = measure(() => {}); - spyOn(console, 'error'); + spyOn(console, 'warn'); ReactPerf.getMeasurementsSummaryMap(measurements); - expectDev(console.error.calls.count()).toBe(1); - expectDev(console.error.calls.argsFor(0)[0]).toContain( + expectDev(console.warn.calls.count()).toBe(1); + expectDev(console.warn.calls.argsFor(0)[0]).toContain( '`ReactPerf.getMeasurementsSummaryMap(...)` is deprecated. Use ' + '`ReactPerf.getWasted(...)` instead.', ); ReactPerf.getMeasurementsSummaryMap(measurements); - expectDev(console.error.calls.count()).toBe(1); + expectDev(console.warn.calls.count()).toBe(1); }); it('warns once when using printDOM', () => { var measurements = measure(() => {}); - spyOn(console, 'error'); + spyOn(console, 'warn'); ReactPerf.printDOM(measurements); - expectDev(console.error.calls.count()).toBe(1); - expectDev(console.error.calls.argsFor(0)[0]).toContain( + expectDev(console.warn.calls.count()).toBe(1); + expectDev(console.warn.calls.argsFor(0)[0]).toContain( '`ReactPerf.printDOM(...)` is deprecated. Use ' + '`ReactPerf.printOperations(...)` instead.', ); ReactPerf.printDOM(measurements); - expectDev(console.error.calls.count()).toBe(1); + expectDev(console.warn.calls.count()).toBe(1); }); it('returns isRunning state', () => { diff --git a/src/renderers/shared/ReactPerf.js b/src/renderers/shared/ReactPerf.js index d119959c551b1..17abb58095e75 100644 --- a/src/renderers/shared/ReactPerf.js +++ b/src/renderers/shared/ReactPerf.js @@ -13,7 +13,7 @@ 'use strict'; var ReactDebugTool = require('ReactDebugTool'); -var warning = require('fbjs/lib/warning'); +var lowPriorityWarning = require('lowPriorityWarning'); var alreadyWarned = false; import type {FlushHistory} from 'ReactDebugTool'; @@ -390,7 +390,7 @@ function printOperations(flushHistory?: FlushHistory) { var warnedAboutPrintDOM = false; function printDOM(measurements: FlushHistory) { - warning( + lowPriorityWarning( warnedAboutPrintDOM, '`ReactPerf.printDOM(...)` is deprecated. Use ' + '`ReactPerf.printOperations(...)` instead.', @@ -401,7 +401,7 @@ function printDOM(measurements: FlushHistory) { var warnedAboutGetMeasurementsSummaryMap = false; function getMeasurementsSummaryMap(measurements: FlushHistory) { - warning( + lowPriorityWarning( warnedAboutGetMeasurementsSummaryMap, '`ReactPerf.getMeasurementsSummaryMap(...)` is deprecated. Use ' + '`ReactPerf.getWasted(...)` instead.', diff --git a/src/renderers/shared/fiber/ReactFiberClassComponent.js b/src/renderers/shared/fiber/ReactFiberClassComponent.js index 1d695f7cb2e3f..a02cda757cc88 100644 --- a/src/renderers/shared/fiber/ReactFiberClassComponent.js +++ b/src/renderers/shared/fiber/ReactFiberClassComponent.js @@ -45,6 +45,7 @@ const isArray = Array.isArray; if (__DEV__) { var {startPhaseTimer, stopPhaseTimer} = require('ReactDebugFiberPerf'); var warning = require('fbjs/lib/warning'); + var lowPriorityWarning = require('lowPriorityWarning'); var warnOnInvalidCallback = function(callback: mixed, callerName: string) { warning( callback === null || typeof callback === 'function', @@ -316,7 +317,7 @@ module.exports = function( if (oldState !== instance.state) { if (__DEV__) { - warning( + lowPriorityWarning( false, '%s.componentWillMount(): Assigning directly to this.state is ' + "deprecated (except inside a component's " + @@ -345,7 +346,7 @@ module.exports = function( if (instance.state !== oldState) { if (__DEV__) { - warning( + lowPriorityWarning( false, '%s.componentWillReceiveProps(): Assigning directly to ' + "this.state is deprecated (except inside a component's " + diff --git a/src/renderers/shared/stack/reconciler/ReactCompositeComponent.js b/src/renderers/shared/stack/reconciler/ReactCompositeComponent.js index 7e97b2316dc0a..54b94701ca57b 100644 --- a/src/renderers/shared/stack/reconciler/ReactCompositeComponent.js +++ b/src/renderers/shared/stack/reconciler/ReactCompositeComponent.js @@ -30,6 +30,7 @@ if (__DEV__) { var checkPropTypes = require('prop-types/checkPropTypes'); var emptyObject = require('fbjs/lib/emptyObject'); var invariant = require('fbjs/lib/invariant'); +var lowPriorityWarning = require('lowPriorityWarning'); var shallowEqual = require('fbjs/lib/shallowEqual'); var shouldUpdateReactComponent = require('shouldUpdateReactComponent'); var warning = require('fbjs/lib/warning'); @@ -879,7 +880,7 @@ var ReactCompositeComponent = { inst.state = beforeState; inst.updater.enqueueReplaceState(inst, afterState); if (__DEV__) { - warning( + lowPriorityWarning( false, '%s.componentWillReceiveProps(): Assigning directly to ' + "this.state is deprecated (except inside a component's " + diff --git a/src/shared/utils/deprecated.js b/src/shared/utils/deprecated.js index 1ed8bb2019283..81e24cfd98d5d 100644 --- a/src/shared/utils/deprecated.js +++ b/src/shared/utils/deprecated.js @@ -12,7 +12,7 @@ 'use strict'; -var warning = require('fbjs/lib/warning'); +var lowPriorityWarning = require('lowPriorityWarning'); /** * This will log a single deprecation notice per function and forward the call @@ -35,7 +35,7 @@ function deprecated( var warned = false; if (__DEV__) { var newFn = function() { - warning( + lowPriorityWarning( warned, /* eslint-disable no-useless-concat */ // Require examples in this string must be split to prevent React's diff --git a/src/shared/utils/lowPriorityWarning.js b/src/shared/utils/lowPriorityWarning.js new file mode 100644 index 0000000000000..d4deb584dccc8 --- /dev/null +++ b/src/shared/utils/lowPriorityWarning.js @@ -0,0 +1,41 @@ +/** + * Copyright 2014-2015, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + * + * @providesModule lowPriorityWarning + */ + +'use strict'; + +/** + * Forked from fbjs/warning: + * https://github.com/facebook/fbjs/blob/e66ba20ad5be433eb54423f2b097d829324d9de6/packages/fbjs/src/__forks__/warning.js + * + * Only change is we use console.warn instead of console.error, + * and do nothing when 'console' is not supported. + * This really simplifies the code. + * --- + * + * Similar to invariant but only logs a warning if the condition is not met. + * This can be used to log issues in development environments in critical + * paths. Removing the logging code for production environments will keep the + * same logic and follow the same code paths. + */ + +var lowPriorityWarning = function() {}; + +if (__DEV__) { + lowPriorityWarning = function(condition, format, ...args) { + var argIndex = 0; + var message = 'Warning: ' + format.replace(/%s/g, () => args[argIndex++]); + if (!condition && typeof console !== 'undefined') { + console.warn(message); + } + }; +} + +module.exports = lowPriorityWarning;