UNPKG

5.13 kBTypeScriptView Raw
1import * as ts from '@schematics/angular/third_party/github.com/Microsoft/TypeScript/lib/typescript';
2import { Change } from './change';
3/**
4 * Add Import `import { symbolName } from fileName` if the import doesn't exit
5 * already. Assumes fileToEdit can be resolved and accessed.
6 * @param fileToEdit (file we want to add import to)
7 * @param symbolName (item to import)
8 * @param fileName (path to the file)
9 * @param isDefault (if true, import follows style for importing default exports)
10 * @return Change
11 */
12export declare function insertImport(source: ts.SourceFile, fileToEdit: string, symbolName: string, fileName: string, isDefault?: boolean): Change;
13/**
14 * Find all nodes from the AST in the subtree of node of SyntaxKind kind.
15 * @param node
16 * @param kind
17 * @param max The maximum number of items to return.
18 * @param recursive Continue looking for nodes of kind recursive until end
19 * the last child even when node of kind has been found.
20 * @return all nodes of kind, or [] if none is found
21 */
22export declare function findNodes(node: ts.Node, kind: ts.SyntaxKind, max?: number, recursive?: boolean): ts.Node[];
23/**
24 * Get all the nodes from a source.
25 * @param sourceFile The source file object.
26 * @returns {Observable<ts.Node>} An observable of all the nodes in the source.
27 */
28export declare function getSourceNodes(sourceFile: ts.SourceFile): ts.Node[];
29export declare function findNode(node: ts.Node, kind: ts.SyntaxKind, text: string): ts.Node | null;
30/**
31 * Insert `toInsert` after the last occurence of `ts.SyntaxKind[nodes[i].kind]`
32 * or after the last of occurence of `syntaxKind` if the last occurence is a sub child
33 * of ts.SyntaxKind[nodes[i].kind] and save the changes in file.
34 *
35 * @param nodes insert after the last occurence of nodes
36 * @param toInsert string to insert
37 * @param file file to insert changes into
38 * @param fallbackPos position to insert if toInsert happens to be the first occurence
39 * @param syntaxKind the ts.SyntaxKind of the subchildren to insert after
40 * @return Change instance
41 * @throw Error if toInsert is first occurence but fall back is not set
42 */
43export declare function insertAfterLastOccurrence(nodes: ts.Node[], toInsert: string, file: string, fallbackPos: number, syntaxKind?: ts.SyntaxKind): Change;
44export declare function getContentOfKeyLiteral(_source: ts.SourceFile, node: ts.Node): string | null;
45export declare function getDecoratorMetadata(source: ts.SourceFile, identifier: string, module: string): ts.Node[];
46/**
47 * Given a source file with @NgModule class(es), find the name of the first @NgModule class.
48 *
49 * @param source source file containing one or more @NgModule
50 * @returns the name of the first @NgModule, or `undefined` if none is found
51 */
52export declare function getFirstNgModuleName(source: ts.SourceFile): string | undefined;
53export declare function getMetadataField(node: ts.ObjectLiteralExpression, metadataField: string): ts.ObjectLiteralElement[];
54export declare function addSymbolToNgModuleMetadata(source: ts.SourceFile, ngModulePath: string, metadataField: string, symbolName: string, importPath?: string | null): Change[];
55/**
56 * Custom function to insert a declaration (component, pipe, directive)
57 * into NgModule declarations. It also imports the component.
58 */
59export declare function addDeclarationToModule(source: ts.SourceFile, modulePath: string, classifiedName: string, importPath: string): Change[];
60/**
61 * Custom function to insert an NgModule into NgModule imports. It also imports the module.
62 */
63export declare function addImportToModule(source: ts.SourceFile, modulePath: string, classifiedName: string, importPath: string): Change[];
64/**
65 * Custom function to insert a provider into NgModule. It also imports it.
66 */
67export declare function addProviderToModule(source: ts.SourceFile, modulePath: string, classifiedName: string, importPath: string): Change[];
68/**
69 * Custom function to insert an export into NgModule. It also imports it.
70 */
71export declare function addExportToModule(source: ts.SourceFile, modulePath: string, classifiedName: string, importPath: string): Change[];
72/**
73 * Custom function to insert an export into NgModule. It also imports it.
74 */
75export declare function addBootstrapToModule(source: ts.SourceFile, modulePath: string, classifiedName: string, importPath: string): Change[];
76/**
77 * Custom function to insert an entryComponent into NgModule. It also imports it.
78 */
79export declare function addEntryComponentToModule(source: ts.SourceFile, modulePath: string, classifiedName: string, importPath: string): Change[];
80/**
81 * Determine if an import already exists.
82 */
83export declare function isImported(source: ts.SourceFile, classifiedName: string, importPath: string): boolean;
84/**
85 * Returns the RouterModule declaration from NgModule metadata, if any.
86 */
87export declare function getRouterModuleDeclaration(source: ts.SourceFile): ts.Expression | undefined;
88/**
89 * Adds a new route declaration to a router module (i.e. has a RouterModule declaration)
90 */
91export declare function addRouteDeclarationToModule(source: ts.SourceFile, fileToAdd: string, routeLiteral: string): Change;