import { __exports as g } from "../../../../../../../_virtual/populate.js";
import { __require as b } from "../../../../../@babel_types@7.18.7/node_modules/@babel/types/lib/index.js";
Object.defineProperty(g, "__esModule", {
  value: !0
});
g.default = $;
var d = b();
const {
  blockStatement: A,
  cloneNode: h,
  emptyStatement: E,
  expressionStatement: u,
  identifier: n,
  isStatement: w,
  isStringLiteral: v,
  stringLiteral: _,
  validate: a
} = d;
function $(t, r) {
  const i = h(t.ast);
  return r && (t.placeholders.forEach((s) => {
    if (!Object.prototype.hasOwnProperty.call(r, s.name)) {
      const o = s.name;
      throw new Error(`Error: No substitution given for "${o}". If this is not meant to be a
            placeholder you may want to consider passing one of the following options to @babel/template:
            - { placeholderPattern: false, placeholderWhitelist: new Set(['${o}'])}
            - { placeholderPattern: /^${o}$/ }`);
    }
  }), Object.keys(r).forEach((s) => {
    if (!t.placeholderNames.has(s))
      throw new Error(`Unknown substitution "${s}" given`);
  })), t.placeholders.slice().reverse().forEach((s) => {
    try {
      S(s, i, r && r[s.name] || null);
    } catch (o) {
      throw o.message = `@babel/template placeholder "${s.name}": ${o.message}`, o;
    }
  }), i;
}
function S(t, r, i) {
  t.isDuplicate && (Array.isArray(i) ? i = i.map((f) => h(f)) : typeof i == "object" && (i = h(i)));
  const {
    parent: s,
    key: o,
    index: y
  } = t.resolve(r);
  if (t.type === "string") {
    if (typeof i == "string" && (i = _(i)), !i || !v(i))
      throw new Error("Expected string substitution");
  } else if (t.type === "statement")
    y === void 0 ? i ? Array.isArray(i) ? i = A(i) : typeof i == "string" ? i = u(n(i)) : w(i) || (i = u(i)) : i = E() : i && !Array.isArray(i) && (typeof i == "string" && (i = n(i)), w(i) || (i = u(i)));
  else if (t.type === "param") {
    if (typeof i == "string" && (i = n(i)), y === void 0)
      throw new Error("Assertion failure.");
  } else if (typeof i == "string" && (i = n(i)), Array.isArray(i))
    throw new Error("Cannot replace single expression with an array.");
  if (y === void 0)
    a(s, o, i), s[o] = i;
  else {
    const f = s[o].slice();
    t.type === "statement" || t.type === "param" ? i == null ? f.splice(y, 1) : Array.isArray(i) ? f.splice(y, 1, ...i) : f[y] = i : f[y] = i, a(s, o, f), s[o] = f;
  }
}
//# sourceMappingURL=populate.js.map
