@vtj/coder
Version:
VVTJ.PRO 是一个开源的、AI 驱动的 Vue3 企业级应用开发平台,通过 AI 智能体与可视化编排实现高效开发,并支持导出标准 Vue 代码以避免平台锁定。
39 lines (38 loc) • 1.69 kB
TypeScript
import { JSExpression, JSFunction } from '@vtj/core';
import { SymbolTable } from './symbolTable';
/**
* 转换上下文:影响 ref/computed 的 .value 解包行为
* - script: 解包,输出 xxx.value
* - template: 不解包,Vue 模板自动解包
*/
export type TransformContext = 'script' | 'template';
/**
* 转换 DSL 中的 this.xxx 引用为 Composition API 顶层标识符
*
* 转换规则:
* - this.$router 等 globalApi → 替换为 router 等
* - this.refsName → script: refsName.value, template: refsName
* - this.reactiveName → reactiveName(包含 state)
* - this.computedName → script: computedName.value, template: computedName
* - this.methodName → methodName
* - this.propName (props) → script: props.propName, template: propName
* - this.composableName → composableName
* - this.injectName → injectName
* - this.dataSourceName → dataSourceName
* - 未识别的 this.xxx → 保持原样(可能是动态属性 / 测试用例)
*/
export declare function transformExpression(code: string, symbols: SymbolTable, context?: TransformContext): string;
/**
* 转换 JSExpression / JSFunction,返回纯字符串
*/
export declare function transformCode(code: JSExpression | JSFunction | undefined, symbols: SymbolTable, context?: TransformContext): string;
/**
* 仅替换 this 前缀,不依赖符号表(兜底转换)
* 用于无法识别的场景:直接去掉 this. 前缀
*/
export declare function stripThisPrefix(code: string): string;
/**
* 移除外层括号包装:( fn ) → fn
* 与 utils.ts 的 replaceFunctionTag 类似但更宽松
*/
export declare function unwrapFunction(code: string): string;