/**
 * Node Interfaces & Related types
 *
 * Note: This file is used by generators! See packages/core/generators/ast.generator.ts
 */ import { DecimalKind , DefinitionFlags , LinkedListFlags , ModifierFlags , NodeFlags , NodeKind , OrderKind , SignatureKind , TypeFlags } from './enums' ; import { CompileOptionsSet , NumberRange } from '../types' ; import { NodeMap , NodeSet , ReadonlyNodeMap , ReadonlyNodeSet } from '#ast/components' ; import { Language } from '#language/language' ; import { NodeIndex , NodeOrigin , OutputFile } from '#ast/shared-types' ; import { Declaration , RootDeclaration , ValueNode } from '#ast/node-aliases' ; interface VariableBitLength { bitLength ? : number | number [ ] | NumberRange ; } /**
 * Helper type used solely to indicate to generator what base flags a Node should have
 */ interface Flags < T extends TypeFlags | NodeFlags , K extends T extends TypeFlags ? keyof typeof TypeFlags : keyof typeof NodeFlags > { } export interface Node { readonly id : number ; readonly parent : Node ; readonly flags : NodeFlags ; readonly typeFlags : TypeFlags ; readonly kind : NodeKind ; readonly modifiers : ModifierFlags ; readonly origin ? : NodeOrigin ; readonly compileOptions ? : CompileOptionsSet ; /**
     * (Getter) String value for kind
     */ readonly kindString : string ; returns getLineage ( ) : undefined | Node [ ] ; param brokenReferenceReplacer delete ( brokenReferenceReplacer ? ) : void ; /**
     * Iterate all children, providing parent property key in which the child was found
     */ forEachChild < T extends Node > ( this , cb ) : void ; param matcher findParent < T > ( matcher ) : T | undefined ; findParent < T > ( matcher ) : T | undefined ; param name getNamedParent ( name ? ) : Node | undefined ; /**
     * Get parent Definition
     */ getDefinition ( ) : Definition | undefined ; /**
     * Get parent SourceFile (only exists during compilation, as definitions can have multiple output files)
     */ getSourceFile ( ) : SourceFile | undefined ; returns param deep param predicate getChildren < T extends Node = Node > ( deep ? , predicate ? ) : NodeSet < T > | undefined ; param parent clone < T extends Node > ( this , parent ) : T ; param newNode param brokenReferenceReplacer param reuseMemory returns replace < T extends Node > ( newNode , brokenReferenceReplacer ? , reuseMemory ? ) : T ; param language param options compile < T extends Language . Names > ( language , options ? ) : string ; /**
     * Get all ReferenceNodes in collection which refer to this node
     */ getReferencesToThisNode ( ) : ReadonlyNodeSet < ReferenceNode > | undefined ; ignore cleanup ( ) : void ; ignore returns updateProperties < T extends Node > ( this , props ) : T ; } export interface NamedNode < T extends NodeIndex = NodeIndex > extends Node , Flags < NodeFlags , 'Named' > { name : T ; } export interface DeclarationBase < T extends NodeIndex = string > extends NamedNode < T > { } export interface Definition extends NamedNode < string > , Flags < NodeFlags , 'Definition' > { readonly kind : NodeKind . Definition ; readonly definitionFlags : DefinitionFlags ; outputs ? : OutputFile [ ] ; name : string ; declarations : NodeSet < RootDeclaration > ; exported ? : boolean ; typeArguments ? : NodeMap < TypeArgumentNode > ; primary : boolean ; } export type ModuleLikeNode = ModuleDeclaration | SourceFile ; interface ModuleBase extends DeclarationBase { name : string ; definitions ? : NodeMap < Definition > ; } export interface ModuleDeclaration extends ModuleBase , Flags < TypeFlags , 'Module' > , Flags < NodeFlags , 'Declaration' > { readonly kind : NodeKind . ModuleDeclaration ; exported ? : boolean ; } export interface SourceFile extends ModuleBase , Flags < TypeFlags , 'Module' > { readonly kind : NodeKind . SourceFile ; readonly language : Language . FullNames ; fileName : string ; } see https export interface StringNode extends Node , Flags < TypeFlags , 'Primitive' > { readonly kind : NodeKind . String ; } see https export interface CharacterNode extends Node , VariableBitLength , Flags < TypeFlags , 'Primitive' > { readonly kind : NodeKind . Character ; length : number | NumberRange ; } see https export interface ByteNode extends Node , VariableBitLength , Flags < TypeFlags , 'Primitive' > { readonly kind : NodeKind . Byte ; length : number | NumberRange ; signed : boolean ; } see https export interface RegExpNode extends Node , Flags < TypeFlags , 'Primitive' > { readonly kind : NodeKind . RegExp ; } see https export interface SymbolNode extends Node , Flags < TypeFlags , 'Primitive' > { readonly kind : NodeKind . Symbol ; } see https export interface BooleanNode extends Node , Flags < TypeFlags , 'Primitive' > { readonly kind : NodeKind . Boolean ; } export type RealNumberNode = IntegerNode | DecimalNode ; export type NumericNode = IntegerNode | DecimalNode | NotANumberNode | InfinityNode | ComplexNumberNode ; see https export interface IntegerNode extends Node , VariableBitLength , Flags < TypeFlags , 'Primitive' | 'Numeric' > { readonly kind : NodeKind . Integer ; } see https see https see https export interface DecimalNode extends Node , VariableBitLength , Flags < TypeFlags , 'Primitive' | 'Numeric' > { readonly kind : NodeKind . Decimal ; decimalKind : DecimalKind ; /**
     * Optionally specify decimal precision
     */ decimalPrecision ? : number ; } see https export interface ComplexNumberNode extends Node , VariableBitLength , Flags < TypeFlags , 'Primitive' | 'Numeric' > { readonly kind : NodeKind . ComplexNumber ; } see https export interface NotANumberNode extends Node , Flags < TypeFlags , 'Primitive' | 'Numeric' > { readonly kind : NodeKind . NotANumber ; } see https export interface InfinityNode extends Node , Flags < TypeFlags , 'Primitive' | 'Numeric' > { readonly kind : NodeKind . Infinity ; negative : boolean ; } /**
 * Exact string value
 */ export interface StringLiteral extends Node , Flags < TypeFlags , 'Literal' > { readonly kind : NodeKind . StringLiteral ; value : string ; } /**
 * true literal value
 */ export interface TrueLiteral extends Node , Flags < TypeFlags , 'Literal' > { readonly kind : NodeKind . TrueLiteral ; } /**
 * false literal value
 */ export interface FalseLiteral extends Node , Flags < TypeFlags , 'Literal' > { readonly kind : NodeKind . FalseLiteral ; } /**
 * Exact Regular Expression
 */ export interface RegExpLiteral extends Node , Flags < TypeFlags , 'Literal' > { readonly kind : NodeKind . RegExpLiteral ; expression : string ; regexFlags ? : string ; } see https export interface DateTimeLiteral extends Node , Flags < TypeFlags , 'Literal' > { kind : NodeKind . DateTimeLiteral ; format : string ; value : string ; } /**
 * Exact symbol (may or may not be always unique - see notes for alwaysUnique property)
 */ export interface SymbolLiteral extends Node , Flags < TypeFlags , 'Literal' > { readonly kind : NodeKind . SymbolLiteral ; value ? : string | number ; alwaysUnique : boolean ; } export type RealNumberLiteral = IntegerLiteral | DecimalLiteral ; export type NumericLiteral = IntegerLiteral | DecimalLiteral | ImaginaryNumberLiteral ; /**
 * Exact integer value
 */ export interface IntegerLiteral extends Node , Flags < TypeFlags , 'Literal' > { readonly kind : NodeKind . IntegerLiteral ; value : string ; } /**
 * Exact decimal value
 */ export interface DecimalLiteral extends Node , Flags < TypeFlags , 'Literal' > { readonly kind : NodeKind . DecimalLiteral ; value : string ; } see https export interface ImaginaryNumberLiteral extends Node , Flags < TypeFlags , 'Literal' > { readonly kind : NodeKind . ImaginaryNumberLiteral ; value : string ; } export type IterableNode = GenericIterable | ArrayNode | MapNode | MultiSetNode | SetNode | ListNode | LinkedListNode ; interface IterableNodeBase extends Node { orderKind : OrderKind ; uniqueMembers ? : boolean ; indexType ? : ValueNode ; valueType : ValueNode ; resizable ? : boolean ; } /**
 * Used if no existing iterable node fits
 */ export interface GenericIterable extends IterableNodeBase , Flags < TypeFlags , 'Iterable' | 'Composite' > { readonly kind : NodeKind . GenericIterable ; } see https export interface ArrayNode extends IterableNodeBase , Flags < TypeFlags , 'Iterable' | 'Composite' > { readonly kind : NodeKind . Array ; readonly orderKind : OrderKind . Index ; readonly indexType : IntegerNode ; resizable : boolean ; } see https export interface MapNode extends IterableNodeBase , Flags < TypeFlags , 'Iterable' | 'Composite' > { readonly kind : NodeKind . Map ; readonly resizable : true ; readonly orderKind : OrderKind . Index ; readonly uniqueMembers : true ; indexType : ValueNode ; } see https export interface MultiSetNode extends IterableNodeBase , Flags < TypeFlags , 'Iterable' | 'Composite' > { readonly kind : NodeKind . MultiSet ; readonly uniqueMembers : false ; } see https export interface SetNode extends IterableNodeBase , Flags < TypeFlags , 'Iterable' | 'Composite' > { readonly kind : NodeKind . Set ; readonly uniqueMembers : true ; } see https export interface ListNode extends IterableNodeBase , Flags < TypeFlags , 'Iterable' | 'Composite' > { readonly kind : NodeKind . List ; readonly resizable : true ; readonly orderKind : OrderKind . Index ; readonly indexType : IntegerNode ; } see https export interface LinkedListNode extends IterableNodeBase , Flags < TypeFlags , 'Iterable' | 'Composite' > { readonly kind : NodeKind . LinkedList ; readonly orderKind : OrderKind . Link ; linkedListFlags : LinkedListFlags ; } see https export interface EnumDeclaration extends DeclarationBase , VariableBitLength , Flags < TypeFlags , 'Enum' > , Flags < NodeFlags , 'Declaration' > { readonly kind : NodeKind . EnumDeclaration ; name : string ; members : NodeMap < EnumMemberDeclaration > ; readonly keys : NodeIndex [ ] | undefined ; readonly values : ( StringLiteral | RealNumberLiteral ) [ ] ; } see https export interface EnumMemberDeclaration extends DeclarationBase , Flags < NodeFlags , 'Declaration' | 'Nested' > { readonly kind : NodeKind . EnumMemberDeclaration ; name : string ; value ? : StringLiteral | RealNumberLiteral ; } see https export interface TupleNode extends Node , Flags < TypeFlags , 'Tuple' > { readonly kind : NodeKind . Tuple ; elements ? : NodeSet < ValueNode > ; hasRestElement ? : boolean ; } export type ObjectNodeKey = string | number | SymbolLiteral ; export type ObjectLikeNode = ObjectNode | ClassDeclaration | InterfaceDeclaration | AnonymousClass ; export type ClassLikeNode = ClassDeclaration | InterfaceDeclaration | AnonymousClass ; export interface ObjectNodeBase extends Node { members : NodeMap < ObjectLikeMember > ; indexType ? : StringNode | RealNumberNode | SymbolNode | NodeSet < StringLiteral | RealNumberLiteral | SymbolLiteral > ; valueType ? : ValueNode ; readonly properties ? : ReadonlyNodeMap < PropertyDeclaration > ; readonly methods ? : ReadonlyNodeMap < MethodDeclaration > ; } export interface ClassLikeNodeBase extends ObjectNodeBase { readonly heritage ? : ReadonlyNodeSet < ReferenceNode > ; constructSignatures ? : NodeSet < SignatureNode | ReferenceNode > ; typeParameters ? : NodeMap < TypeParameterDeclaration > ; } see https export interface ObjectNode extends ObjectNodeBase , Flags < TypeFlags , 'Object' > { readonly kind : NodeKind . Object ; } see https export interface ClassDeclaration extends ClassLikeNodeBase , DeclarationBase , Flags < NodeFlags , 'Declaration' > , Flags < TypeFlags , 'Class' | 'Composite' > { readonly parent : Definition ; readonly kind : NodeKind . ClassDeclaration ; name : string ; } see https export interface AnonymousClass extends ClassLikeNodeBase , Flags < TypeFlags , 'Class' | 'Composite' > { readonly parent : Definition ; readonly kind : NodeKind . AnonymousClass ; name ? : string ; } see https see https export interface InterfaceDeclaration extends ClassLikeNodeBase , DeclarationBase , Flags < NodeFlags , 'Declaration' > , Flags < TypeFlags , 'Interface' | 'Composite' > { readonly parent : Definition ; readonly kind : NodeKind . InterfaceDeclaration ; callSignatures ? : NodeSet < SignatureNode > ; name : string ; } export type ObjectLikeMember = PropertyDeclaration | MethodDeclaration ; export interface ObjectMemberBase extends DeclarationBase < ObjectNodeKey > { optional ? : boolean ; } see https export interface PropertyDeclaration extends ObjectMemberBase , Flags < NodeFlags , 'Nested' | 'Declaration' > , Flags < TypeFlags , 'Property' > { readonly kind : NodeKind . PropertyDeclaration ; value : ValueNode ; /**
     * Indicates property is implemented as accessors (able to determine getter/setter by ReadOnly/WriteOnly modifiers)
     */ isAccessor ? : boolean ; } see https export interface MethodDeclaration extends ObjectMemberBase , Flags < NodeFlags , 'Nested' | 'Declaration' > , Flags < TypeFlags , 'Method' > { readonly kind : NodeKind . MethodDeclaration ; signatures : NodeSet < SignatureNode > ; } export type DateLikeNode = DateNode | DateTimeNode ; export interface DateBase extends Node { format ? : string ; } see https export interface DateNode extends DateBase , Flags < TypeFlags , 'Abstract' > { kind : NodeKind . Date ; } see https export interface DateTimeNode extends DateBase , Flags < TypeFlags , 'Abstract' > { kind : NodeKind . DateTime ; } export type FunctionNode = FunctionDeclaration | AnonymousFunctionNode ; see https export interface FunctionDeclaration extends DeclarationBase , Flags < TypeFlags , 'Function' > , Flags < NodeFlags , 'Declaration' > { readonly kind : NodeKind . FunctionDeclaration ; signatures : NodeSet < SignatureNode > ; } see https export interface AnonymousFunctionNode extends Node , Flags < TypeFlags , 'Function' > { readonly kind : NodeKind . AnonymousFunction ; name ? : string ; signature : SignatureNode ; } see https export interface SignatureNode extends Node , Flags < NodeFlags , 'Nested' > { readonly kind : NodeKind . Signature ; signatureKind : SignatureKind ; isAsync ? : boolean ; isGenerator ? : boolean ; returnType : ValueNode ; parameters ? : NodeMap < ParameterNode > ; typeParameters ? : NodeMap < TypeParameterDeclaration > ; } see https export interface ParameterNode extends NamedNode < string > , Flags < NodeFlags , 'Nested' > { readonly kind : NodeKind . Parameter ; name : string ; type ? : ValueNode ; initializer ? : ValueNode ; markedOptional : boolean ; see https isRestParameter ? : boolean ; } see https export interface TypeParameterDeclaration extends DeclarationBase , Flags < NodeFlags , 'Declaration' | 'Nested' > { readonly kind : NodeKind . TypeParameterDeclaration ; name : string ; constraint ? : ValueNode ; default ? : ValueNode ; } see https export interface TypeArgumentNode extends NamedNode < string > , Flags < NodeFlags , 'Nested' > { readonly kind : NodeKind . TypeArgument ; readonly association : TypeParameterDeclaration ; readonly name : string ; type : ValueNode ; } see https export interface TypeDeclaration extends DeclarationBase , Flags < NodeFlags , 'Declaration' > { kind : NodeKind . TypeDeclaration ; value : ValueNode ; } export interface VariableDeclaration extends DeclarationBase , Flags < NodeFlags , 'Declaration' > { kind : NodeKind . VariableDeclaration ; value : ValueNode ; } see https see https export interface UnionNode extends Node , Flags < TypeFlags , 'Composite' > { readonly kind : NodeKind . Union ; members : NodeSet < ValueNode > ; discriminants ? : ObjectLikeMember [ 'name' ] ; } see https export interface IntersectionNode extends Node , Flags < TypeFlags , 'Composite' > { readonly kind : NodeKind . Intersection ; /**
     * Some languages may have custom methodology for joining types. When set, this value represents the final resolved
     * type for the members. If not present, common logic should be applied on members
     */ resolvedType ? : ValueNode ; } export type TopNode = AnythingNode ; export type BottomNode = NothingNode ; see https export interface AnythingNode extends Node { readonly kind : NodeKind . Anything ; } see https export interface NothingNode extends Node { readonly kind : NodeKind . Nothing ; } see https export interface NullNode extends Node , Flags < TypeFlags , 'Unit' > { readonly kind : NodeKind . Null ; } see https export interface ReferenceNode extends Node , Flags < TypeFlags , 'Reference' > { readonly kind : NodeKind . Reference ; notChild target : Declaration ; internal notChild targetBase : Definition | TypeParameterDeclaration ; internal path : NodeIndex [ ] ; }