// @ts-nocheck
if (!Symbol.dispose) {
  Object.defineProperty(Symbol, "dispose", {
    configurable: false,
    enumerable: false,
    writable: false,
    value: Symbol("Symbol.dispose"),
  })
}

if (!Symbol.asyncDispose) {
  Object.defineProperty(Symbol, "asyncDispose", {
    configurable: false,
    enumerable: false,
    writable: false,
    value: Symbol("Symbol.asyncDispose"),
  })
}

// node_modules/suppressed-error/polyfill.js
class SuppressedError extends Error {
  constructor(
    public error: any,
    public suppressed: any,
    message?: string,
  ) {
    super(message)
  }
}

// node_modules/es-abstract/2022/CompletionRecord.js
type CompletionRecordType = "normal" | "break" | "continue" | "return" | "throw"

class CompletionRecord<T = any> {
  #Type: CompletionRecordType
  #Value: T

  constructor(type: CompletionRecordType, value: T) {
    if (
      type !== "normal" &&
      type !== "break" &&
      type !== "continue" &&
      type !== "return" &&
      type !== "throw"
    ) {
      throw new SyntaxError(
        'Assertion failed: `type` must be one of "normal", "break", "continue", "return", or "throw"',
      )
    }
    this.#Type = type
    this.#Value = value
  }

  type() {
    return this.#Type
  }

  value() {
    return this.#Value
  }

  "?"() {
    const type = this.#Type
    const value = this.#Value
    if (type === "normal") {
      return value
    }
    if (type === "throw") {
      throw value
    }
    throw new SyntaxError(
      'Completion Record is not of type "normal" or "throw": other types not supported',
    )
  }

  "!"() {
    const type = this.#Type
    if (type !== "normal") {
      throw new SyntaxError('Assertion failed: Completion Record is not of type "normal"')
    }
    return this.#Value
  }
}

// node_modules/es-abstract/2022/NormalCompletion.js
function normalCompletion(value?: unknown) {
  return new CompletionRecord("normal", value)
}

const enum Hint {
  SyncDispose,
  AsyncDispose,
}

// node_modules/disposablestack/aos/GetDisposeMethod.js
function GetDisposeMethod(V: unknown, hint: Hint): () => unknown {
  if (typeof V !== "object") {
    throw new TypeError("`V` must be an Object")
  }
  let method
  if (hint === Hint.AsyncDispose && Symbol.asyncDispose) {
    method = (V as AsyncDisposable)[Symbol.asyncDispose]
  }
  if (!method) {
    method = (V as Disposable)[Symbol.dispose]
  }
  return method
}

// node_modules/disposablestack/aos/CreateDisposableResource.js
type DisposableResource = ReturnType<typeof createDisposableResource>

function createDisposableResource(V: unknown, hint: Hint, method?: () => unknown) {
  if (typeof V !== "undefined" && typeof V !== "object") {
    throw new TypeError("`V` must be an Object")
  }
  if (arguments.length < 3) {
    if (typeof V === "undefined") {
      throw new TypeError("`V` must not be `undefined` when `method` is not provided")
    }
    method = GetDisposeMethod(V, hint)
    if (typeof method === "undefined") {
      throw new TypeError(
        "dispose method must not be `undefined` on `V` when an object `V` is provided",
      )
    }
  } else if (typeof method !== "function") {
    throw new TypeError("`method`, when provided, must be a function")
  }
  return {
    // step 3
    "[[ResourceValue]]": V,
    "[[Hint]]": hint,
    "[[DisposeMethod]]": method,
  }
}

// node_modules/disposablestack/aos/AddDisposableResource.js
function addDisposableResource(
  disposeCapability: DisposeCapability,
  V: unknown,
  hint: Hint,
  method?: () => unknown,
) {
  let resource
  if (arguments.length < 4) {
    if (V == null) {
      return "unused"
    }
    if (typeof V !== "object") {
      throw new TypeError("`V` must be an Object")
    }
    resource = createDisposableResource(V, hint)
  } else {
    if (typeof V !== "undefined") {
      throw new TypeError(
        "Assertion failed: `V` must be undefined when `method` is present",
      )
    }
    resource = createDisposableResource(undefined, hint, method)
  }
  disposeCapability["[[DisposableResourceStack]]"].push(resource)
  return "unused"
}

// node_modules/disposablestack/aos/Dispose.js
function dispose(V: unknown, hint: Hint, method: () => unknown) {
  if (typeof V !== "undefined" && typeof V !== "object") {
    throw new SyntaxError("Assertion failed: `V` must be `undefined` or an Object")
  }
  if (typeof method !== "undefined" && typeof method !== "function") {
    throw new SyntaxError("Assertion failed: `method` must be `undefined` or a function")
  }
  const result = Reflect.apply(method, V, [])
  if (hint === Hint.AsyncDispose) {
    return Promise.resolve(result)
  }
}

// node_modules/es-abstract/2022/ThrowCompletion.js
function throwCompletion(argument: unknown) {
  return new CompletionRecord("throw", argument)
}

// node_modules/disposablestack/aos/DisposeResources.js
function disposeResources(
  disposeCapability: DisposeCapability,
  completion: CompletionRecord,
) {
  if (!(completion instanceof CompletionRecord)) {
    throw new TypeError("`completion` must be a Completion Record")
  }
  const stack = disposeCapability["[[DisposableResourceStack]]"]
  let actualHint
  for (let j = stack.length - 1; j >= 0; j -= 1) {
    if (!actualHint) {
      actualHint = stack[j]["[[Hint]]"]
    } else if (actualHint !== stack[j]["[[Hint]]"]) {
      throw new SyntaxError("mixed hint stacks are not supported")
    }
  }
  let promise = actualHint === Hint.AsyncDispose && Promise.resolve(completion)
  const rejecter = function (e: Error) {
    if (completion.type() === "throw") {
      const suppressed = completion.value()
      const error = new SuppressedError(e, suppressed)
      completion = throwCompletion(error)
    } else {
      completion = throwCompletion(e)
    }
  }
  const getPromise = function getPromise2(resource: DisposableResource) {
    return (promise as Promise<any>).then(() => {
      const result = dispose(
        // step 1.a
        resource["[[ResourceValue]]"],
        resource["[[Hint]]"],
        resource["[[DisposeMethod]]"],
      )
      if (!result) {
        throw new SyntaxError(
          "Assertion failed: non-`async-dispose` resource returned a promise from Dispose",
        )
      }
      return result.then(normalCompletion)
    }, rejecter)
  }
  for (let i = stack.length - 1; i >= 0; i -= 1) {
    if (actualHint === Hint.AsyncDispose) {
      promise = getPromise(stack[i]) as Promise<CompletionRecord>
    } else {
      const resource = stack[i]
      try {
        const result = dispose(
          // step 1.a
          resource["[[ResourceValue]]"],
          resource["[[Hint]]"],
          resource["[[DisposeMethod]]"],
        )
        if (result) {
          throw new SyntaxError(
            "Assertion failed: `sync-dispose` resource returned something from Dispose",
          )
        }
      } catch (e) {
        rejecter(e)
      }
    }
  }
  return actualHint === Hint.AsyncDispose
    ? (promise as Promise<CompletionRecord>)
    : completion
}

// node_modules/disposablestack/aos/NewDisposeCapability.js
type DisposeCapability = ReturnType<typeof newDisposeCapability>
function newDisposeCapability() {
  return { "[[DisposableResourceStack]]": [] as DisposableResource[] }
}

// node_modules/disposablestack/DisposableStack/implementation.js
class DisposableStack {
  #DisposableState = "pending"
  #DisposeCapability = newDisposeCapability()

  get disposed() {
    return this.#DisposableState === "disposed"
  }

  dispose(): void {
    if (this.disposed) return
    this.#markDisposed()
    return disposeResources(this.#DisposeCapability, normalCompletion())["?"]()
  }

  use<T extends Disposable | null | undefined>(value: T): T {
    if (this.disposed) {
      throw new ReferenceError("a disposed stack cannot use anything new")
    }
    addDisposableResource(this.#DisposeCapability, value, Hint.SyncDispose)
    return value
  }

  adopt<T>(value: T, onDispose: (value: T) => void): T {
    if (this.disposed) {
      throw new ReferenceError("a disposed stack cannot use anything new")
    }
    if (typeof onDispose !== "function") {
      throw new TypeError("`onDispose` must be a function")
    }
    addDisposableResource(this.#DisposeCapability, undefined, Hint.SyncDispose, () =>
      onDispose(value),
    )
    return value
  }

  defer(onDispose: () => void): void {
    if (this.disposed) {
      throw new ReferenceError("a disposed stack cannot defer anything new")
    }
    if (typeof onDispose !== "function") {
      throw new TypeError("`onDispose` must be a function")
    }
    addDisposableResource(this.#DisposeCapability, undefined, Hint.SyncDispose, onDispose)
  }

  move(): DisposableStack {
    if (this.disposed) {
      throw new ReferenceError("a disposed stack cannot use anything new")
    }
    const newDisposableStack = new DisposableStack()
    newDisposableStack.#DisposeCapability = this.#DisposeCapability
    this.#DisposeCapability = newDisposeCapability()
    this.#markDisposed()
    return newDisposableStack
  }

  #markDisposed() {
    this.#DisposableState = "disposed"
  }

  [Symbol.dispose]() {
    this.dispose()
  }
}

// node_modules/disposablestack/AsyncDisposableStack/implementation.js
class AsyncDisposableStack implements AsyncDisposableStack {
  #AsyncDisposableState = "pending"
  #DisposeCapability = newDisposeCapability()

  get disposed() {
    return this.#AsyncDisposableState === "disposed"
  }

  #markDisposed() {
    this.#AsyncDisposableState = "disposed"
  }

  async disposeAsync(): Promise<void> {
    if (this.disposed) {
      return Promise.resolve()
    }
    this.#markDisposed()
    const completion = await Promise.resolve(
      disposeResources(this.#DisposeCapability, normalCompletion()),
    )
    return completion["?"]()
  }

  use<T extends AsyncDisposable | Disposable | null | undefined>(value: T): T {
    if (this.disposed) {
      throw new ReferenceError("a disposed stack cannot use anything new")
    }
    addDisposableResource(this.#DisposeCapability, value, Hint.AsyncDispose)
    return value
  }

  adopt<T>(value: T, onDisposeAsync: (value: T) => PromiseLike<void> | void): T {
    if (this.disposed) {
      throw new ReferenceError("a disposed stack cannot use anything new")
    }
    if (typeof onDisposeAsync !== "function") {
      throw new TypeError("`onDisposeAsync` must be a function")
    }
    const F = () => onDisposeAsync(value)
    F.value = value
    addDisposableResource(this.#DisposeCapability, undefined, Hint.AsyncDispose, F)
    return value
  }

  defer(onDisposeAsync: () => PromiseLike<void> | void): void {
    if (this.disposed) {
      throw new ReferenceError("a disposed stack cannot defer anything new")
    }
    if (typeof onDisposeAsync !== "function") {
      throw new TypeError("`onDispose` must be a function")
    }
    addDisposableResource(
      this.#DisposeCapability,
      undefined,
      Hint.AsyncDispose,
      onDisposeAsync,
    )
  }

  move(): AsyncDisposableStack {
    if (this.disposed) {
      throw new ReferenceError("a disposed stack cannot use anything new")
    }
    const newAsyncDisposableStack = new AsyncDisposableStack()
    newAsyncDisposableStack.#DisposeCapability = this.#DisposeCapability
    this.#DisposeCapability = newDisposeCapability()
    this.#markDisposed()
    return newAsyncDisposableStack
  }

  [Symbol.asyncDispose](): Promise<void> {
    return this.disposeAsync()
  }
}

// node_modules/disposablestack/AsyncDisposableStack/polyfill.js

// node_modules/disposablestack/AsyncDisposableStack/shim.js

// node_modules/disposablestack/auto.js
;(globalThis as any).SuppressedError ??= SuppressedError
;(globalThis as any).DisposableStack ??= DisposableStack
;(globalThis as any).AsyncDisposableStack ??= AsyncDisposableStack

export {}
