|
| 1 | +/** |
| 2 | + * Copyright 2014-2015, Facebook, Inc. |
| 3 | + * All rights reserved. |
| 4 | + * |
| 5 | + * This source code is licensed under the BSD-style license found in the |
| 6 | + * LICENSE file in the root directory of https://github.com/facebook/react/tree/0.13-stable. |
| 7 | + * An additional grant of patent rights can be found in the PATENTS file in the same directory. |
| 8 | + * |
| 9 | + * @providesModule warning |
| 10 | + */ |
| 11 | + |
| 12 | +"use strict"; |
| 13 | + |
| 14 | +/** |
| 15 | + * Similar to invariant but only logs a warning if the condition is not met. |
| 16 | + * This can be used to log issues in development environments in critical |
| 17 | + * paths. Removing the logging code for production environments will keep the |
| 18 | + * same logic and follow the same code paths. |
| 19 | + */ |
| 20 | + |
| 21 | +var __DEV__ = process.env.NODE_ENV !== 'production'; |
| 22 | + |
| 23 | +var warning = function () {}; |
| 24 | + |
| 25 | +if (__DEV__) { |
| 26 | + warning = function(condition, format, ...args) { |
| 27 | + if (format === undefined) { |
| 28 | + throw new Error( |
| 29 | + '`warning(condition, format, ...args)` requires a warning ' + |
| 30 | + 'message argument' |
| 31 | + ); |
| 32 | + } |
| 33 | + |
| 34 | + if (format.length < 10 || /^[s\W]*$/.test(format)) { |
| 35 | + throw new Error( |
| 36 | + 'The warning format should be able to uniquely identify this ' + |
| 37 | + 'warning. Please, use a more descriptive format than: ' + format |
| 38 | + ); |
| 39 | + } |
| 40 | + |
| 41 | + if (format.indexOf('Failed Composite propType: ') === 0) { |
| 42 | + return; // Ignore CompositeComponent proptype check. |
| 43 | + } |
| 44 | + |
| 45 | + if (!condition) { |
| 46 | + var argIndex = 0; |
| 47 | + var message = 'Warning: ' + format.replace(/%s/g, () => args[argIndex++]); |
| 48 | + console.warn(message); |
| 49 | + try { |
| 50 | + // --- Welcome to debugging React --- |
| 51 | + // This error was thrown as a convenience so that you can use this stack |
| 52 | + // to find the callsite that caused this warning to fire. |
| 53 | + throw new Error(message); |
| 54 | + } catch(x) {} |
| 55 | + } |
| 56 | + }; |
| 57 | +} |
| 58 | + |
| 59 | +module.exports = warning; |
0 commit comments