leap.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.TryEntry = exports.SwitchEntry = exports.LoopEntry = exports.LeapManager = exports.LabeledEntry = exports.FunctionEntry = exports.FinallyEntry = exports.Entry = exports.CatchEntry = void 0;
  6. var _assert = require("assert");
  7. class Entry {}
  8. exports.Entry = Entry;
  9. class FunctionEntry extends Entry {
  10. constructor(returnLoc) {
  11. super();
  12. this.returnLoc = void 0;
  13. this.returnLoc = returnLoc;
  14. }
  15. }
  16. exports.FunctionEntry = FunctionEntry;
  17. class LoopEntry extends Entry {
  18. constructor(breakLoc, continueLoc, label = null) {
  19. super();
  20. this.breakLoc = void 0;
  21. this.continueLoc = void 0;
  22. this.label = void 0;
  23. this.breakLoc = breakLoc;
  24. this.continueLoc = continueLoc;
  25. this.label = label;
  26. }
  27. }
  28. exports.LoopEntry = LoopEntry;
  29. class SwitchEntry extends Entry {
  30. constructor(breakLoc) {
  31. super();
  32. this.breakLoc = void 0;
  33. this.breakLoc = breakLoc;
  34. }
  35. }
  36. exports.SwitchEntry = SwitchEntry;
  37. class TryEntry extends Entry {
  38. constructor(firstLoc, catchEntry = null, finallyEntry = null) {
  39. super();
  40. this.firstLoc = void 0;
  41. this.catchEntry = void 0;
  42. this.finallyEntry = void 0;
  43. _assert.ok(catchEntry || finallyEntry);
  44. this.firstLoc = firstLoc;
  45. this.catchEntry = catchEntry;
  46. this.finallyEntry = finallyEntry;
  47. }
  48. }
  49. exports.TryEntry = TryEntry;
  50. class CatchEntry extends Entry {
  51. constructor(firstLoc, paramId) {
  52. super();
  53. this.firstLoc = void 0;
  54. this.paramId = void 0;
  55. this.firstLoc = firstLoc;
  56. this.paramId = paramId;
  57. }
  58. }
  59. exports.CatchEntry = CatchEntry;
  60. class FinallyEntry extends Entry {
  61. constructor(firstLoc, afterLoc) {
  62. super();
  63. this.firstLoc = void 0;
  64. this.afterLoc = void 0;
  65. this.firstLoc = firstLoc;
  66. this.afterLoc = afterLoc;
  67. }
  68. }
  69. exports.FinallyEntry = FinallyEntry;
  70. class LabeledEntry extends Entry {
  71. constructor(breakLoc, label) {
  72. super();
  73. this.breakLoc = void 0;
  74. this.label = void 0;
  75. this.breakLoc = breakLoc;
  76. this.label = label;
  77. }
  78. }
  79. exports.LabeledEntry = LabeledEntry;
  80. class LeapManager {
  81. constructor(emitter) {
  82. this.emitter = void 0;
  83. this.entryStack = void 0;
  84. this.emitter = emitter;
  85. this.entryStack = [new FunctionEntry(emitter.finalLoc)];
  86. }
  87. withEntry(entry, callback) {
  88. this.entryStack.push(entry);
  89. try {
  90. callback.call(this.emitter);
  91. } finally {
  92. const popped = this.entryStack.pop();
  93. _assert.strictEqual(popped, entry);
  94. }
  95. }
  96. _findLeapLocation(property, label) {
  97. for (let i = this.entryStack.length - 1; i >= 0; --i) {
  98. const entry = this.entryStack[i];
  99. const loc = entry[property];
  100. if (loc) {
  101. if (label) {
  102. if (entry.label && entry.label.name === label.name) {
  103. return loc;
  104. }
  105. } else if (entry instanceof LabeledEntry) {} else {
  106. return loc;
  107. }
  108. }
  109. }
  110. return null;
  111. }
  112. getBreakLoc(label) {
  113. return this._findLeapLocation("breakLoc", label);
  114. }
  115. getContinueLoc(label) {
  116. return this._findLeapLocation("continueLoc", label);
  117. }
  118. }
  119. exports.LeapManager = LeapManager;
  120. //# sourceMappingURL=leap.js.map