"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/core/index.ts var _common = require('@vue-macros/common'); var _api = require('@vue-macros/api'); async function transformBetterDefine(code, id, isProduction) { const s = new (0, _common.MagicString)(code); const sfc = _common.parseSFC.call(void 0, code, id); if (!sfc.scriptSetup) return; const offset = sfc.scriptSetup.loc.start.offset; const result = await _api.analyzeSFC.call(void 0, s, sfc); if (result.props) { await processProps(result.props); } if (result.emits) { processEmits(result.emits); } return _common.getTransformResult.call(void 0, s, id); async function processProps(props) { const runtimeDefs = await props.getRuntimeDefinitions(); const runtimeDecls = `{ ${Object.entries(runtimeDefs).map(([key, { type, required, default: defaultDecl }]) => { const escapedKey = JSON.stringify(key); let defaultString = ""; if (defaultDecl) { defaultString = defaultDecl("default"); } if (!isProduction) { return `${escapedKey}: { type: ${_api.toRuntimeTypeString.call(void 0, type )}, required: ${required}, ${defaultString} }`; } else if (type.some((el) => el === "Boolean" || el === "Function")) { return `${escapedKey}: { type: ${_api.toRuntimeTypeString.call(void 0, type )}, ${defaultString} }`; } else { return `${escapedKey}: ${defaultString ? `{ ${defaultString} }` : "null"}`; } }).join(",\n ")} }`; let decl = runtimeDecls; if (props.withDefaultsAst && !props.defaults) { decl = `${_common.HELPER_PREFIX}mergeDefaults(${decl}, ${s.sliceNode( props.withDefaultsAst.arguments[1], { offset } )})`; _common.importHelperFn.call(void 0, s, offset, "mergeDefaults", "vue"); } decl = `defineProps(${decl})`; s.overwriteNode(props.withDefaultsAst || props.definePropsAst, decl, { offset }); } function processEmits(emits) { const runtimeDecls = `[${Object.keys(emits.definitions).map((name) => JSON.stringify(name)).join(", ")}]`; s.overwriteNode(emits.defineEmitsAst, `defineEmits(${runtimeDecls})`, { offset }); } } exports.transformBetterDefine = transformBetterDefine;