@purevue/compiler-core
Version:
## 📖 Introduction
91 lines • 3.56 kB
TypeScript
import { type CallExpression, type CompoundExpressionNode, type ElementNode, type InterpolationNode, type Property, type SimpleExpressionNode, type TemplateChildNode, type TextNode, type VNodeCall } from './types';
/**
* 创建简单表达式节点
* @param content 表达式内容
* @param isStatic 是否静态表达式
*/
export declare function createSimpleExpression(content: string, isStatic: boolean): SimpleExpressionNode;
/**
* 创建对象属性节点,用于表示对象字面量中的一对 key-value
* @param key SimpleExpressionNode,表示属性名
* @param value SimpleExpressionNode,表示属性值
* @returns PropertyNode 对象
*/
export declare function createObjectProperty(key: Property['key'], value: Property['value']): Property;
/**
* 创建复合表达式节点
* @param children 字符串或表达式节点数组,表示拼接内容
* @returns CompoundExpressionNode 对象
*/
export declare function createCompoundExpression(children: CompoundExpressionNode['children']): CompoundExpressionNode;
/**
* 创建一个 JS 调用表达式 AST 节点
* @param callee 调用的函数名,可以是字符串或 runtime helper 符号
* @param args 调用参数数组
* @returns CallExpression AST 节点
*/
export declare function createCallExpression(callee: string | symbol, args?: any[]): CallExpression;
export declare function createInterpolation(content: InterpolationNode['content'] | string): InterpolationNode;
export declare function createElementNode(tag: ElementNode['tag'], props: ElementNode['props'], children: ElementNode['children'], tagType?: ElementNode['tagType']): ElementNode;
/**
* 判断一个 AST 节点是否是组件
* @param node ElementNode
* @returns boolean
*/
export declare function isComponent(tag: ElementNode['tag']): boolean;
export declare function createTextNode(content: TextNode['content']): TextNode;
/**
* 创建 VNode 调用表达式
*/
export declare function createVNodeCall(tag: VNodeCall['tag'], props: VNodeCall['props'], children: any, _patchFlag?: any): VNodeCall;
/**
* 代码生成阶段的配置选项
*/
export interface CodegenOptions {
/**
* 生成模式:
* - 'function':生成可用 new Function 执行的渲染函数代码(运行时编译)
* - 'module':生成包含 import/export 的 ES 模块代码(预编译/构建时使用)
* @default 'function'
*/
mode?: 'function' | 'module';
/**
* 编译目标环境是否是浏览器
* 用于控制导入/导出等生成逻辑
* @default false
*/
isBrowser?: boolean;
/**
* 运行时模块名(通常为 "vue")
* 在 module 模式下用于生成 import 语句
* @default 'vue'
*/
runtimeModuleName?: string;
/**
* 在 UMD / IIFE 或全局环境下访问 Vue runtime 的全局变量名
* 比如 window.Vue 或 globalThis.Vue
* 默认 'Vue'
*/
runtimeGlobalName?: string;
/**
* 是否启用 import 助手函数的优化(webpack code-split 时用)
* @default false
*/
optimizeImports?: boolean;
/**
* 是否生成源码位置(开发调试用)
* @default false
*/
sourceMap?: boolean;
/**
* 缩进级别(用于生成格式化代码)
* @default 0
*/
indentLevel?: number;
/**
* 模板源代码(用于生成代码位置映射)
*/
source?: string;
}
export declare function isText(node: TemplateChildNode): node is TextNode | InterpolationNode;
//# sourceMappingURL=ast.d.ts.map