ts-simple-ast
Version:
TypeScript compiler wrapper for AST navigation and code generation.
253 lines (252 loc) • 11.6 kB
TypeScript
import * as ts from "typescript";
import { PropertyDeclarationStructure, MethodDeclarationStructure, ConstructorDeclarationStructure, ClassDeclarationStructure } from "./../../structures";
import { Node } from "./../common";
import { NamedNode, ExportableNode, ModifierableNode, AmbientableNode, DocumentationableNode, TypeParameteredNode, DecoratableNode, HeritageClauseableNode, ImplementsClauseableNode, TextInsertableNode } from "./../base";
import { AbstractableNode } from "./base";
import { ParameterDeclaration } from "./../function";
import { ExpressionWithTypeArguments } from "./../type";
import { NamespaceChildableNode } from "./../namespace";
import { ConstructorDeclaration } from "./ConstructorDeclaration";
import { MethodDeclaration } from "./MethodDeclaration";
import { PropertyDeclaration } from "./PropertyDeclaration";
import { GetAccessorDeclaration } from "./GetAccessorDeclaration";
import { SetAccessorDeclaration } from "./SetAccessorDeclaration";
export declare type ClassInstancePropertyTypes = PropertyDeclaration | GetAccessorDeclaration | SetAccessorDeclaration | ParameterDeclaration;
export declare type ClassInstanceMemberTypes = MethodDeclaration | ClassInstancePropertyTypes;
export declare type ClassStaticPropertyTypes = PropertyDeclaration | GetAccessorDeclaration | SetAccessorDeclaration;
export declare type ClassStaticMemberTypes = MethodDeclaration | ClassStaticPropertyTypes;
export declare type ClassMemberTypes = MethodDeclaration | PropertyDeclaration | GetAccessorDeclaration | SetAccessorDeclaration | ConstructorDeclaration | ParameterDeclaration;
export declare const ClassDeclarationBase: (new (...args: any[]) => TextInsertableNode) & (new (...args: any[]) => ImplementsClauseableNode) & (new (...args: any[]) => HeritageClauseableNode) & (new (...args: any[]) => DecoratableNode) & (new (...args: any[]) => TypeParameteredNode) & (new (...args: any[]) => NamespaceChildableNode) & (new (...args: any[]) => DocumentationableNode) & (new (...args: any[]) => AmbientableNode) & (new (...args: any[]) => AbstractableNode) & (new (...args: any[]) => ExportableNode) & (new (...args: any[]) => ModifierableNode) & (new (...args: any[]) => NamedNode) & typeof Node;
export declare class ClassDeclaration extends ClassDeclarationBase<ts.ClassDeclaration> {
/**
* Fills the node from a structure.
* @param structure - Structure to fill.
*/
fill(structure: Partial<ClassDeclarationStructure>): this;
/**
* Sets the extends expression.
* @param text - Text to set as the extends expression.
*/
setExtends(text: string): this;
/**
* Gets the extends expression.
*/
getExtends(): ExpressionWithTypeArguments | undefined;
/**
* Adds a constructor. Will remove the previous constructor if it exists.
* @param structure - Structure of the constructor.
*/
addConstructor(structure?: ConstructorDeclarationStructure): ConstructorDeclaration;
/**
* Inserts a constructor. Will remove the previous constructor if it exists.
* @param index - Index to insert at.
* @param structure - Structure of the constructor.
*/
insertConstructor(index: number, structure?: ConstructorDeclarationStructure): ConstructorDeclaration;
/**
* Gets the constructor declarations.
*/
getConstructors(): ConstructorDeclaration[];
/**
* Add property.
* @param structure - Structure representing the property.
*/
addProperty(structure: PropertyDeclarationStructure): PropertyDeclaration;
/**
* Add properties.
* @param structures - Structures representing the properties.
*/
addProperties(structures: PropertyDeclarationStructure[]): PropertyDeclaration[];
/**
* Insert property.
* @param index - Index to insert at.
* @param structure - Structure representing the property.
*/
insertProperty(index: number, structure: PropertyDeclarationStructure): PropertyDeclaration;
/**
* Insert properties.
* @param index - Index to insert at.
* @param structures - Structures representing the properties.
*/
insertProperties(index: number, structures: PropertyDeclarationStructure[]): PropertyDeclaration[];
/**
* Gets the first instance property by name.
* @param name - Name.
*/
getInstanceProperty(name: string): ClassInstancePropertyTypes | undefined;
/**
* Gets the first instance property by a find function.
* @param findFunction - Function to find an instance property by.
*/
getInstanceProperty(findFunction: (prop: ClassInstancePropertyTypes) => boolean): ClassInstancePropertyTypes | undefined;
/**
* Gets the first instance property by name or throws if not found.
* @param name - Name.
*/
getInstancePropertyOrThrow(name: string): ClassInstancePropertyTypes;
/**
* Gets the first instance property by a find function or throws if not found.
* @param findFunction - Function to find an instance property by.
*/
getInstancePropertyOrThrow(findFunction: (prop: ClassInstancePropertyTypes) => boolean): ClassInstancePropertyTypes;
/**
* Gets the class instance property declarations.
*/
getInstanceProperties(): ClassInstancePropertyTypes[];
/**
* Gets the first static property by name.
* @param name - Name.
*/
getStaticProperty(name: string): ClassStaticPropertyTypes | undefined;
/**
* Gets the first static property by a find function.
* @param findFunction - Function to find a static property by.
*/
getStaticProperty(findFunction: (prop: ClassStaticPropertyTypes) => boolean): ClassStaticPropertyTypes | undefined;
/**
* Gets the first static property by name or throws if not found.
* @param name - Name.
*/
getStaticPropertyOrThrow(name: string): ClassStaticPropertyTypes;
/**
* Gets the first static property by a find function. or throws if not found.
* @param findFunction - Function to find a static property by.
*/
getStaticPropertyOrThrow(findFunction: (prop: ClassStaticPropertyTypes) => boolean): ClassStaticPropertyTypes;
/**
* Gets the class instance property declarations.
*/
getStaticProperties(): ClassStaticPropertyTypes[];
/**
* Add method.
* @param structure - Structure representing the method.
*/
addMethod(structure: MethodDeclarationStructure): MethodDeclaration;
/**
* Add methods.
* @param structures - Structures representing the methods.
*/
addMethods(structures: MethodDeclarationStructure[]): MethodDeclaration[];
/**
* Insert method.
* @param index - Index to insert at.
* @param structure - Structure representing the method.
*/
insertMethod(index: number, structure: MethodDeclarationStructure): MethodDeclaration;
/**
* Insert methods.
* @param index - Index to insert at.
* @param structures - Structures representing the methods.
*/
insertMethods(index: number, structures: MethodDeclarationStructure[]): MethodDeclaration[];
/**
* Gets the first instance method by name.
* @param name - Name.
*/
getInstanceMethod(name: string): MethodDeclaration | undefined;
/**
* Gets the first instance method by a find function.
* @param findFunction - Function to find an instance method by.
*/
getInstanceMethod(findFunction: (method: MethodDeclaration) => boolean): MethodDeclaration | undefined;
/**
* Gets the first instance method by name or throws if not found.
* @param name - Name.
*/
getInstanceMethodOrThrow(name: string): MethodDeclaration;
/**
* Gets the first instance method by a find function. or throws if not found.
* @param findFunction - Function to find an instance method by.
*/
getInstanceMethodOrThrow(findFunction: (method: MethodDeclaration) => boolean): MethodDeclaration;
/**
* Gets the class instance method declarations.
*/
getInstanceMethods(): MethodDeclaration[];
/**
* Gets the first static method by name.
* @param name - Name.
*/
getStaticMethod(name: string): MethodDeclaration | undefined;
/**
* Gets the first static method by a find function.
* @param findFunction - Function to find a static method by.
*/
getStaticMethod(findFunction: (method: MethodDeclaration) => boolean): MethodDeclaration | undefined;
/**
* Gets the first static method by name or throws if not found.
* @param name - Name.
*/
getStaticMethodOrThrow(name: string): MethodDeclaration;
/**
* Gets the first static method by a find function. or throws if not found.
* @param findFunction - Function to find a static method by.
*/
getStaticMethodOrThrow(findFunction: (method: MethodDeclaration) => boolean): MethodDeclaration;
/**
* Gets the class instance method declarations.
*/
getStaticMethods(): MethodDeclaration[];
/**
* Gets the first instance member by name.
* @param name - Name.
*/
getInstanceMember(name: string): ClassInstanceMemberTypes | undefined;
/**
* Gets the first instance member by a find function.
* @param findFunction - Function to find the instance member by.
*/
getInstanceMember(findFunction: (member: ClassInstanceMemberTypes) => boolean): ClassInstanceMemberTypes | undefined;
/**
* Gets the first instance member by name or throws if not found.
* @param name - Name.
*/
getInstanceMemberOrThrow(name: string): ClassInstanceMemberTypes;
/**
* Gets the first instance member by a find function. or throws if not found.
* @param findFunction - Function to find the instance member by.
*/
getInstanceMemberOrThrow(findFunction: (member: ClassInstanceMemberTypes) => boolean): ClassInstanceMemberTypes;
/**
* Gets the instance members.
*/
getInstanceMembers(): (GetAccessorDeclaration | MethodDeclaration | ParameterDeclaration | PropertyDeclaration | SetAccessorDeclaration)[];
/**
* Gets the first static member by name.
* @param name - Name.
*/
getStaticMember(name: string): ClassStaticMemberTypes | undefined;
/**
* Gets the first static member by a find function.
* @param findFunction - Function to find an static method by.
*/
getStaticMember(findFunction: (member: ClassStaticMemberTypes) => boolean): ClassStaticMemberTypes | undefined;
/**
* Gets the first static member by name or throws if not found.
* @param name - Name.
*/
getStaticMemberOrThrow(name: string): ClassStaticMemberTypes;
/**
* Gets the first static member by a find function. or throws if not found.
* @param findFunction - Function to find an static method by.
*/
getStaticMemberOrThrow(findFunction: (member: ClassStaticMemberTypes) => boolean): ClassStaticMemberTypes;
/**
* Gets the static members.
*/
getStaticMembers(): (GetAccessorDeclaration | MethodDeclaration | PropertyDeclaration | SetAccessorDeclaration)[];
/**
* Gets the constructors, methods, properties, and class parameter properties.
*/
getAllMembers(): ClassMemberTypes[];
/**
* Gets all the derived classes.
*/
getDerivedClasses(): ClassDeclaration[];
/**
* Removes this class declaration.
*/
remove(): void;
private getImmediateDerivedClasses();
private getBodyMembers();
}