import { Location } from '../source/Location'; export type BaseNode = Location & { readonly type: string; }; export type NodeContainer = BaseNode & { readonly type: 'container'; readonly children: ReadonlyArray; }; export type NodeComment = BaseNode & { readonly type: 'comment'; readonly value: string; }; export type NodeText = BaseNode & { readonly type: 'text'; readonly value: string; }; export type NodeData = BaseNode & { readonly type: 'data'; readonly escaped: boolean; readonly value: string; readonly filters?: ReadonlyArray<{ readonly name: string; readonly args: ReadonlyArray; }>; }; export type BaseFunction = BaseNode & { readonly name: string; readonly args?: ReadonlyArray; }; export type NodeFunction = BaseFunction & { readonly type: 'function'; }; export type NodeRawFunction = BaseFunction & { readonly type: 'raw-function'; readonly content: string; }; export type NodeSequence = BaseNode & { readonly type: 'sequence'; readonly data: ReadonlyArray<[NodeFunction, NodeContainer]>; readonly ending: NodeFunction; }; export type Node = | NodeContainer | NodeComment | NodeText | NodeData | NodeFunction | NodeRawFunction | NodeSequence ; // node types without location export type NodeWithoutLocation = | Omit | Omit | Omit | Omit | Omit | Omit | Omit ; // recursive node types without position (start, end) export type NodeContainerRWL = Omit & { readonly children: ReadonlyArray; }; export type NodeCommentRWL = Omit; export type NodeTextRWL = Omit; export type NodeDataRWL = Omit; export type NodeFunctionRWL = Omit; export type NodeRawFunctionRWL = Omit; export type NodeSequenceRWL = Omit & { readonly data: ReadonlyArray<[NodeFunctionRWL, NodeContainerRWL]>; readonly ending: NodeFunctionRWL; }; export type NodeRecursiveWithoutLocation = | NodeContainerRWL | NodeCommentRWL | NodeTextRWL | NodeDataRWL | NodeFunctionRWL | NodeRawFunctionRWL | NodeSequenceRWL ; // utilities export const isNotEmptyContainer = (node?: NodeContainer): node is NodeContainer => { return node !== undefined && node.children.some(it => { return it.type !== 'text' || it.value.trim() !== ''; }); };