UNPKG

onelang

Version:

OneLang transpiler framework core

56 lines (55 loc) 2.88 kB
import { ExprLangVM, IModelHandler, VariableContext, VariableSource } from "../ExprLang/ExprLangVM"; import { TemplateAst as Ast } from "./TemplateAst"; import { OneAst as one } from "../../One/Ast"; /** * Some important notes: * - nodes DON'T include trailing '\n', it's only added when they are included into somewhere else * - the AST usually contains all the newline ('\n') characters, except for "for" and "if" constructs, * because those are not always generate _any_ result (not even a newline), eg: * - for: no items and {{else}} is not specified * - if: condition is not true and {{else}} is not specified * so we have to add that '\n' here in the generator based on runtime data * (but only if it's not an inline construct & it's not the last node -> no trailing '\n' is allowed) * - empty string ("") and <null> are different: <null> is created when an if or for does not match any item * <null> does not generate code, not counts as a valid item in for (so no separator included) * empty string ("") can generate code (eg. new line, separator in for loop, etc) */ export declare class TemplateMethod { name: string; args: string[]; template: string; body: Ast.Block; constructor(name: string, args: string[], template: string); static fromSignature(signature: string, template: string): TemplateMethod; } export declare class CallStackItem { methodName: string; vars: VariableContext; constructor(methodName: string, vars: VariableContext); } export declare class GeneratedNode { text: string; astNode: one.INode; constructor(text: string); } export declare class TemplateGenerator implements IModelHandler { vm: ExprLangVM; rootVars: VariableContext; methods: VariableSource; callStack: CallStackItem[]; objectHook: (obj: object) => GeneratedNode[]; constructor(variables: VariableContext); addMethod(method: TemplateMethod): void; methodCall(method: any, args: any[], thisObj: any, vars: VariableContext): GeneratedNode[]; memberAccess(obj: object, memberName: string | number, isProperty: boolean): any; isSimpleTextNode(node: Ast.BlockItem): boolean; static join(items: GeneratedNode[], separator: string): GeneratedNode[]; static joinLines(lines: GeneratedNode[][], separator: string): GeneratedNode[]; processBlockNode(node: Ast.Block, vars: VariableContext): GeneratedNode[]; processLineNode(node: Ast.Line, vars: VariableContext): GeneratedNode[]; processIfNode(node: Ast.IfNode, vars: VariableContext): GeneratedNode[]; processForNode(node: Ast.ForNode, vars: VariableContext): GeneratedNode[]; processTemplateNode(node: Ast.TemplateNode, vars: VariableContext): GeneratedNode[]; generateNode(node: Ast.Node, vars: VariableContext): GeneratedNode[]; generate(template: Ast.Node): string; }