UNPKG

@o3r/schematics

Version:

Schematics module of the Otter framework

127 lines 5.01 kB
import * as ts from 'typescript'; /** * Find the first node with the specific syntax kind * @param sourceFile Typescript file * @param searchKind Kind of syntax to look up * @param node current node */ export declare function findFirstNodeOfKind<T extends ts.Node = ts.Node>(sourceFile: ts.SourceFile, searchKind: ts.SyntaxKind, node?: ts.Node): T | null; /** * Find the last node with the specific syntax kind * @param sourceFile Typescript file * @param searchKind Kind of syntax to look up * @param node current node */ export declare function findLastNodeOfKind<T extends ts.Node = ts.Node>(sourceFile: ts.SourceFile, searchKind: ts.SyntaxKind, node?: ts.Node): T | null; /** * Reads all the imports of a given SourceFile and returns a parsed list that's easy to consume. * @param sourceFile */ export declare function parseImportsFromFile(sourceFile: ts.SourceFile): { node: ts.ImportDeclaration; symbols: string[]; module: string; }[]; /** * Given a program and a path to a source file, returns all the Symbols exported by the file. * @param program * @param sourcePath */ export declare function getExportedSymbolsFromFile(program: ts.Program, sourcePath: string): ts.Symbol[]; /** * Decorator with arguments * @example * ```typescript * \@Decorator({ propName: 'value' }) * ``` */ export type DecoratorWithArg = ts.Decorator & { expression: ts.CallExpression & { expression: ts.Identifier; }; }; /** * Returns true if it is a decorator with arguments * @param node decorator node */ export declare const isDecoratorWithArg: (node: ts.Node) => node is DecoratorWithArg; /** * Returns the value of {@link argName} in the first argument * @param decorator * @param argName */ export declare const getPropertyFromDecoratorFirstArgument: (decorator: DecoratorWithArg, argName: string) => ts.Expression | undefined; /** * Returns `ExpressionWithTypeArguments[]` of a class that implements {@link str} * @param str */ export declare const generateImplementsExpressionWithTypeArguments: (str: string) => ts.ExpressionWithTypeArguments[]; /** * Returns `ClassElement[]` of a class that have {@link str} has body * @param str */ export declare const generateClassElementsFromString: (str: string) => ts.ClassElement[]; /** * Returns `Statement[]` of a function that have {@link str} has body * @param str */ export declare const generateBlockStatementsFromString: (str: string) => ts.Statement[]; /** * Returns `ParameterDeclaration[]` of a function that have {@link str} has parameters * @param str */ export declare const generateParametersDeclarationFromString: (str: string) => ts.ParameterDeclaration[]; /** * Method to sort ClassElement based on the kind of it * order will be PropertyDeclaration, Constructor then MethodDeclaration * @param classElement1 * @param classElement2 */ export declare const sortClassElement: (classElement1: ts.ClassElement, classElement2: ts.ClassElement) => 1 | -1; /** * Returns a TransformerFactory to add an interface to a class * @param interfaceToAdd * @param classIdentifier * @param interfacesToRemove */ export declare const addInterfaceToClassTransformerFactory: (interfaceToAdd: string, classIdentifier?: (node: ts.ClassDeclaration) => boolean, interfacesToRemove?: Set<string>) => ts.TransformerFactory<ts.Node>; /** * Add comment on class properties * @param classElements * @param comments Dictionary of comment indexed by properties' name */ export declare const addCommentsOnClassProperties: (classElements: ts.ClassElement[], comments: Record<string, string>) => void; /** * Transformer to be used to fix the string literals generated by creating a new SourceFile (for instance, using #generateClassElementsFromString) * @param ctx */ export declare const fixStringLiterals: ts.TransformerFactory<ts.Node>; /** * Returns a function to match classElement by method name * @param methodName */ export declare const findMethodByName: (methodName: string) => (classElement: ts.ClassElement) => classElement is ts.MethodDeclaration; /** * Add block statements to a method * @param node * @param factory * @param methodName * @param blockStatements */ export declare const getSimpleUpdatedMethod: (node: ts.ClassDeclaration, factory: ts.NodeFactory, methodName: string, blockStatements: ts.Statement[]) => ts.MethodDeclaration; /** * Return true is the node is the ExpressionStatement of the TestBedConfiguration * @param node */ export declare const isTestBedConfiguration: (node: ts.Node) => node is ts.ExpressionStatement & { expression: ts.CallExpression & { expression: ts.PropertyAccessExpression; }; }; /** * TransformerFactory to add imports at spec initialization and code to be run just after * @param imports * @param code */ export declare const addImportsAndCodeBlockStatementAtSpecInitializationTransformerFactory: (imports: (string | ts.Expression)[], code?: string) => ts.TransformerFactory<ts.Node>; //# sourceMappingURL=ast.d.ts.map