import { fileURLToPath as _furl } from "node:url";
import { dirname as _dname } from "node:path";
_dname(_furl(import.meta.url));
import { NodeTypes } from "@vue/compiler-core";
import { parse } from "vue/compiler-sfc";
//#region packages/cli-lib/vue_extractor.ts
function walk(node, visitor) {
	if (typeof node !== "object" || node == null) return;
	if (node.type === NodeTypes.ROOT) {
		node.children.forEach((n) => walk(n, visitor));
		return;
	}
	if (node.type !== NodeTypes.ELEMENT && node.type !== NodeTypes.COMPOUND_EXPRESSION && node.type !== NodeTypes.INTERPOLATION) return;
	visitor(node);
	if (node.type === NodeTypes.INTERPOLATION) visitor(node.content);
	else if (node.type === NodeTypes.ELEMENT) {
		node.children.forEach((n) => walk(n, visitor));
		node.props.filter((prop) => prop.type === NodeTypes.DIRECTIVE).filter((prop) => !!prop.exp).forEach((prop) => visitor(prop.exp));
	} else node.children.forEach((n) => walk(n, visitor));
}
function templateSimpleExpressionNodeVisitor(parseScriptFn) {
	return (n) => {
		if (typeof n !== "object") return;
		if (n.type !== NodeTypes.SIMPLE_EXPRESSION) return;
		const { content } = n;
		try {
			parseScriptFn(`(${content})`);
		} catch (e) {
			console.warn(`Failed to parse "${content}". Ignore this if content has no extractable message`, e);
		}
	};
}
function parseFile(source, filename, parseScriptFn) {
	const { descriptor, errors } = parse(source, { filename });
	if (errors.length) throw errors[0];
	const { script, scriptSetup, template } = descriptor;
	if (template) walk(template.ast, templateSimpleExpressionNodeVisitor(parseScriptFn));
	if (script) parseScriptFn(script.content);
	if (scriptSetup) parseScriptFn(scriptSetup.content);
}
//#endregion
export { parseFile };

//# sourceMappingURL=vue_extractor-BcCeb_v6.js.map