UNPKG

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