UNPKG

ts-simple-ast

Version:

TypeScript compiler wrapper for AST navigation and code generation.

58 lines (57 loc) 2.23 kB
import * as ts from "typescript"; import { Constructor } from "./../../Constructor"; import { DecoratorStructure } from "./../../structures"; import { Node } from "./../common"; import { Decorator } from "./../decorator/Decorator"; export declare type DecoratableNodeExtensionType = Node<ts.Node & { decorators: ts.NodeArray<ts.Decorator> | undefined; }>; export interface DecoratableNode { /** * Gets a decorator or undefined if it doesn't exist. * @param name - Name of the parameter. */ getDecorator(name: string): Decorator | undefined; /** * Gets a decorator or undefined if it doesn't exist. * @param findFunction - Function to use to find the parameter. */ getDecorator(findFunction: (declaration: Decorator) => boolean): Decorator | undefined; /** * Gets a decorator or throws if it doesn't exist. * @param name - Name of the parameter. */ getDecoratorOrThrow(name: string): Decorator; /** * Gets a decorator or throws if it doesn't exist. * @param findFunction - Function to use to find the parameter. */ getDecoratorOrThrow(findFunction: (declaration: Decorator) => boolean): Decorator; /** * Gets all the decorators of the node. */ getDecorators(): Decorator[]; /** * Adds a decorator. * @param structure - Structure of the decorator. */ addDecorator(structure: DecoratorStructure): Decorator; /** * Adds decorators. * @param structures - Structures of the decorators. */ addDecorators(structures: DecoratorStructure[]): Decorator[]; /** * Inserts a decorator. * @param index - Index to insert at. Specify a negative index to insert from the reverse. * @param structure - Structure of the decorator. */ insertDecorator(index: number, structure: DecoratorStructure): Decorator; /** * Insert decorators. * @param index - Index to insert at. * @param structures - Structures to insert. */ insertDecorators(index: number, structures: DecoratorStructure[]): Decorator[]; } export declare function DecoratableNode<T extends Constructor<DecoratableNodeExtensionType>>(Base: T): Constructor<DecoratableNode> & T;