invariant.esm.js 2.4 KB

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