import { __exports as d } from "../../../../../../../_virtual/parse.js";
import { __require as f } from "../../../../../@babel_types@7.18.7/node_modules/@babel/types/lib/index.js";
import "../../../../../@babel_parser@7.18.6/node_modules/@babel/parser/lib/index.js";
import "../../../../../@babel_code-frame@7.18.6/node_modules/@babel/code-frame/lib/index.js";
import { __exports as m } from "../../../../../../../_virtual/index4.js";
import { __exports as y } from "../../../../../../../_virtual/index39.js";
Object.defineProperty(d, "__esModule", {
  value: !0
});
d.default = W;
var g = f(), v = m, _ = y;
const {
  isCallExpression: P,
  isExpressionStatement: R,
  isFunction: L,
  isIdentifier: w,
  isJSXIdentifier: E,
  isNewExpression: x,
  isPlaceholder: p,
  isStatement: S,
  isStringLiteral: h,
  removePropertiesDeep: b,
  traverse: A
} = g, N = /^[_$A-Z0-9]+$/;
function W(l, r, e) {
  const {
    placeholderWhitelist: s,
    placeholderPattern: i,
    preserveComments: t,
    syntacticPlaceholders: c
  } = e, a = C(r, e.parser, c);
  b(a, {
    preserveComments: t
  }), l.validate(a);
  const o = {
    placeholders: [],
    placeholderNames: /* @__PURE__ */ new Set()
  }, n = {
    placeholders: [],
    placeholderNames: /* @__PURE__ */ new Set()
  }, u = {
    value: void 0
  };
  return A(a, F, {
    syntactic: o,
    legacy: n,
    isLegacyRef: u,
    placeholderWhitelist: s,
    placeholderPattern: i,
    syntacticPlaceholders: c
  }), Object.assign({
    ast: a
  }, u.value ? n : o);
}
function F(l, r, e) {
  var s;
  let i;
  if (p(l)) {
    if (e.syntacticPlaceholders === !1)
      throw new Error("%%foo%%-style placeholders can't be used when '.syntacticPlaceholders' is false.");
    i = l.name.name, e.isLegacyRef.value = !1;
  } else {
    if (e.isLegacyRef.value === !1 || e.syntacticPlaceholders)
      return;
    if (w(l) || E(l))
      i = l.name, e.isLegacyRef.value = !0;
    else if (h(l))
      i = l.value, e.isLegacyRef.value = !0;
    else
      return;
  }
  if (!e.isLegacyRef.value && (e.placeholderPattern != null || e.placeholderWhitelist != null))
    throw new Error("'.placeholderWhitelist' and '.placeholderPattern' aren't compatible with '.syntacticPlaceholders: true'");
  if (e.isLegacyRef.value && (e.placeholderPattern === !1 || !(e.placeholderPattern || N).test(i)) && !((s = e.placeholderWhitelist) != null && s.has(i)))
    return;
  r = r.slice();
  const {
    node: t,
    key: c
  } = r[r.length - 1];
  let a;
  h(l) || p(l, {
    expectedNode: "StringLiteral"
  }) ? a = "string" : x(t) && c === "arguments" || P(t) && c === "arguments" || L(t) && c === "params" ? a = "param" : R(t) && !p(l) ? (a = "statement", r = r.slice(0, -1)) : S(l) && p(l) ? a = "statement" : a = "other";
  const {
    placeholders: o,
    placeholderNames: n
  } = e.isLegacyRef.value ? e.legacy : e.syntactic;
  o.push({
    name: i,
    type: a,
    resolve: (u) => T(u, r),
    isDuplicate: n.has(i)
  }), n.add(i);
}
function T(l, r) {
  let e = l;
  for (let t = 0; t < r.length - 1; t++) {
    const {
      key: c,
      index: a
    } = r[t];
    a === void 0 ? e = e[c] : e = e[c][a];
  }
  const {
    key: s,
    index: i
  } = r[r.length - 1];
  return {
    parent: e,
    key: s,
    index: i
  };
}
function C(l, r, e) {
  const s = (r.plugins || []).slice();
  e !== !1 && s.push("placeholders"), r = Object.assign({
    allowReturnOutsideFunction: !0,
    allowSuperOutsideMethod: !0,
    sourceType: "module"
  }, r, {
    plugins: s
  });
  try {
    return (0, v.parse)(l, r);
  } catch (i) {
    const t = i.loc;
    throw t && (i.message += `
` + (0, _.codeFrameColumns)(l, {
      start: t
    }), i.code = "BABEL_TEMPLATE_PARSE_ERROR"), i;
  }
}
//# sourceMappingURL=parse.js.map
