@maverick-js/compiler
Version:
Maverick toolchain including the analyzer and compiler.
138 lines (137 loc) • 4.88 kB
TypeScript
import type ts from 'typescript';
import type { JSXAttrNamespace, JSXElementNode, JSXEventNamespace, JSXRootNode } from './jsx/parse-jsx';
declare const AST: unique symbol;
export type AST = {
/** @internal */
[AST]: true;
root: JSXRootNode;
tree: ASTTree;
};
export type ASTTree = ASTNode[];
export declare const enum ASTNodeKind {
Element = 1,
Fragment = 2,
Spread = 3,
Attribute = 4,
Text = 5,
Expression = 6,
Ref = 7,
Event = 8,
Directive = 9,
Structural = 20
}
export type ASTNode = ElementNode | FragmentNode | TextNode | ExpressionNode | AttributeNode | SpreadNode | RefNode | EventNode | DirectiveNode | StructuralNode;
export type ASTUnknownNode = {
kind: ASTNodeKind;
};
export declare const enum StructuralNodeType {
ElementEnd = 1,
ChildrenStart = 4,
ChildrenEnd = 5,
AttributesEnd = 6
}
export type StructuralNode = {
type: StructuralNodeType;
kind: ASTNodeKind.Structural;
};
export type ElementNode = {
kind: ASTNodeKind.Element;
ref: JSXElementNode;
tagName: string;
isVoid: boolean;
isSVG: boolean;
isCE: boolean;
children?: ComponentChildren[];
isComponent: boolean;
hasChildren: boolean;
childCount: number;
childElementCount: number;
spread(): boolean;
dynamic(): boolean;
};
export type ComponentChildren = AST | TextNode | ExpressionNode;
export type FragmentNode = {
kind: ASTNodeKind.Fragment;
ref: ts.JsxFragment;
childCount: number;
childElementCount: number;
children?: ComponentChildren[];
};
export type TextNode = {
kind: ASTNodeKind.Text;
ref: ts.JsxText;
value: string;
};
export type ExpressionNode = {
kind: ASTNodeKind.Expression;
ref: ts.Expression | ts.JsxExpression;
root?: boolean;
observable?: boolean;
children?: AST[];
dynamic: boolean;
value: string;
callId?: string;
};
export type SpreadNode = {
kind: ASTNodeKind.Spread;
ref: ts.JsxSpreadAttribute;
value: string;
};
export type AttributeNode = {
kind: ASTNodeKind.Attribute;
ref: ts.JsxAttribute | ts.StringLiteral | ts.Expression;
namespace: JSXAttrNamespace | null;
name: string;
value: string;
dynamic?: boolean;
observable?: boolean;
callId?: string;
children?: AST[];
};
export type RefNode = {
kind: ASTNodeKind.Ref;
ref: ts.Expression;
value: string;
};
export type EventNode = {
kind: ASTNodeKind.Event;
ref: ts.Expression;
namespace: JSXEventNamespace | null;
type: string;
value: string;
data?: string;
delegate: boolean;
};
export type DirectiveNode = {
kind: ASTNodeKind.Directive;
ref: ts.Expression;
name: string;
value: string;
};
export declare function createAST(root: JSXRootNode): AST;
export declare function createElementNode(info: Omit<ElementNode, 'kind'>): ElementNode;
export declare function createFragmentNode(info: Omit<FragmentNode, 'kind'>): FragmentNode;
export declare function createTextNode(info: Omit<TextNode, 'kind' | 'value'>): TextNode;
export declare function createAttributeNode(info: Omit<AttributeNode, 'kind'>): AttributeNode;
export declare function createRefNode(info: Omit<RefNode, 'kind'>): RefNode;
export declare function createEventNode(info: Omit<EventNode, 'kind'>): EventNode;
export declare function createDirectiveNode(info: Omit<DirectiveNode, 'kind'>): DirectiveNode;
export declare function createExpressionNode(info: Omit<ExpressionNode, 'kind'>): ExpressionNode;
export declare function createSpreadNode(info: Omit<SpreadNode, 'kind' | 'value'>): SpreadNode;
export declare function createStructuralNode(type: StructuralNodeType): StructuralNode;
export declare function isAST(value: any): value is AST;
export declare function isElementNode(node: ASTUnknownNode): node is ElementNode;
export declare function isFragmentNode(node: ASTUnknownNode): node is FragmentNode;
export declare function isTextNode(node: ASTUnknownNode): node is TextNode;
export declare function isAttributeNode(node: ASTUnknownNode): node is AttributeNode;
export declare function isSpreadNode(node: ASTUnknownNode): node is SpreadNode;
export declare function isExpressionNode(node: ASTUnknownNode): node is ExpressionNode;
export declare function isRefNode(node: ASTUnknownNode): node is RefNode;
export declare function isEventNode(node: ASTUnknownNode): node is EventNode;
export declare function isDirectiveNode(node: ASTUnknownNode): node is DirectiveNode;
export declare function isStructuralNode(node: ASTUnknownNode): node is StructuralNode;
export declare function isElementEnd(node: StructuralNode): boolean;
export declare function isAttributesEnd(node: StructuralNode): boolean;
export declare function isChildrenStart(node: StructuralNode): boolean;
export declare function isChildrenEnd(node: StructuralNode): boolean;
export {};