@joker.front/ast
Version:
### Overview
175 lines (174 loc) • 3.88 kB
TypeScript
/**
* AST 语法树(Joker)
*/
export declare namespace AST {
/** 节点类型 */
enum NodeType {
TEXT = 0,
COMMENT = 1,
ELEMENT = 2,
COMMAND = 3,
COMPONENT = 4
}
/**
* 节点父类
*/
interface Node {
childrens?: Array<Node>;
type: NodeType;
}
/**
* 文本节点
*/
interface Text extends Node {
type: NodeType.TEXT;
text: string;
}
/**
* 注释节点
*/
interface Comment extends Node {
type: NodeType.COMMENT;
text: string;
}
/**
* Element 属性
*/
interface Attribute {
express?: string;
name: string;
value?: string;
}
/**
* Element 事件
*/
type Event = {
name: string;
modifiers?: Array<string>;
functionName?: string;
functionParam?: string;
_code?: string;
};
/**
* Element节点(含组件)
*/
interface Element extends Node {
type: NodeType.ELEMENT;
childrens: Node[];
attributes: Attribute[];
events: Event[];
tagName: string;
}
/**
* Component节点(动态组件,不提供给SFC静态文件解析时使用)
*/
interface Component extends Node {
type: NodeType.COMPONENT;
childrens: Node[];
attributes: Attribute[];
events: Event[];
component: IComponent | (new (...arg: any[]) => IComponent);
}
/**
* 命令节点
*/
interface Command extends Node {
type: NodeType.COMMAND;
_code?: string;
cmdName: string;
isGroup: boolean;
}
/**
* 区域渲染命令
*/
interface SectionCommand extends Command {
cmdName: "section";
childrens: Node[];
id: string;
paramKeys: Array<string>;
}
interface ConditionParam {
/**
* let的key指
*/
letKey: string;
/**
* let Key 的默认值(开始值)
*/
defaultKeyVal: string;
/**
* for循环 步骤命令
*/
step: string;
/**
* for循环条件
*/
condition: string;
}
interface InOrOfParam {
/**
* for 循环index索引值
* for in 时的key
* for in (索引,item)
*/
indexKey: string | undefined;
/**
* for循环 item值
* for of 时的item值
* for in (索引,item)
*/
itemKey: string | undefined;
/**
* 要遍历的目标
*/
dataKey: string;
}
/**
* For循环命令
*/
interface ForCommand extends Command {
childrens: Node[];
keyType: "in" | "of" | "condition";
param: ConditionParam | InOrOfParam;
cmdName: "for";
}
/**
* if 判断节点
*/
interface IfCommand extends Command {
childrens: Node[];
kind: "if" | "elseif" | "else";
condition: string;
cmdName: "if";
}
/**
* 属性/方法 命令
*/
interface PropertyOrFunctionCommand extends Command {
param: string;
}
}
export interface IComponent {
/** 在启用keepalive时,用于判断是否在睡眠状态 */
isSleeped: boolean;
/** 是否要保持存活 */
isKeepAlive?: boolean;
/**
* 挂载到元素上
* @param root
* @returns
*/
$mount: (root: any) => void;
/**
* 销毁
* @param force 是否强制销毁,用于清理keepalive组件
* @returns
*/
$destroy: (force?: boolean) => void;
}
export declare const JOKER_TRACE_EXPRESSIONS: unique symbol;
declare global {
interface Window {
[JOKER_TRACE_EXPRESSIONS]?: boolean;
}
}