assert.js 746 B

12345678910111213141516171819202122232425262728
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.assertThrows = exports.assert = exports.assertNever = void 0;
  4. // this function can be used to ensure there are no missing cases in the handling of a union type
  5. function assertNever(x) {
  6. throw new Error(`Unexpected object: ${x}`);
  7. }
  8. exports.assertNever = assertNever;
  9. function assert(expression, msg) {
  10. if (!expression) {
  11. throw new Error(msg);
  12. }
  13. }
  14. exports.assert = assert;
  15. function assertThrows(callback, msg) {
  16. let threw = false;
  17. try {
  18. callback();
  19. }
  20. catch (e) {
  21. threw = true;
  22. }
  23. if (!threw) {
  24. throw new Error(msg);
  25. }
  26. }
  27. exports.assertThrows = assertThrows;
  28. //# sourceMappingURL=assert.js.map