import { __exports as _ } from "../../../../../../../../_virtual/cloneNode.js";
import { __require as O } from "../definitions/index.js";
import "../validators/generated/index.js";
import { __exports as A } from "../../../../../../../../_virtual/index35.js";
Object.defineProperty(_, "__esModule", {
  value: !0
});
_.default = I;
var p = O(), u = A;
const f = Function.call.bind(Object.prototype.hasOwnProperty);
function y(r, n, t, i) {
  return r && typeof r.type == "string" ? g(r, n, t, i) : r;
}
function m(r, n, t, i) {
  return Array.isArray(r) ? r.map((l) => y(l, n, t, i)) : y(r, n, t, i);
}
function I(r, n = !0, t = !1) {
  return g(r, n, t, /* @__PURE__ */ new Map());
}
function g(r, n = !0, t = !1, i) {
  if (!r)
    return r;
  const {
    type: l
  } = r, e = {
    type: r.type
  };
  if ((0, u.isIdentifier)(r))
    e.name = r.name, f(r, "optional") && typeof r.optional == "boolean" && (e.optional = r.optional), f(r, "typeAnnotation") && (e.typeAnnotation = n ? m(r.typeAnnotation, !0, t, i) : r.typeAnnotation);
  else if (f(p.NODE_FIELDS, l))
    for (const a of Object.keys(p.NODE_FIELDS[l]))
      f(r, a) && (n ? e[a] = (0, u.isFile)(r) && a === "comments" ? s(r.comments, n, t, i) : m(r[a], !0, t, i) : e[a] = r[a]);
  else
    throw new Error(`Unknown node type: "${l}"`);
  return f(r, "loc") && (t ? e.loc = null : e.loc = r.loc), f(r, "leadingComments") && (e.leadingComments = s(r.leadingComments, n, t, i)), f(r, "innerComments") && (e.innerComments = s(r.innerComments, n, t, i)), f(r, "trailingComments") && (e.trailingComments = s(r.trailingComments, n, t, i)), f(r, "extra") && (e.extra = Object.assign({}, r.extra)), e;
}
function s(r, n, t, i) {
  return !r || !n ? r : r.map((l) => {
    const e = i.get(l);
    if (e)
      return e;
    const {
      type: a,
      value: c,
      loc: N
    } = l, o = {
      type: a,
      value: c,
      loc: N
    };
    return t && (o.loc = null), i.set(l, o), o;
  });
}
//# sourceMappingURL=cloneNode.js.map
