import {
  MagicString,
  checkInvalidScopeReference,
  compileScript,
  filterMarco,
  parseSFC
} from "./chunk-CSOIUEGY.mjs";
import {
  DEFINE_OPTIONS_NAME,
  init_esm_shims
} from "./chunk-WNNTV2HR.mjs";

// src/core/transform.ts
init_esm_shims();
var transform = (code, id) => {
  const sfc = parseSFC(code, id);
  if (!sfc.scriptSetup)
    return;
  sfc.scriptSetup = compileScript(sfc, {
    id
  });
  const { script, scriptSetup, source } = sfc;
  const nodes = filterMarco(scriptSetup);
  if (nodes.length === 0)
    return;
  else if (nodes.length > 1)
    throw new SyntaxError(`duplicate ${DEFINE_OPTIONS_NAME}() call`);
  if (script)
    throw new SyntaxError(`${DEFINE_OPTIONS_NAME} cannot be used, with both script and script-setup.`);
  const node = nodes[0];
  const arg = node.arguments[0];
  if (!(node.arguments.length === 1 && arg.type === "ObjectExpression")) {
    throw new SyntaxError(`${DEFINE_OPTIONS_NAME}() arguments error`);
  }
  checkInvalidScopeReference(arg, DEFINE_OPTIONS_NAME, scriptSetup.bindings);
  const argLoc = arg.loc;
  const argText = scriptSetup.loc.source.slice(argLoc.start.index, argLoc.end.index);
  const s = new MagicString(source);
  s.prepend(`<script lang="${scriptSetup.attrs.lang || "js"}">
export default ${argText}<\/script>
`);
  s.remove(scriptSetup.loc.start.offset + node.loc.start.index, scriptSetup.loc.start.offset + node.loc.end.index);
  return {
    code: s.toString(),
    get map() {
      return s.generateMap({
        source: id,
        includeContent: true
      });
    }
  };
};

export {
  transform
};
//# sourceMappingURL=chunk-GURS3HNK.mjs.map