UNPKG

6.53 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const ast_utils_1 = require("@schematics/angular/utility/ast-utils");
4/**
5 * Add Import `import { symbolName } from fileName` if the import doesn't exit
6 * already. Assumes fileToEdit can be resolved and accessed.
7 * @param fileToEdit (file we want to add import to)
8 * @param symbolName (item to import)
9 * @param fileName (path to the file)
10 * @param isDefault (if true, import follows style for importing default exports)
11 * @return Change
12 */
13function insertImport(source, fileToEdit, symbolName, fileName, isDefault = false) {
14 return ast_utils_1.insertImport(source, fileToEdit, symbolName, fileName, isDefault);
15}
16exports.insertImport = insertImport;
17/**
18 * Find all nodes from the AST in the subtree of node of SyntaxKind kind.
19 * @param node
20 * @param kind
21 * @param max The maximum number of items to return.
22 * @param recursive Continue looking for nodes of kind recursive until end
23 * the last child even when node of kind has been found.
24 * @return all nodes of kind, or [] if none is found
25 */
26function findNodes(node, kind, max = Infinity, recursive = false) {
27 return ast_utils_1.findNodes(node, kind, max, recursive);
28}
29exports.findNodes = findNodes;
30/**
31 * Get all the nodes from a source.
32 * @param sourceFile The source file object.
33 * @returns {Observable<ts.Node>} An observable of all the nodes in the source.
34 */
35function getSourceNodes(sourceFile) {
36 return ast_utils_1.getSourceNodes(sourceFile);
37}
38exports.getSourceNodes = getSourceNodes;
39function findNode(node, kind, text) {
40 return ast_utils_1.findNode(node, kind, text);
41}
42exports.findNode = findNode;
43/**
44 * Insert `toInsert` after the last occurence of `ts.SyntaxKind[nodes[i].kind]`
45 * or after the last of occurence of `syntaxKind` if the last occurence is a sub child
46 * of ts.SyntaxKind[nodes[i].kind] and save the changes in file.
47 *
48 * @param nodes insert after the last occurence of nodes
49 * @param toInsert string to insert
50 * @param file file to insert changes into
51 * @param fallbackPos position to insert if toInsert happens to be the first occurence
52 * @param syntaxKind the ts.SyntaxKind of the subchildren to insert after
53 * @return Change instance
54 * @throw Error if toInsert is first occurence but fall back is not set
55 */
56function insertAfterLastOccurrence(nodes, toInsert, file, fallbackPos, syntaxKind) {
57 return ast_utils_1.insertAfterLastOccurrence(nodes, toInsert, file, fallbackPos, syntaxKind);
58}
59exports.insertAfterLastOccurrence = insertAfterLastOccurrence;
60function getContentOfKeyLiteral(_source, node) {
61 return ast_utils_1.getContentOfKeyLiteral(_source, node);
62}
63exports.getContentOfKeyLiteral = getContentOfKeyLiteral;
64function getDecoratorMetadata(source, identifier, module) {
65 return ast_utils_1.getDecoratorMetadata(source, identifier, module);
66}
67exports.getDecoratorMetadata = getDecoratorMetadata;
68/**
69 * Given a source file with @NgModule class(es), find the name of the first @NgModule class.
70 *
71 * @param source source file containing one or more @NgModule
72 * @returns the name of the first @NgModule, or `undefined` if none is found
73 */
74function getFirstNgModuleName(source) {
75 return ast_utils_1.getFirstNgModuleName(source);
76}
77exports.getFirstNgModuleName = getFirstNgModuleName;
78function getMetadataField(node, metadataField) {
79 return ast_utils_1.getMetadataField(node, metadataField);
80}
81exports.getMetadataField = getMetadataField;
82function addSymbolToNgModuleMetadata(source, ngModulePath, metadataField, symbolName, importPath = null) {
83 return ast_utils_1.addSymbolToNgModuleMetadata(source, ngModulePath, metadataField, symbolName, importPath);
84}
85exports.addSymbolToNgModuleMetadata = addSymbolToNgModuleMetadata;
86/**
87 * Custom function to insert a declaration (component, pipe, directive)
88 * into NgModule declarations. It also imports the component.
89 */
90function addDeclarationToModule(source, modulePath, classifiedName, importPath) {
91 return ast_utils_1.addDeclarationToModule(source, modulePath, classifiedName, importPath);
92}
93exports.addDeclarationToModule = addDeclarationToModule;
94/**
95 * Custom function to insert an NgModule into NgModule imports. It also imports the module.
96 */
97function addImportToModule(source, modulePath, classifiedName, importPath) {
98 return ast_utils_1.addImportToModule(source, modulePath, classifiedName, importPath);
99}
100exports.addImportToModule = addImportToModule;
101/**
102 * Custom function to insert a provider into NgModule. It also imports it.
103 */
104function addProviderToModule(source, modulePath, classifiedName, importPath) {
105 return ast_utils_1.addProviderToModule(source, modulePath, classifiedName, importPath);
106}
107exports.addProviderToModule = addProviderToModule;
108/**
109 * Custom function to insert an export into NgModule. It also imports it.
110 */
111function addExportToModule(source, modulePath, classifiedName, importPath) {
112 return ast_utils_1.addExportToModule(source, modulePath, classifiedName, importPath);
113}
114exports.addExportToModule = addExportToModule;
115/**
116 * Custom function to insert an export into NgModule. It also imports it.
117 */
118function addBootstrapToModule(source, modulePath, classifiedName, importPath) {
119 return ast_utils_1.addBootstrapToModule(source, modulePath, classifiedName, importPath);
120}
121exports.addBootstrapToModule = addBootstrapToModule;
122/**
123 * Custom function to insert an entryComponent into NgModule. It also imports it.
124 */
125function addEntryComponentToModule(source, modulePath, classifiedName, importPath) {
126 return ast_utils_1.addEntryComponentToModule(source, modulePath, classifiedName, importPath);
127}
128exports.addEntryComponentToModule = addEntryComponentToModule;
129/**
130 * Determine if an import already exists.
131 */
132function isImported(source, classifiedName, importPath) {
133 return ast_utils_1.isImported(source, classifiedName, importPath);
134}
135exports.isImported = isImported;
136/**
137 * Returns the RouterModule declaration from NgModule metadata, if any.
138 */
139function getRouterModuleDeclaration(source) {
140 return ast_utils_1.getRouterModuleDeclaration(source);
141}
142exports.getRouterModuleDeclaration = getRouterModuleDeclaration;
143/**
144 * Adds a new route declaration to a router module (i.e. has a RouterModule declaration)
145 */
146function addRouteDeclarationToModule(source, fileToAdd, routeLiteral) {
147 return ast_utils_1.addRouteDeclarationToModule(source, fileToAdd, routeLiteral);
148}
149exports.addRouteDeclarationToModule = addRouteDeclarationToModule;
150//# sourceMappingURL=ast-utils.js.map
\No newline at end of file