import { GeneratorOptions as GeneratorOptions$1 } from '@babel/generator'; import { ParseResult as ParseResult$1 } from '@babel/parser'; import * as t from '@babel/types'; import { SourceLocation, Expression, ArrayExpression, JSXIdentifier } from '@babel/types'; import { RootNode, SourceLocation as SourceLocation$1 } from '@vue/compiler-core'; import { SFCTemplateBlock, SFCScriptBlock, SFCStyleBlock } from '@vue/compiler-sfc'; import { Options } from 'prettier'; interface FileLockOptions { /** * 锁过期时间(毫秒) * 默认: 10000 (10秒) */ stale?: number; /** * 锁更新间隔(毫秒) * 默认: stale / 2 */ update?: number; /** * 重试配置 * 可以是重试次数或 retry 选项对象 * 默认: 5 */ retries?: number | { retries?: number; factor?: number; minTimeout?: number; maxTimeout?: number; randomize?: boolean; }; /** * 是否解析符号链接 * 默认: true */ realpath?: boolean; /** * 自定义锁文件路径 * 默认: `${filePath}.lock` */ lockfilePath?: string; } type CompilationUnit = SFCUnit | ScriptUnit | StyleUnit; interface SFCUnit extends BaseUnit { type: CacheKey.SFC; output?: { jsx: OutputItem; css: Partial; }; } interface ScriptUnit extends BaseUnit { type: CacheKey.SCRIPT; output?: { script: OutputItem; }; } interface StyleUnit extends Omit { type: CacheKey.STYLE; output?: { style: OutputItem; }; } interface AssetUnit extends Omit { type: CacheKey.ASSET; } interface BaseUnit extends FileMeta { file: string; fileId: string; source: string; hasRoute?: boolean; } interface OutputItem { file: string; code: string; } type CacheMap = Record; type LoadedCache = { key: CacheKey; target: T[]; source: CacheList; }; type CacheMeta = Vue2ReactCacheMeta | FileCacheMeta; declare enum CacheKey { SFC = "sfc", SCRIPT = "script", STYLE = "style", ASSET = "copied" } interface CacheList { [CacheKey.SFC]: Vue2ReactCacheMeta[]; [CacheKey.SCRIPT]: ScriptCacheMeta[]; [CacheKey.STYLE]: StyleCacheMeta[]; [CacheKey.ASSET]: FileCacheMeta[]; } type Vue2ReactCacheMeta = Omit; type ScriptCacheMeta = Omit; type StyleCacheMeta = Omit; interface FileCacheMeta extends FileMeta { file: string; } interface FileMeta { fileSize: number; mtime: number; hash?: string; } interface CacheCheckResult { shouldCompile: boolean; hash?: string; } type CompilationResult = SFCCompilationResult | ScriptCompilationResult | StyleCompilationResult; interface SFCCompilationResult extends BaseCompilationResult { fileInfo: { jsx: { file: string; lang: string; }; css: { file?: string; hash?: string; code?: string; }; }; } interface ScriptCompilationResult extends BaseCompilationResult { fileInfo: { script: { file: string; lang: string; }; }; } interface StyleCompilationResult extends Omit { code: string; fileInfo: { style: { file: string; lang: string; }; }; } interface BaseCompilationResult extends GeneratorResult { fileId: string; hasRoute?: boolean; } type LangType = 'js' | 'jsx' | 'ts' | 'tsx'; type ReactiveTypes = 'ref' | 'reactive' | 'indirect' | 'none'; interface ICompilationContext { fileId: string; source: string; filename: string; imports: Map; cssVars: string[]; inputType: FileInputType; /** * 函数组件的 prop 参数名 * @default 'props' */ propField: string; /** 是否使用了路由 */ route?: boolean; /** 是否将 Less / Sass 样式语言处理为 CSS */ preprocessStyles?: boolean; templateData: { lang?: string; /** 用于描述 `` / `` */ slots: Record; /** 收集模板 ref 对应的 script 绑定元数据 */ refBindings: { /** 普通 html 元素的 ref */ domRefs: RefBindings; /** 组件的 ref */ componentRefs: RefBindings; }; /** 收集所有模板中的响应式变量,其来自 script 的绑定元数据 */ reactiveBindings: ReactiveBindinds; /** defineProps 中声明的属性名 */ declaredProps: Set; /** defineEmits 中声明的事件名 */ declaredEmits: Set; /** useAttrs 的变量声明名 */ declaredAttrs?: string; }; scriptData: { lang: LangType; /** 用于收集 Vue 的 `provide(name, value)` */ provide: ProvideData; /** 组件 props ts 接口集合 */ propsTSIface: IPropsContext; /** script 源码 */ source: string; /** 检测 useAttrs() 调用是否存在 */ hasUseAttrsCall?: boolean; /** 是否需要 forwardRef 包装组件 */ forwardRef: { enabled: boolean; /** * forwardRef 函数的第二个参数名 * @default 'expose' */ refField: string; }; /** defineOptions 中声明的选项 */ declaredOptions: { name?: string; inheritAttrs?: boolean; }; /** withDefaults 中的默认值 */ propsWithDefaults?: PropsWithDefaults; /** * 使用时手动类型断言为 `ScriptBlockIR` */ __vureact_script_block_ir: any; }; styleData: { filePath: string; /** style module 的名称 */ moduleName?: string; /** style scoped 对应 id */ scopeId?: string; }; } type ImportItem = { name: string; onDemand: boolean; }; type FileInputType = 'sfc' | 'script-js' | 'script-ts' | 'style' | 'unknow'; interface SlotNodesContext { name: string; isScope: boolean; props: { prop: string; value: string; tsType: t.TSTypeAnnotation; }[]; } interface ReactiveBindinds { [name: string]: { name: string; value: t.Expression; source: string; reactiveType: ReactiveTypes; }; } interface RefBindings { [name: string]: { tag: string; name: string; htmlType: string; }; } interface ProvideData { name: string; value: string; isOccupied: boolean; provide: ProvideData | Record; } interface IPropsContext { /** * props 接口名称 */ name: string; /** * 标记为疑似有 props 但是在 js 环境下 */ hasPropsInJsEnv?: boolean; /** * 用于记录源码中对应 API 的 ts 类型 * * 1.推导出的属性元数据,如 (defineProps(['foo', 'bar'])) * 记录 key 和对应的类型(默认为 any/String 等) * * 2.显式定义的 TS 类型节点,如 (defineProps<{...}>) */ propsTypes: t.TSType[]; emitTypes: t.TSType[]; slotTypes: t.TSType[]; } interface PropsWithDefaults { varName: string; values: t.Expression | undefined; /** 收集 defineProps 的类型参数 */ typeParameters?: t.TSTypeParameterInstantiation | null; /** 原 withDefaults 调用的 babel 位置信息,用于 postprocess 阶段定位替换 */ leadingComments?: t.Comment[] | null; innerComments?: t.Comment[] | null; trailingComments?: t.Comment[] | null; start?: number | null; end?: number | null; loc?: SourceLocation | null; } type CompilerPlugins = PluginRegister & { /** * Register parser plugins */ parser?: PluginRegister; /** * Register transformer plugins */ transformer?: PluginRegister; /** * Register codegen plugins */ codegen?: PluginRegister; }; interface PluginRegister { [name: string]: (result: T, ctx: ICompilationContext) => void; } interface CompilerOptions { /** * Manually specify the root directory. * @default process.cwd() */ root?: string; /** * Path to the source file or directory. * - If it is a file, compile the single file. * - If it is a directory, recursively compile all .vue files under the directory. * * @default * 'src/' // The src directory under the root directory */ input?: string; /** * Whether to enable build cache and reuse the previous cache results * @default true */ cache?: boolean; /** * @see {@link OutputConfig} */ output?: OutputConfig; /** * Excluded file/directory matching patterns (glob syntax supported). * @default * [ * 'node_modules/**', * 'dist/**', * 'build/**', * '.git/**', * '.vureact/**' * ] */ exclude?: string[]; /** * Whether to recursively search subdirectories. * @default true */ recursive?: boolean; /** * Options passed through to babel-generator. * @see {@link GeneratorOptions} */ generate?: GeneratorOptions$1; /** * Watch files in real time and auto-recompile on changes. * @default false */ watch?: boolean; /** * Whether to process Less/Sass style languages into CSS * @default true */ preprocessStyles?: boolean; /** * Specify the path to the Vue Router config file * The file must default export createRouter * Used to inject Router Provider in React's main.tsx or main.jsx * * * * @see {@link RouterConfig} * * @example * ```js * router: { * configFile: 'src/router/index.ts' * } * ``` * * Assumes the config file default exports createRouter: * * ```js * // src/router/index.ts * export default createRouter({ ... }) * ``` */ router?: RouterConfig; /** * Can be used to add plugins and customize the output results of * the parse/transform/codegen/compiled stages respectively. * * @see {@link CompilerPlugins} * * @example * ```ts * plugins: { * // For example, add custom data to the parsing results. * parser: { * myPlugin: (result, ctx) => { * result.metadata = { * timestamp: Date.now() * } * }, * }, * * // If the key names parse/transform/codegen are not specified, * // the plugin will execute upon completion of compilation. * yourPlguin: (result) => { * console.log(result) * } * } * ``` */ plugins?: CompilerPlugins; /** * @see {@link FormatConfig} */ format?: FormatConfig; /** * Log Control Options * @see {@link LoggingConfig} */ logging?: LoggingConfig; /** * Execute only after the first successful full compilation. */ onSuccess?: () => Promise; /** * Execute after file are added or recompiled in `watch` mode. * * @param event Add or modify file * @param unit Current sfc or script file compilation unit */ onChange?: (event: 'add' | 'change', unit: CompilationUnit) => Promise; } interface OutputConfig { /** * Output the name of the root directory corresponding to the file's location. * @default '.vureact' */ workspace?: string; /** * Output directory name, relative to `output.workspace` * @default 'dist' */ outDir?: string; /** * Whether to automatically call Vite to initialize a standard * React project environment before compilation. * @default true */ bootstrapVite?: boolean | { /** * Specify the React template type. * @default 'react-ts' */ template?: 'react-ts' | 'react'; /** * Specify the Vite version for initial installation, which must start with '@'. * @default '@latest' * * @example * * ```js * { vite: '@7' } * ``` */ vite?: string; /** * Specify the React version for initial installation. * @default 'latest' * * @example * * ```js * { react: '^19.2.0' } * ``` */ react?: string; }; /** * Specify asset files that do not need to be copied. * They can be filenames or paths, using fuzzy matching. * @default * [ * 'package.json', * 'package-lock.json', * 'pnpm-lock.yaml', * 'index.html', * 'tsconfig.', * 'vite.config.', * 'eslint.config.', * 'readme.', * 'vue.', * '.vue', * 'vureact.config.js', * 'vureact.config.ts', * ] */ ignoreAssets?: string[]; /** * Customize the generated package.json file. * This function receives the default package.json object * and should return the modified version. * * @note This option only takes effect when `bootstrapVite` is enabled. * * @example * ```js * packageJson: (defaultPkg) => { * // Modify and return the copy * defaultPkg.dependencies['my-library'] = '^1.0.0'; * return defaultPkg; * } * ``` */ packageJson?: (defaultPkg: Record) => Record; } interface RouterConfig { /** * Path to the Vue Router config file. * Must be the location where `createRouter` is **exported as default**. */ configFile: string; /** * Automatically update the react app entry file to use the VuReact Router Provider. * * Note: Injection only occurs when `output.bootstrapVite` is enabled. * * @default true */ autoUpdateEntry?: boolean; } interface FormatConfig { /** * @default false */ enabled?: boolean; /** * @default 'prettier' */ formatter?: 'prettier' | 'builtin'; /** * Configure the formatting options for Prettier, * which takes effect only when the formatter is set to 'prettier'. */ prettierOptions?: Options; } interface LoggingConfig { /** * @default true */ enabled?: boolean; /** Whether to output warning messages. */ warnings?: boolean; /** Whether to output info messages. */ info?: boolean; /** Whether to output error messages. */ errors?: boolean; } declare class Helper { private compilerOpts; private pathFilter; private workspaceDir; private outDir; constructor(opts: CompilerOptions); /** * 获取用户的项目根目录 */ getProjectRoot(): string; /** * 获取输入文件的路径 */ getInputPath(): string; /** * 获取输出文件的路径。如:'[root]/.vureact/dist/' * @param addInput 会输出如:'[root]/.vureact/dist/[input]/' */ getOuputPath(addInput?: boolean): string; getOutDirName(): string; getWorkspaceDir(): string; /** * 根据相对输出路径反推源文件路径 */ getSourcePath(outputPath: string): string; getIgnoreAssets(): Set; getIsCache(): boolean; /** * 返回原始目录下的 package.json 路径 */ getRootPkgPath(): string; /** * 返回 output 的 package.json 路径 */ getOutputPkgPath(): string; /** * 获取缓存文件路径 */ getCachePath(): string; /** * 返回文件相对工作区的路径 */ relativePath(filePath: string): string; /** * 替换 .vue 文件名后缀为 .jsx/.tsx * @param filePath 文件完整路径 * @param ext 文件拓展名 * @returns 返回文件的相对路径,不包含当前工作区路径 */ replaceVueFileExt(filePath: string, ext: string): string; /** * 判断是否应该跳过不需要进行文件搜索的路径 */ shouldSkipPath(filePath: string): boolean; /** * 自动根据项目结构推导 react-app 目录下的对应位置 */ resolveOutputPath(filePath: string, extname?: string): string; /** * 格式化代码 */ formatCode({ code, fileInfo }: CompilationResult): Promise; /** * 通用的缓存校验工具函数 * @param current 当前文件元数据 * @param cached 缓存中的旧数据 * @param getSource 获取文件内容的函数(仅在元数据不一致时才调用,避免多余 I/O) */ checkCacheStatus(current: FileMeta, cached: CacheMeta | undefined, getSource: () => Promise): Promise; /** * 对比相同两个文件的基础元数据 */ compareFileMeta(a: FileMeta, b: FileMeta): boolean; /** * 统一的写文件方法,包含自动创建目录(带文件互斥锁可选) * @param filePath - 要写入的文件路径 * @param content - 要写入的内容 * @param options - 可选配置项 * @param options.lock - 是否启用文件锁(默认false) */ writeFileWithDir(filePath: string, content: string, options?: FileLockOptions & { lock?: boolean; }): Promise; rmFile(filePath: string): Promise; genHash(content: string): string; getAbsPath(filePath: string): string; getFileMeta(filePath: string): Promise; removeOutputFile(filePath: string, resolveOutputPath?: boolean): Promise; updateCache(targetFile: string, newData: any, cache: LoadedCache): void; /** * 获取需要排除编译的文件 */ getExcludes(): string[]; /** * 打印 core 模块执行过程中收集的日志 */ printCoreLogs(): void; print(...message: any[]): void; /** * 读取 package.json 文件内容,并处理成对象返回 */ resolvePackageFile(path: string): Promise>; /** * 获取目录到文件的相对路径 * @returns 结果路径不包含文件拓展名,并以诸如 ./ 开头 */ resolveRelativePath(from: string, to: string): string; } /** * 基础编译器类 - Vue 到 React 代码转换的核心实现 * * 继承自 Helper,提供单文件编译功能,支持插件系统和三阶段编译流程。 * 主要用于文件系统批量编译和单文件编译场景。 */ declare class BaseCompiler extends Helper { version: string; options: CompilerOptions; private createContext; constructor(options?: CompilerOptions); /** 编译 Vue 源代码为 React 代码 */ compile(source: string, filename: string): CompilationResult; private prepareGenerateOptions; private resolveMainResult; private resolveStyleResult; } declare class CacheManager { private fileCompiler; private pendingUpdates; /** 缓存文件仅读取一次,之后复用此副本 */ private cachedData; constructor(fileCompiler: FileCompiler); /** * 批量更新缓存记录 */ updateCacheIncrementally(unit: CompilationUnit, key: CacheKey): Promise; /** * 一次性刷新所有缓存(只写一次文件) */ flushAllCache(): Promise; /** * 一次性加载所有缓存(只读一次文件) */ loadAllCache(): Promise; /** * 加载指定类型的缓存(watch 等场景使用) */ loadCache(key: CacheKey): Promise; /** * 刷新指定 key 的缓存(统一由 flushAllCache 写入,此方法仅用于外部兼容调用) */ flushCache(key: CacheKey): Promise; private getEmptyList; /** * 保存缓存数据到文件(watch 等场景使用) */ saveCache(data: LoadedCache): Promise; private buildLoadedCache; } declare class CleanupManager { private fileCompiler; private cacheManager; constructor(fileCompiler: FileCompiler, cacheManager: CacheManager); /** * 删除指定路径对应的构建产物和缓存 */ removeOutputPath(targetPath: string, type: CacheKey): Promise; /** * 删除匹配的输出文件,并从内存缓存中移除对应条目(不写磁盘) */ removeMatchedFromCache(key: CacheKey, cache: LoadedCache, filter: (m: CacheMeta) => boolean): Promise; /** * 删除单个缓存元数据对应的输出文件(不操作缓存) */ removeCacheMeta(key: CacheKey, meta: CacheMeta): Promise; } declare class AssetManager { private fileCompiler; private cleanupManager; private cacheManager; pipelineFiles: string[]; private skippedCount; constructor(fileCompiler: FileCompiler, cleanupManager: CleanupManager, cacheManager: CacheManager); /** * 运行资源文件处理管线 */ runAsset(files: string[], cacheMap: CacheMap): Promise; /** * Process single asset file, compare with cache and decide whether to copy. */ processAsset(filePath: string, existingCache?: LoadedCache): Promise; /** * 更新缓存 */ private updateCache; /** * 获取跳过的文件数量 */ getSkippedCount(): number; /** * 重置跳过的文件数量 */ resetSkippedCount(): void; } declare class CompilationUnitProcessor { private fileCompiler; constructor(fileCompiler: FileCompiler); /** * 处理编译单元,落地成对应代码和文件 */ resolve(unit: CompilationUnit, key: CacheKey): Promise; private resolveResult; /** * 将编译产物写入磁盘 */ saveCompiledFiles(unit: CompilationUnit, key: CacheKey): Promise; } interface FileScanResult { assets: string[]; script: string[]; style: string[]; vue: string[]; } declare class FileProcessor { private fileCompiler; private compilationUnitProcessor; private cacheManager; private skippedCount; constructor(fileCompiler: FileCompiler, compilationUnitProcessor: CompilationUnitProcessor, cacheManager: CacheManager); /** * Process a single Vue file (this method is called directly in CLI Watch mode) */ processSFC(filePath: string, existingCache?: LoadedCache): Promise; /** * Process a single script file (this method is called directly in CLI Watch mode) */ processScript(filePath: string, existingCache?: LoadedCache): Promise; /** * Process a single style file (this method is called directly in CLI Watch mode) */ processStyle(filePath: string, existingCache?: LoadedCache): Promise; /** * Process a single vue file */ processFile(key: CacheKey.SFC, filePath: string, existingCache?: LoadedCache): Promise; /** * Process a single script file */ processFile(key: CacheKey.SCRIPT, filePath: string, existingCache?: LoadedCache): Promise; /** * Process a single style file */ processFile(key: CacheKey.STYLE, filePath: string, existingCache?: LoadedCache): Promise; /** * Process a single vue/script/style file */ processFile(key: CacheKey, filePath: string, existingCache?: LoadedCache): Promise; /** * 对 package.json 注入路由依赖项 */ private addRouterToPackageJson; /** * 注入路由提供器到 React 应用的入口文件(如 main.tsx) */ private updateEntryWithRouterProvider; /** * 获取跳过的文件数量 */ getSkippedCount(): number; /** * 重置跳过的文件数量 */ resetSkippedCount(): void; /** * 扫描项目中的编译文件和资产文件 * @param recursive 是否递归扫描子目录 * @param ignoreAssets 需要忽略的资产文件列表 */ scanFiles(): FileScanResult; } declare class PipelineManager { private fileCompiler; private fileProcessor; private cleanupManager; private skippedCount; constructor(fileCompiler: FileCompiler, fileProcessor: FileProcessor, cleanupManager: CleanupManager); /** * 运行 SFC 编译管线 */ runSFC(files: string[], cacheMap: CacheMap): Promise; /** * 运行 Script 编译管线 */ runScript(files: string[], cacheMap: CacheMap): Promise; /** * 运行 Style 编译管线 */ runStyle(files: string[], cacheMap: CacheMap): Promise; /** * 核心编译管线 */ private runCore; /** * 获取跳过的文件数量 */ getSkippedCount(): number; /** * 重置跳过的文件数量 */ resetSkippedCount(): void; } /** * Vite 环境初始化管理器 */ declare class ViteBootstrapper { private fileCompiler; private options; private spinner; private defaultConfig; constructor(fileCompiler: FileCompiler, options: CompilerOptions); /** * 检查是否需要初始化 Vite 环境 */ private isSingleFile; /** * 利用 Vite 官方脚手架创建标准 React 环境 */ bootstrapIfNeeded(): Promise; /** * 执行 vite 创建命令 */ private resolveViteCreateApp; /** * 处理 React 包版本 * @param ver 版本号 */ private resolveReactVersion; } interface CompilerManager { viteBootstrapper: ViteBootstrapper; fileProcessor: FileProcessor; pipelineManager: PipelineManager; assetManager: AssetManager; cacheManager: CacheManager; cleanupManager: CleanupManager; } /** * 文件系统编译器 - 将 Vue 项目批量转换为 React 项目 * * 提供完整的文件系统级别编译功能,包括 SFC、脚本、样式编译, * 资源拷贝、增量编译、缓存管理和 Vite 环境初始化。 */ declare class FileCompiler extends BaseCompiler { manager: CompilerManager; private spinner; constructor(options?: CompilerOptions); private printTitle; private updateSpinner; /** 执行完整的编译流程 */ execute(): Promise; /** 处理单个 Vue 单文件组件(SFC) */ processSFC(filePath: string, existingCache?: LoadedCache): Promise; /** 处理单个 JavaScript/TypeScript 脚本文件 */ processScript(filePath: string, existingCache?: LoadedCache): Promise; /** 处理单个 CSS/LESS/SCSS 样式文件 */ processStyle(filePath: string, existingCache?: LoadedCache): Promise; /** 处理单个文件(Vue 或 Script) */ processFile(key: CacheKey, filePath: string, existingCache?: LoadedCache): Promise; /** 处理单个资源文件 */ processAsset(filePath: string, existingCache?: LoadedCache): Promise; /** 删除指定路径对应的输出文件和缓存 */ removeOutputPath(targetPath: string, type: CacheKey): Promise; private showCompileStats; private resetSkippedCount; } /** * Type helper to make it easier to use vureact.config.js * accepts a direct {@link UserConfig} object, or a function that returns it. */ declare function defineConfig(config: CompilerOptions): CompilerOptions; declare function defineConfig(config: UserConfigFnObject): CompilerOptions; type UserConfigFnObject = () => CompilerOptions; /** * Next Vue to React compiler, compiles Vue 3 syntax into runnable React 18+ code. * * @extends FileCompiler * * @see {@link FileCompiler} * @see https://vureact.top */ declare class VuReact extends FileCompiler { } interface ParseResult { template: BlockIR; script: BlockIR; style: BlockIR; } type BlockIR = { source?: S; ast: T; } | null; interface ParserOptions { plugins?: PluginRegister; } /** * 解析 Vue 单文件组件(SFC)源码,生成结构化解析结果。 * * 此函数是解析阶段的核心入口, * 负责将 Vue SFC 源码解析为包含模板、脚本、样式等各个块的结构化数据。 * * @param source - Vue 单文件组件的源码字符串 * @param ctx - 编译上下文对象 * @param plugins - 可选的插件注册表,用于对解析结果进行自定义处理和增强 * * @returns 解析结果对象,包含模板、脚本、样式块的解析信息 * @throws 不会直接抛出异常,错误信息会通过日志系统记录 */ declare function parseSFC(source: string, ctx: ICompilationContext, options?: ParserOptions): ParseResult; /** * 仅用于解析 script 文件,参数与 parseSFC 一致 */ declare function parseOnlyScript(source: string, ctx: ICompilationContext, options?: ParserOptions): ParseResult; /** * 解析 Vue 组件源码的统一入口函数。 * * 根据输入类型自动选择解析器: * - `sfc`: 解析 Vue 单文件组件(包含 template/script/style) * - `script-*`: 仅解析脚本文件(如 .js、.ts) * * @param source - 源码字符串 * @param ctx - 编译上下文,包含输入类型、文件名等信息 * @param options - 可选的解析器配置,如插件 * @returns 解析结果对象,包含模板、脚本、样式的结构化数据 */ declare function parse(source: string, ctx: ICompilationContext, options?: ParserOptions): ParseResult; interface ScriptBlockIR { /** Transformed full script AST (used for script-only input). */ scriptAST?: ParseResult$1; imports: t.ImportDeclaration[]; exports: t.ExportDeclaration[]; tsTypes: t.TypeScript[]; /** Executable statements extracted from script block. */ statement: { /** Statements hoisted outside component function. */ global: t.Node[]; /** Statements kept inside component function. */ local: ParseResult$1 | null; }; } declare const enum NodeTypes { FRAGMENT = 0, ELEMENT = 1, TEXT = 2, COMMENT = 3, JSX_INTERPOLATION = 4 } declare const enum PropTypes { ATTRIBUTE = 1, SLOT = 2, EVENT = 3, DYNAMIC_ATTRIBUTE = 4 } interface BabelExp { content: string; ast: T; } interface BaseSimpleNodeIR { type: NodeTypes; content: string; babelExp: Expression; } interface FragmentNodeIR { type: NodeTypes; children: TemplateChildNodeIR[]; } interface ElementNodeIR extends BaseElementNodeIR { type: NodeTypes; props: (PropsIR | SlotPropsIR)[]; children: TemplateChildNodeIR[]; meta: Partial; conditionIsHandled: boolean; isBuiltIn?: boolean; isRoute?: boolean; } interface BaseElementNodeIR { tag: string; isRoot?: boolean; isComponent?: boolean; isSelfClosing?: boolean; ref?: string; loc?: SourceLocation$1; } interface ElementNodeIRMeta { condition: ConditionMeta; loop: LoopMeta; memo: MemoMeta; show: ShowMeta; } type ConditionMeta = { if?: boolean; elseIf?: boolean; else?: boolean; value: string; babelExp: BabelExp; next?: ElementNodeIR; isHandled: boolean; }; type LoopMeta = { isLoop?: boolean; value: { source: string; value: string; key?: string; index?: string; }; isHandled: boolean; }; type MemoMeta = { isMemo?: boolean; value: string; babelExp: BabelExp; isHandled: boolean; }; type ShowMeta = { isShow?: boolean; value: string; babelExp: BabelExp; }; interface PropsIR { type: PropTypes; rawName?: string; name: string; isStatic?: boolean; modifiers?: string[]; value: PropIRValue; isKeyLessVBind?: boolean; babelExp: BabelExp; } type PropIRValue = { content: string; isStringLiteral?: boolean; merge?: string[]; babelExp: BabelExp; }; interface SlotPropsIR { type: PropTypes.SLOT; name: string; rawName: string; isStatic: boolean; isScoped: boolean; content?: TemplateChildNodeIR[]; callback?: { arg: string; exp: TemplateChildNodeIR[]; }; } interface TemplateBlockIR { children: TemplateChildNodeIR[]; } type TemplateChildNodeIR = ElementNodeIR | BaseSimpleNodeIR | FragmentNodeIR; interface ReactIRDescriptor { template: TemplateBlockIR; script: ScriptBlockIR; style?: string; } interface TransformerOptions { plugins?: PluginRegister; } /** * 将 Vue SFC 解析结果转换为 React 中间表示(IR)。 * * 此函数是转换阶段的核心入口,负责将 Vue 组件的解析结果(AST)转换为 * 适合生成 React 代码的中间表示形式。转换过程包括模板转换和脚本转换。 * * @param ast - Vue SFC 的解析结果,来自 {@link parse} 函数的返回值 * @param ctx - 编译上下文对象 * @param plugins - 可选的插件注册表,用于对转换结果进行自定义处理和增强 * * @returns React 中间表示描述符,包含模板、脚本和样式的转换结果 */ declare function transform(ast: ParseResult, ctx: ICompilationContext, options?: TransformerOptions): ReactIRDescriptor; interface GeneratorOptions extends GeneratorOptions$1 { plugins?: PluginRegister; } interface GeneratorResult { ast: t.Program | ParseResult$1; code: string; source: string; } /** * 将 React 中间表示(IR)生成为可执行的 JSX/TSX 代码。 * * 此函数是代码生成阶段的核心入口,负责将转换后的 React IR 转换为 * 完整的 AST 并最终生成源代码。生成过程包括 JSX 构建和脚本构建。 * * @param ir - React 中间表示描述符,来自 {@link transform} 函数的返回值 * @param ctx - 编译上下文对象 * @param options - 可选的生成选项,包括 Babel 生成器选项和插件 * * @returns 生成结果对象,包含 AST、生成的代码和原始源码引用 */ declare function generateComponent(ir: ReactIRDescriptor, ctx: ICompilationContext, options?: GeneratorOptions): GeneratorResult; declare function generateOnlyScript(ir: ReactIRDescriptor, ctx: ICompilationContext, options?: GeneratorOptions): GeneratorResult; /** * 代码生成的统一入口函数。 * * 根据输入类型自动选择生成器: * - `sfc`: 生成完整的 React 组件(包含 JSX 和脚本) * - `script-*`: 仅生成脚本代码(如 .js、.ts) * * @param ir - React 中间表示描述符,来自转换阶段的结果 * @param ctx - 编译上下文,包含输入类型、源码等信息 * @param options - 可选的生成器配置,如 Babel 生成选项和插件 * @returns 生成结果对象,包含 AST、生成的代码和原始源码 */ declare function generate(ir: ReactIRDescriptor, ctx: ICompilationContext, options?: GeneratorOptions): GeneratorResult; export { type AssetUnit, type BaseCompilationResult, BaseCompiler, type BaseUnit, type CacheCheckResult, CacheKey, type CacheList, type CacheMap, type CacheMeta, type CompilationResult, type CompilationUnit, type CompilerOptions, type CompilerPlugins, type FileCacheMeta, FileCompiler, type FileMeta, type FormatConfig, type GeneratorOptions, type GeneratorResult, Helper, type LoadedCache, type LoggingConfig, type OutputConfig, type ParseResult, type ParserOptions, type PluginRegister, type ReactIRDescriptor, type RouterConfig, type SFCCompilationResult, type SFCUnit, type ScriptCacheMeta, type ScriptCompilationResult, type ScriptUnit, type StyleCacheMeta, type StyleCompilationResult, type StyleUnit, type TransformerOptions, type UserConfigFnObject, VuReact, type Vue2ReactCacheMeta, defineConfig, generate, generateComponent, generateOnlyScript, parse, parseOnlyScript, parseSFC, transform };