warning.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /**
  2. * Copyright (c) 2014-present, Facebook, Inc.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. *
  7. */
  8. 'use strict';
  9. var emptyFunction = require("./emptyFunction");
  10. /**
  11. * Similar to invariant but only logs a warning if the condition is not met.
  12. * This can be used to log issues in development environments in critical
  13. * paths. Removing the logging code for production environments will keep the
  14. * same logic and follow the same code paths.
  15. */
  16. function printWarning(format) {
  17. for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  18. args[_key - 1] = arguments[_key];
  19. }
  20. var argIndex = 0;
  21. var message = 'Warning: ' + format.replace(/%s/g, function () {
  22. return args[argIndex++];
  23. });
  24. if (typeof console !== 'undefined') {
  25. console.error(message);
  26. }
  27. try {
  28. // --- Welcome to debugging React ---
  29. // This error was thrown as a convenience so that you can use this stack
  30. // to find the callsite that caused this warning to fire.
  31. throw new Error(message);
  32. } catch (x) {}
  33. }
  34. var warning = process.env.NODE_ENV !== "production" ? function (condition, format) {
  35. if (format === undefined) {
  36. throw new Error('`warning(condition, format, ...args)` requires a warning ' + 'message argument');
  37. }
  38. if (!condition) {
  39. for (var _len2 = arguments.length, args = new Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
  40. args[_key2 - 2] = arguments[_key2];
  41. }
  42. printWarning.apply(void 0, [format].concat(args));
  43. }
  44. } : emptyFunction;
  45. module.exports = warning;