{"version":3,"names":["_assert","require","Entry","exports","FunctionEntry","constructor","returnLoc","LoopEntry","breakLoc","continueLoc","label","SwitchEntry","TryEntry","firstLoc","catchEntry","finallyEntry","assert","ok","CatchEntry","paramId","FinallyEntry","afterLoc","LabeledEntry","LeapManager","emitter","entryStack","finalLoc","withEntry","entry","callback","push","call","popped","pop","strictEqual","_findLeapLocation","property","i","length","loc","name","getBreakLoc","getContinueLoc"],"sources":["../../src/regenerator/leap.ts"],"sourcesContent":["import assert from \"node:assert\";\nimport type { Emitter } from \"./emit.ts\";\nimport type { types as t } from \"@babel/core\";\n\nexport class Entry {}\n\nexport class FunctionEntry extends Entry {\n  returnLoc: t.NumericLiteral;\n\n  constructor(returnLoc: t.NumericLiteral) {\n    super();\n    this.returnLoc = returnLoc;\n  }\n}\n\nexport class LoopEntry extends Entry {\n  breakLoc: t.NumericLiteral;\n  continueLoc: t.NumericLiteral;\n  label: t.Identifier;\n\n  constructor(\n    breakLoc: t.NumericLiteral,\n    continueLoc: t.NumericLiteral,\n    label: t.Identifier = null,\n  ) {\n    super();\n    this.breakLoc = breakLoc;\n    this.continueLoc = continueLoc;\n    this.label = label;\n  }\n}\n\nexport class SwitchEntry extends Entry {\n  breakLoc: t.NumericLiteral;\n\n  constructor(breakLoc: t.NumericLiteral) {\n    super();\n    this.breakLoc = breakLoc;\n  }\n}\n\nexport class TryEntry extends Entry {\n  firstLoc: t.NumericLiteral;\n  catchEntry: CatchEntry;\n  finallyEntry: FinallyEntry;\n\n  constructor(\n    firstLoc: t.NumericLiteral,\n    catchEntry: CatchEntry | null = null,\n    finallyEntry: FinallyEntry | null = null,\n  ) {\n    super();\n    assert.ok(catchEntry || finallyEntry);\n    this.firstLoc = firstLoc;\n    this.catchEntry = catchEntry;\n    this.finallyEntry = finallyEntry;\n  }\n}\n\nexport class CatchEntry extends Entry {\n  firstLoc: t.NumericLiteral;\n  paramId: t.Identifier;\n\n  constructor(firstLoc: t.NumericLiteral, paramId: t.Identifier) {\n    super();\n    this.firstLoc = firstLoc;\n    this.paramId = paramId;\n  }\n}\n\nexport class FinallyEntry extends Entry {\n  firstLoc: t.NumericLiteral;\n  afterLoc: t.NumericLiteral;\n\n  constructor(firstLoc: t.NumericLiteral, afterLoc: t.NumericLiteral) {\n    super();\n    this.firstLoc = firstLoc;\n    this.afterLoc = afterLoc;\n  }\n}\n\nexport class LabeledEntry extends Entry {\n  breakLoc: t.NumericLiteral;\n  label: t.Identifier;\n\n  constructor(breakLoc: t.NumericLiteral, label: t.Identifier) {\n    super();\n    this.breakLoc = breakLoc;\n    this.label = label;\n  }\n}\n\nexport class LeapManager {\n  emitter: Emitter;\n  entryStack: Entry[];\n\n  constructor(emitter: Emitter) {\n    this.emitter = emitter;\n    this.entryStack = [new FunctionEntry(emitter.finalLoc)];\n  }\n\n  withEntry(entry: Entry, callback: any) {\n    this.entryStack.push(entry);\n    try {\n      callback.call(this.emitter);\n    } finally {\n      const popped = this.entryStack.pop();\n      assert.strictEqual(popped, entry);\n    }\n  }\n\n  _findLeapLocation(property: \"breakLoc\" | \"continueLoc\", label: t.Identifier) {\n    for (let i = this.entryStack.length - 1; i >= 0; --i) {\n      const entry = this.entryStack[i];\n      // @ts-expect-error Element implicitly has an 'any' type\n      const loc = entry[property] as t.NumericLiteral;\n      if (loc) {\n        if (label) {\n          // @ts-expect-error entry.label may not exist\n          if (entry.label && entry.label.name === label.name) {\n            return loc;\n          }\n        } else if (entry instanceof LabeledEntry) {\n          // Ignore LabeledEntry entries unless we are actually breaking to\n          // a label.\n        } else {\n          return loc;\n        }\n      }\n    }\n    return null;\n  }\n\n  getBreakLoc(label: t.Identifier) {\n    return this._findLeapLocation(\"breakLoc\", label);\n  }\n\n  getContinueLoc(label: t.Identifier) {\n    return this._findLeapLocation(\"continueLoc\", label);\n  }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAIO,MAAMC,KAAK,CAAC;AAAEC,OAAA,CAAAD,KAAA,GAAAA,KAAA;AAEd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