invariant.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var tslib = require('tslib');
  4. var genericMessage = "Invariant Violation";
  5. var _a = Object.setPrototypeOf, setPrototypeOf = _a === void 0 ? function (obj, proto) {
  6. obj.__proto__ = proto;
  7. return obj;
  8. } : _a;
  9. var InvariantError = /** @class */ (function (_super) {
  10. tslib.__extends(InvariantError, _super);
  11. function InvariantError(message) {
  12. if (message === void 0) { message = genericMessage; }
  13. var _this = _super.call(this, typeof message === "number"
  14. ? genericMessage + ": " + message + " (see https://github.com/apollographql/invariant-packages)"
  15. : message) || this;
  16. _this.framesToPop = 1;
  17. _this.name = genericMessage;
  18. setPrototypeOf(_this, InvariantError.prototype);
  19. return _this;
  20. }
  21. return InvariantError;
  22. }(Error));
  23. function invariant(condition, message) {
  24. if (!condition) {
  25. throw new InvariantError(message);
  26. }
  27. }
  28. function wrapConsoleMethod(method) {
  29. return function () {
  30. return console[method].apply(console, arguments);
  31. };
  32. }
  33. (function (invariant) {
  34. invariant.warn = wrapConsoleMethod("warn");
  35. invariant.error = wrapConsoleMethod("error");
  36. })(invariant || (invariant = {}));
  37. // Code that uses ts-invariant with rollup-plugin-invariant may want to
  38. // import this process stub to avoid errors evaluating process.env.NODE_ENV.
  39. // However, because most ESM-to-CJS compilers will rewrite the process import
  40. // as tsInvariant.process, which prevents proper replacement by minifiers, we
  41. // also attempt to define the stub globally when it is not already defined.
  42. exports.process = { env: {} };
  43. if (typeof process === "object") {
  44. exports.process = process;
  45. }
  46. else
  47. try {
  48. // Using Function to evaluate this assignment in global scope also escapes
  49. // the strict mode of the current module, thereby allowing the assignment.
  50. // Inspired by https://github.com/facebook/regenerator/pull/369.
  51. Function("stub", "process = stub")(exports.process);
  52. }
  53. catch (atLeastWeTried) {
  54. // The assignment can fail if a Content Security Policy heavy-handedly
  55. // forbids Function usage. In those environments, developers should take
  56. // extra care to replace process.env.NODE_ENV in their production builds,
  57. // or define an appropriate global.process polyfill.
  58. }
  59. var invariant$1 = invariant;
  60. exports.default = invariant$1;
  61. exports.InvariantError = InvariantError;
  62. exports.invariant = invariant;
  63. //# sourceMappingURL=invariant.js.map