@magic-xpa/cli 4.1201.0 → 4.1201.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (183) hide show
  1. package/README.md +28 -28
  2. package/index.js.map +1 -1
  3. package/index.ts +1 -1
  4. package/package.json +1 -1
  5. package/src/collection.json +75 -75
  6. package/src/public_api.js.map +1 -1
  7. package/src/public_api.ts +5 -5
  8. package/src/schematics/magic-utils/config.js.map +1 -1
  9. package/src/schematics/magic-utils/config.ts +68 -68
  10. package/src/schematics/magic-utils/env.js.map +1 -1
  11. package/src/schematics/magic-utils/env.ts +50 -50
  12. package/src/schematics/magic-utils/manifest.js.map +1 -1
  13. package/src/schematics/magic-utils/manifest.ts +46 -46
  14. package/src/schematics/magic-utils/metadata.class.js.map +1 -1
  15. package/src/schematics/magic-utils/metadata.class.ts +159 -159
  16. package/src/schematics/magic-utils/rules/generate.rule.js.map +1 -1
  17. package/src/schematics/magic-utils/rules/generate.rule.ts +61 -61
  18. package/src/schematics/magic-utils/rules/init-add-modules.rule.js.map +1 -1
  19. package/src/schematics/magic-utils/rules/init-add-modules.rule.ts +360 -360
  20. package/src/schematics/magic-utils/rules/init-magic-metadata.rule.js.map +1 -1
  21. package/src/schematics/magic-utils/rules/init-magic-metadata.rule.ts +19 -19
  22. package/src/schematics/magic-utils/rules/magic-option.scheme.js.map +1 -1
  23. package/src/schematics/magic-utils/rules/magic-option.scheme.ts +24 -24
  24. package/src/schematics/magic-utils/utils.js.map +1 -1
  25. package/src/schematics/magic-utils/utils.ts +134 -134
  26. package/src/schematics/mg-Install-prerequisites/index.js.map +1 -1
  27. package/src/schematics/mg-Install-prerequisites/index.ts +30 -30
  28. package/src/schematics/mg-Install-prerequisites/schema.json +14 -14
  29. package/src/schematics/mg-add/files/src/app/app.component.html +17 -17
  30. package/src/schematics/mg-add/files/src/app/app.routes.ts +14 -14
  31. package/src/schematics/mg-add/files/src/app/magic/component-list.g.ts +9 -9
  32. package/src/schematics/mg-add/files/src/magic-styles.css +131 -131
  33. package/src/schematics/mg-add/schema.json +29 -29
  34. package/src/schematics/mg-add/utils/add-declaration-to-root-module.js.map +1 -1
  35. package/src/schematics/mg-add/utils/add-declaration-to-root-module.ts +12 -12
  36. package/src/schematics/mg-add/webModule/app.routes.ts +14 -14
  37. package/src/schematics/mg-add-tasks/index.js.map +1 -1
  38. package/src/schematics/mg-add-tasks/index.ts +53 -53
  39. package/src/schematics/mg-add-tasks/schema.json +41 -41
  40. package/src/schematics/mg-delete-files/index.js.map +1 -1
  41. package/src/schematics/mg-delete-files/index.ts +12 -12
  42. package/src/schematics/mg-delete-files/schema.json +14 -14
  43. package/src/schematics/mg-gen-module/index.js.map +1 -1
  44. package/src/schematics/mg-gen-module/index.ts +14 -14
  45. package/src/schematics/mg-gen-module/schema.json +24 -24
  46. package/src/schematics/mg-generate/index.js.map +1 -1
  47. package/src/schematics/mg-generate/index.ts +12 -12
  48. package/src/schematics/mg-generate/schema.json +34 -34
  49. package/src/schematics/mg-install/index.js.map +1 -1
  50. package/src/schematics/mg-install/index.ts +37 -37
  51. package/src/schematics/mg-install/schema.json +24 -24
  52. package/src/schematics/mg-routes/schema.json +14 -14
  53. package/src/schematics/mg-single-control/schema.json +24 -24
  54. package/src/schematics/utils/ast.js.map +1 -1
  55. package/src/schematics/utils/ast.ts +103 -103
  56. package/src/schematics/utils/devkit-utils/README.md +1 -1
  57. package/src/schematics/utils/devkit-utils/ast-utils.js.map +1 -1
  58. package/src/schematics/utils/devkit-utils/ast-utils.ts +570 -570
  59. package/src/schematics/utils/devkit-utils/ast-utils_old.js.map +1 -1
  60. package/src/schematics/utils/devkit-utils/ast-utils_old.ts +478 -478
  61. package/src/schematics/utils/devkit-utils/change.js.map +1 -1
  62. package/src/schematics/utils/devkit-utils/change.ts +127 -127
  63. package/src/schematics/utils/devkit-utils/component.js.map +1 -1
  64. package/src/schematics/utils/devkit-utils/component.ts +136 -136
  65. package/src/schematics/utils/devkit-utils/config.js.map +1 -1
  66. package/src/schematics/utils/devkit-utils/config.ts +120 -120
  67. package/src/schematics/utils/devkit-utils/find-module.js.map +1 -1
  68. package/src/schematics/utils/devkit-utils/find-module.ts +108 -108
  69. package/src/schematics/utils/devkit-utils/ng-ast-utils.js.map +1 -1
  70. package/src/schematics/utils/devkit-utils/ng-ast-utils.ts +84 -84
  71. package/src/schematics/utils/devkit-utils/parse-name.js.map +1 -1
  72. package/src/schematics/utils/devkit-utils/parse-name.ts +24 -24
  73. package/src/schematics/utils/devkit-utils/route-utils.js.map +1 -1
  74. package/src/schematics/utils/devkit-utils/route-utils.ts +180 -180
  75. package/src/schematics/utils/devkit-utils/validation.js +1 -1
  76. package/src/schematics/utils/devkit-utils/validation.js.map +1 -1
  77. package/src/schematics/utils/devkit-utils/validation.ts +16 -16
  78. package/src/schematics/utils/html.js.map +1 -1
  79. package/src/schematics/utils/html.ts +63 -63
  80. package/src/schematics/utils/lib-versions.js.map +1 -1
  81. package/src/schematics/utils/lib-versions.ts +3 -3
  82. package/src/schematics/utils/package.js.map +1 -1
  83. package/src/schematics/utils/package.ts +22 -22
  84. package/src/schematics/utils/testing.js.map +1 -1
  85. package/src/schematics/utils/testing.ts +25 -25
  86. package/src/types/enums/Enums.js.map +1 -1
  87. package/src/types/enums/Enums.ts +2063 -2063
  88. package/src/types/enums/generated-file-types.enum.js.map +1 -1
  89. package/src/types/enums/generated-file-types.enum.ts +6 -6
  90. package/src/types/enums/horizontal-alignments.enum.js.map +1 -1
  91. package/src/types/enums/horizontal-alignments.enum.ts +6 -6
  92. package/src/types/enums/themes.enum.js.map +1 -1
  93. package/src/types/enums/themes.enum.ts +6 -6
  94. package/src/types/index.js.map +1 -1
  95. package/src/types/index.ts +8 -8
  96. package/src/types/interfaces/app.js.map +1 -1
  97. package/src/types/interfaces/app.ts +89 -89
  98. package/src/types/interfaces/control.js.map +1 -1
  99. package/src/types/interfaces/control.ts +106 -106
  100. package/src/types/interfaces/template.config.js.map +1 -1
  101. package/src/types/interfaces/template.config.ts +11 -11
  102. package/templates/angular/src/app/app.component.html.ejs +17 -17
  103. package/templates/angular/src/app/cmp-array.ejs +3 -3
  104. package/templates/angular/src/app/cmp-hash.ejs +3 -3
  105. package/templates/angular/src/app/component-list.g.ts +21 -21
  106. package/templates/angular/src/app.component.ts +16 -16
  107. package/templates/angular/src/app.module.ts +70 -70
  108. package/templates/angular/src/app.routes.ts +73 -73
  109. package/templates/angular/src/styles/app.css +5 -5
  110. package/templates/attributes/button_attributes.ejs +2 -2
  111. package/templates/attributes/common/base/class.ejs +6 -6
  112. package/templates/attributes/common/base/control_type.ejs +53 -53
  113. package/templates/attributes/common/base/enabled.ejs +9 -9
  114. package/templates/attributes/common/base/imageFileName.ejs +3 -3
  115. package/templates/attributes/common/base/no_control_class.ejs +3 -3
  116. package/templates/attributes/common/base/rtol.ejs +3 -3
  117. package/templates/attributes/common/base/tabindex.ejs +11 -11
  118. package/templates/attributes/common/base/testingId.ejs +8 -8
  119. package/templates/attributes/common/base/tooltip.ejs +7 -7
  120. package/templates/attributes/common/base/visible.ejs +6 -6
  121. package/templates/attributes/common/base/wallpaper.ejs +3 -3
  122. package/templates/attributes/common/base_attributes.ejs +10 -10
  123. package/templates/attributes/common/container_attributes.ejs +6 -6
  124. package/templates/attributes/common/control_attributes.ejs +3 -3
  125. package/templates/attributes/common/format.ejs +5 -5
  126. package/templates/attributes/common/input/hint.ejs +13 -13
  127. package/templates/attributes/common/input/multiline_edit.ejs +3 -3
  128. package/templates/attributes/common/input/must_input.ejs +8 -8
  129. package/templates/attributes/common/input/password_edit.ejs +7 -7
  130. package/templates/attributes/common/input/row_editing_input_attributes.ejs +6 -6
  131. package/templates/attributes/common/input/validation.ejs +5 -5
  132. package/templates/attributes/common/input_attributes.ejs +4 -4
  133. package/templates/attributes/common/no_control_base_attributes.ejs +4 -4
  134. package/templates/attributes/common/row_editing_button_attributes.ejs +10 -10
  135. package/templates/component/view.component.html +14 -14
  136. package/templates/component/view.component.ts +136 -136
  137. package/templates/themes/basicHTML/Code/theme.module.ts +10 -10
  138. package/templates/themes/basicHTML/combobox.ejs +37 -37
  139. package/templates/themes/basicHTML/edit.ejs +169 -169
  140. package/templates/themes/basicHTML/form.ejs +4 -4
  141. package/templates/themes/basicHTML/group.ejs +4 -4
  142. package/templates/themes/basicHTML/image.ejs +6 -6
  143. package/templates/themes/basicHTML/label.ejs +11 -11
  144. package/templates/themes/basicHTML/listbox.ejs +21 -21
  145. package/templates/themes/basicHTML/push-button.ejs +28 -28
  146. package/templates/themes/basicHTML/radio.ejs +20 -20
  147. package/templates/themes/basicHTML/subform.ejs +6 -6
  148. package/templates/themes/basicHTML/tab.ejs +31 -31
  149. package/templates/themes/basicHTML/tabpage.ejs +5 -5
  150. package/templates/themes/basicHiddenHTML/Code/theme.module.ts +10 -10
  151. package/templates/themes/basicHiddenHTML/combobox.ejs +5 -5
  152. package/templates/themes/basicHiddenHTML/form.ejs +3 -3
  153. package/templates/themes/basicHiddenHTML/group.ejs +2 -2
  154. package/templates/themes/basicHiddenHTML/image.ejs +4 -4
  155. package/templates/themes/basicHiddenHTML/label.ejs +1 -1
  156. package/templates/themes/basicHiddenHTML/listbox.ejs +8 -8
  157. package/templates/themes/basicHiddenHTML/push-button.ejs +26 -26
  158. package/templates/themes/basicHiddenHTML/radio.ejs +17 -17
  159. package/templates/themes/basicHiddenHTML/tab.ejs +13 -13
  160. package/templates/themes/basicHiddenHTML/table.ejs +18 -18
  161. package/templates/themes/basicHiddenHTML/tabpage.ejs +2 -2
  162. package/templates/themes/container.ejs +26 -26
  163. package/templates/themes/control.ejs +52 -52
  164. package/templates/themes/editTypeSelector.ejs +1 -1
  165. package/templates/themes/material/Code/theme.module.ts +68 -68
  166. package/templates/themes/material/base_attributes_date.ejs +8 -8
  167. package/templates/themes/material/combobox.ejs +58 -58
  168. package/templates/themes/material/edit.ejs +204 -204
  169. package/templates/themes/material/group.ejs +3 -3
  170. package/templates/themes/material/listbox.ejs +22 -22
  171. package/templates/themes/material/push-button.ejs +28 -28
  172. package/templates/themes/material/radio.ejs +22 -22
  173. package/templates/themes/material/subform.ejs +8 -8
  174. package/templates/themes/material/tab.ejs +19 -19
  175. package/templates/themes/router_outlet.ejs +5 -5
  176. package/templates/themes/table/HTMLTable/table.ejs +37 -37
  177. package/templates/themes/table/grid/additionalComponentCode.ejs +26 -26
  178. package/templates/themes/table/grid/additionalIncludes.ejs +1 -1
  179. package/templates/themes/table/grid/table.ejs +37 -37
  180. package/templates/themes/table/repeatable/column.ejs +11 -11
  181. package/templates/themes/table/repeatable/table.ejs +28 -28
  182. package/templates/themes/tableTypeSelector.ejs +21 -21
  183. package/tsconfig.json +36 -36
@@ -1,478 +1,478 @@
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
- */
8
- import * as ts from 'typescript';
9
- import { Change, InsertChange } from './change';
10
- import { insertImport } from './route-utils';
11
-
12
-
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
- * @return all nodes of kind, or [] if none is found
19
- */
20
- export function findNodes(node: ts.Node, kind: ts.SyntaxKind, max = Infinity): ts.Node[] {
21
- if (!node || max == 0) {
22
- return [];
23
- }
24
-
25
- const arr: ts.Node[] = [];
26
- if (node.kind === kind) {
27
- arr.push(node);
28
- max--;
29
- }
30
- if (max > 0) {
31
- for (const child of node.getChildren()) {
32
- findNodes(child, kind, max).forEach(node => {
33
- if (max > 0) {
34
- arr.push(node);
35
- }
36
- max--;
37
- });
38
-
39
- if (max <= 0) {
40
- break;
41
- }
42
- }
43
- }
44
-
45
- return arr;
46
- }
47
-
48
-
49
-
50
- export function getSourceNodes(sourceFile: ts.SourceFile): ts.Node[] {
51
- const nodes: ts.Node[] = [sourceFile];
52
- const result = [];
53
-
54
- while (nodes.length > 0) {
55
- const node = nodes.shift();
56
-
57
- if (node) {
58
- result.push(node);
59
- if (node.getChildCount(sourceFile) >= 0) {
60
- nodes.unshift(...node.getChildren());
61
- }
62
- }
63
- }
64
-
65
- return result;
66
- }
67
-
68
- export function findNode(node: ts.Node, kind: ts.SyntaxKind, text: string): ts.Node | null {
69
- if (node.kind === kind && node.getText() === text) {
70
- // throw new Error(node.getText());
71
- return node;
72
- }
73
-
74
- let foundNode: ts.Node | null = null;
75
- ts.forEachChild(node, childNode => {
76
- foundNode = foundNode || findNode(childNode, kind, text);
77
- });
78
-
79
- return foundNode;
80
- }
81
-
82
-
83
- /**
84
- * Helper for sorting nodes.
85
- * @return function to sort nodes in increasing order of position in sourceFile
86
- */
87
- function nodesByPosition(first: ts.Node, second: ts.Node): number {
88
- return first.getStart() - second.getStart();
89
- }
90
-
91
-
92
- /**
93
- * Insert `toInsert` after the last occurence of `ts.SyntaxKind[nodes[i].kind]`
94
- * or after the last of occurence of `syntaxKind` if the last occurence is a sub child
95
- * of ts.SyntaxKind[nodes[i].kind] and save the changes in file.
96
- *
97
- * @param nodes insert after the last occurence of nodes
98
- * @param toInsert string to insert
99
- * @param file file to insert changes into
100
- * @param fallbackPos position to insert if toInsert happens to be the first occurence
101
- * @param syntaxKind the ts.SyntaxKind of the subchildren to insert after
102
- * @return Change instance
103
- * @throw Error if toInsert is first occurence but fall back is not set
104
- */
105
- export function insertAfterLastOccurrence(nodes: ts.Node[],
106
- toInsert: string,
107
- file: string,
108
- fallbackPos: number,
109
- syntaxKind?: ts.SyntaxKind): Change {
110
- let lastItem = nodes.sort(nodesByPosition).pop();
111
- if (!lastItem) {
112
- //throw new Error();
113
- // No imports exist....
114
- new InsertChange(file, 0, toInsert);
115
- }
116
- if (syntaxKind) {
117
- lastItem = findNodes(lastItem, syntaxKind).sort(nodesByPosition).pop();
118
- }
119
- if (!lastItem && fallbackPos == undefined) {
120
- throw new Error(`tried to insert ${toInsert} as first occurence with no fallback position`);
121
- }
122
- const lastItemPosition: number = lastItem ? lastItem.getEnd() : fallbackPos;
123
-
124
- return new InsertChange(file, lastItemPosition, toInsert);
125
- }
126
-
127
-
128
- export function getContentOfKeyLiteral(_source: ts.SourceFile, node: ts.Node): string | null {
129
- if (node.kind == ts.SyntaxKind.Identifier) {
130
- return (node as ts.Identifier).text;
131
- } else if (node.kind == ts.SyntaxKind.StringLiteral) {
132
- return (node as ts.StringLiteral).text;
133
- } else {
134
- return null;
135
- }
136
- }
137
-
138
-
139
- function _angularImportsFromNode(node: ts.ImportDeclaration,
140
- _sourceFile: ts.SourceFile): {[name: string]: string} {
141
- const ms = node.moduleSpecifier;
142
- let modulePath: string;
143
- switch (ms.kind) {
144
- case ts.SyntaxKind.StringLiteral:
145
- modulePath = (ms as ts.StringLiteral).text;
146
- break;
147
- default:
148
- return {};
149
- }
150
-
151
- if (!modulePath.startsWith('@angular/')) {
152
- return {};
153
- }
154
-
155
- if (node.importClause) {
156
- if (node.importClause.name) {
157
- // This is of the form `import Name from 'path'`. Ignore.
158
- return {};
159
- } else if (node.importClause.namedBindings) {
160
- const nb = node.importClause.namedBindings;
161
- if (nb.kind == ts.SyntaxKind.NamespaceImport) {
162
- // This is of the form `import * as name from 'path'`. Return `name.`.
163
- return {
164
- [(nb as ts.NamespaceImport).name.text + '.']: modulePath,
165
- };
166
- } else {
167
- // This is of the form `import {a,b,c} from 'path'`
168
- const namedImports = nb as ts.NamedImports;
169
-
170
- return namedImports.elements
171
- .map((is: ts.ImportSpecifier) => is.propertyName ? is.propertyName.text : is.name.text)
172
- .reduce((acc: {[name: string]: string}, curr: string) => {
173
- acc[curr] = modulePath;
174
-
175
- return acc;
176
- }, {});
177
- }
178
- }
179
-
180
- return {};
181
- } else {
182
- // This is of the form `import 'path';`. Nothing to do.
183
- return {};
184
- }
185
- }
186
-
187
-
188
- export function getDecoratorMetadata(source: ts.SourceFile, identifier: string,
189
- module: string): ts.Node[] {
190
- const angularImports: {[name: string]: string}
191
- = findNodes(source, ts.SyntaxKind.ImportDeclaration)
192
- .map((node: ts.ImportDeclaration) => _angularImportsFromNode(node, source))
193
- .reduce((acc: {[name: string]: string}, current: {[name: string]: string}) => {
194
- for (const key of Object.keys(current)) {
195
- acc[key] = current[key];
196
- }
197
-
198
- return acc;
199
- }, {});
200
-
201
- return getSourceNodes(source)
202
- .filter(node => {
203
- return node.kind == ts.SyntaxKind.Decorator
204
- && (node as ts.Decorator).expression.kind == ts.SyntaxKind.CallExpression;
205
- })
206
- .map(node => (node as ts.Decorator).expression as ts.CallExpression)
207
- .filter(expr => {
208
- if (expr.expression.kind == ts.SyntaxKind.Identifier) {
209
- const id = expr.expression as ts.Identifier;
210
-
211
- return id.getFullText(source) == identifier
212
- && angularImports[id.getFullText(source)] === module;
213
- } else if (expr.expression.kind == ts.SyntaxKind.PropertyAccessExpression) {
214
- // This covers foo.NgModule when importing * as foo.
215
- const paExpr = expr.expression as ts.PropertyAccessExpression;
216
- // If the left expression is not an identifier, just give up at that point.
217
- if (paExpr.expression.kind !== ts.SyntaxKind.Identifier) {
218
- return false;
219
- }
220
-
221
- const id = paExpr.name.text;
222
- const moduleId = (paExpr.expression as ts.Identifier).getText(source);
223
-
224
- return id === identifier && (angularImports[moduleId + '.'] === module);
225
- }
226
-
227
- return false;
228
- })
229
- .filter(expr => expr.arguments[0]
230
- && expr.arguments[0].kind == ts.SyntaxKind.ObjectLiteralExpression)
231
- .map(expr => expr.arguments[0] as ts.ObjectLiteralExpression);
232
- }
233
-
234
- function findClassDeclarationParent(node: ts.Node): ts.ClassDeclaration|undefined {
235
- if (ts.isClassDeclaration(node)) {
236
- return node;
237
- }
238
-
239
- return node.parent && findClassDeclarationParent(node.parent);
240
- }
241
-
242
- /**
243
- * Given a source file with @NgModule class(es), find the name of the first @NgModule class.
244
- *
245
- * @param source source file containing one or more @NgModule
246
- * @returns the name of the first @NgModule, or `undefined` if none is found
247
- */
248
- export function getFirstNgModuleName(source: ts.SourceFile): string|undefined {
249
- // First, find the @NgModule decorators.
250
- const ngModulesMetadata = getDecoratorMetadata(source, 'NgModule', '@angular/core');
251
- if (ngModulesMetadata.length === 0) {
252
- return undefined;
253
- }
254
-
255
- // Then walk parent pointers up the AST, looking for the ClassDeclaration parent of the NgModule
256
- // metadata.
257
- const moduleClass = findClassDeclarationParent(ngModulesMetadata[0]);
258
- if (!moduleClass || !moduleClass.name) {
259
- return undefined;
260
- }
261
-
262
- // Get the class name of the module ClassDeclaration.
263
- return moduleClass.name.text;
264
- }
265
-
266
- export function addSymbolToNgModuleMetadata(
267
- source: ts.SourceFile,
268
- ngModulePath: string,
269
- metadataField: string,
270
- symbolName: string,
271
- importPath: string | null = null,
272
- ): Change[] {
273
- const nodes = getDecoratorMetadata(source, 'NgModule', '@angular/core');
274
- let node: any = nodes[0]; // tslint:disable-line:no-any
275
-
276
- // Find the decorator declaration.
277
- if (!node) {
278
- return [];
279
- }
280
-
281
- // Get all the children property assignment of object literals.
282
- const matchingProperties: ts.ObjectLiteralElement[] =
283
- (node as ts.ObjectLiteralExpression).properties
284
- .filter(prop => prop.kind == ts.SyntaxKind.PropertyAssignment)
285
- // Filter out every fields that's not "metadataField". Also handles string literals
286
- // (but not expressions).
287
- .filter((prop: ts.PropertyAssignment) => {
288
- const name = prop.name;
289
- switch (name.kind) {
290
- case ts.SyntaxKind.Identifier:
291
- return (name as ts.Identifier).getText(source) == metadataField;
292
- case ts.SyntaxKind.StringLiteral:
293
- return (name as ts.StringLiteral).text == metadataField;
294
- }
295
-
296
- return false;
297
- });
298
-
299
- // Get the last node of the array literal.
300
- if (!matchingProperties) {
301
- return [];
302
- }
303
- if (matchingProperties.length == 0) {
304
- // We haven't found the field in the metadata declaration. Insert a new field.
305
- const expr = node as ts.ObjectLiteralExpression;
306
- let position: number;
307
- let toInsert: string;
308
- if (expr.properties.length == 0) {
309
- position = expr.getEnd() - 1;
310
- toInsert = ` ${metadataField}: [${symbolName}]\n`;
311
- } else {
312
- node = expr.properties[expr.properties.length - 1];
313
- position = node.getEnd();
314
- // Get the indentation of the last element, if any.
315
- const text = node.getFullText(source);
316
- const matches = text.match(/^\r?\n\s*/);
317
- if (matches.length > 0) {
318
- toInsert = `,${matches[0]}${metadataField}: [${symbolName}]`;
319
- } else {
320
- toInsert = `, ${metadataField}: [${symbolName}]`;
321
- }
322
- }
323
- if (importPath !== null) {
324
- return [
325
- new InsertChange(ngModulePath, position, toInsert),
326
- insertImport(source, ngModulePath, symbolName.replace(/\..*$/, ''), importPath),
327
- ];
328
- } else {
329
- return [new InsertChange(ngModulePath, position, toInsert)];
330
- }
331
- }
332
- const assignment = matchingProperties[0] as ts.PropertyAssignment;
333
-
334
- // If it's not an array, nothing we can do really.
335
- if (assignment.initializer.kind !== ts.SyntaxKind.ArrayLiteralExpression) {
336
- return [];
337
- }
338
-
339
- const arrLiteral = assignment.initializer as ts.ArrayLiteralExpression;
340
- if (arrLiteral.elements.length == 0) {
341
- // Forward the property.
342
- node = arrLiteral;
343
- } else {
344
- node = arrLiteral.elements;
345
- }
346
-
347
- if (!node) {
348
- console.log('No app module found. Please add your new class to your component.');
349
-
350
- return [];
351
- }
352
-
353
- if (Array.isArray(node)) {
354
- const nodeArray = node as {} as Array<ts.Node>;
355
- const symbolsArray = nodeArray.map(node => node.getText());
356
- if (symbolsArray.includes(symbolName)) {
357
- return [];
358
- }
359
-
360
- node = node[node.length - 1];
361
- }
362
-
363
- let toInsert: string;
364
- let position = node.getEnd();
365
- if (node.kind == ts.SyntaxKind.ObjectLiteralExpression) {
366
- // We haven't found the field in the metadata declaration. Insert a new
367
- // field.
368
- const expr = node as ts.ObjectLiteralExpression;
369
- if (expr.properties.length == 0) {
370
- position = expr.getEnd() - 1;
371
- toInsert = ` ${metadataField}: [${symbolName}]\n`;
372
- } else {
373
- node = expr.properties[expr.properties.length - 1];
374
- position = node.getEnd();
375
- // Get the indentation of the last element, if any.
376
- const text = node.getFullText(source);
377
- if (text.match('^\r?\r?\n')) {
378
- toInsert = `,${text.match(/^\r?\n\s+/)[0]}${metadataField}: [${symbolName}]`;
379
- } else {
380
- toInsert = `, ${metadataField}: [${symbolName}]`;
381
- }
382
- }
383
- } else if (node.kind == ts.SyntaxKind.ArrayLiteralExpression) {
384
- // We found the field but it's empty. Insert it just before the `]`.
385
- position--;
386
- toInsert = `${symbolName}`;
387
- } else {
388
- // Get the indentation of the last element, if any.
389
- const text = node.getFullText(source);
390
- if (text.match(/^\r?\n/)) {
391
- toInsert = `,${text.match(/^\r?\n(\r?)\s+/)[0]}${symbolName}`;
392
- } else {
393
- toInsert = `, ${symbolName}`;
394
- }
395
- }
396
- if (importPath !== null) {
397
- return [
398
- new InsertChange(ngModulePath, position, toInsert),
399
- insertImport(source, ngModulePath, symbolName.replace(/\..*$/, ''), importPath),
400
- ];
401
- }
402
-
403
- return [new InsertChange(ngModulePath, position, toInsert)];
404
- }
405
-
406
- /**
407
- * Custom function to insert a declaration (component, pipe, directive)
408
- * into NgModule declarations. It also imports the component.
409
- */
410
- export function addDeclarationToModule(source: ts.SourceFile,
411
- modulePath: string, classifiedName: string,
412
- importPath: string): Change[] {
413
- return addSymbolToNgModuleMetadata(
414
- source, modulePath, 'declarations', classifiedName, importPath);
415
- }
416
-
417
- /**
418
- * Custom function to insert an NgModule into NgModule imports. It also imports the module.
419
- */
420
- export function addImportToModule(source: ts.SourceFile,
421
- modulePath: string, classifiedName: string,
422
- importPath: string): Change[] {
423
-
424
- return addSymbolToNgModuleMetadata(source, modulePath, 'imports', classifiedName, importPath);
425
- }
426
-
427
- /**
428
- * Custom function to insert a provider into NgModule. It also imports it.
429
- */
430
- export function addProviderToModule(source: ts.SourceFile,
431
- modulePath: string, classifiedName: string,
432
- importPath: string): Change[] {
433
- return addSymbolToNgModuleMetadata(source, modulePath, 'providers', classifiedName, importPath);
434
- }
435
-
436
- /**
437
- * Custom function to insert an export into NgModule. It also imports it.
438
- */
439
- export function addExportToModule(source: ts.SourceFile,
440
- modulePath: string, classifiedName: string,
441
- importPath: string): Change[] {
442
- return addSymbolToNgModuleMetadata(source, modulePath, 'exports', classifiedName, importPath);
443
- }
444
-
445
- /**
446
- * Custom function to insert an export into NgModule. It also imports it.
447
- */
448
- export function addBootstrapToModule(source: ts.SourceFile,
449
- modulePath: string, classifiedName: string,
450
- importPath: string): Change[] {
451
- return addSymbolToNgModuleMetadata(source, modulePath, 'bootstrap', classifiedName, importPath);
452
- }
453
-
454
- /**
455
- * Determine if an import already exists.
456
- */
457
- export function isImported(source: ts.SourceFile,
458
- classifiedName: string,
459
- importPath: string): boolean {
460
- const allNodes = getSourceNodes(source);
461
- const matchingNodes = allNodes
462
- .filter(node => node.kind === ts.SyntaxKind.ImportDeclaration)
463
- .filter((imp: ts.ImportDeclaration) => imp.moduleSpecifier.kind === ts.SyntaxKind.StringLiteral)
464
- .filter((imp: ts.ImportDeclaration) => {
465
- return (<ts.StringLiteral> imp.moduleSpecifier).text === importPath;
466
- })
467
- .filter((imp: ts.ImportDeclaration) => {
468
- if (!imp.importClause) {
469
- return false;
470
- }
471
- const nodes = findNodes(imp.importClause, ts.SyntaxKind.ImportSpecifier)
472
- .filter(n => n.getText() === classifiedName);
473
-
474
- return nodes.length > 0;
475
- });
476
-
477
- return matchingNodes.length > 0;
478
- }
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
+ */
8
+ import * as ts from 'typescript';
9
+ import { Change, InsertChange } from './change';
10
+ import { insertImport } from './route-utils';
11
+
12
+
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
+ * @return all nodes of kind, or [] if none is found
19
+ */
20
+ export function findNodes(node: ts.Node, kind: ts.SyntaxKind, max = Infinity): ts.Node[] {
21
+ if (!node || max == 0) {
22
+ return [];
23
+ }
24
+
25
+ const arr: ts.Node[] = [];
26
+ if (node.kind === kind) {
27
+ arr.push(node);
28
+ max--;
29
+ }
30
+ if (max > 0) {
31
+ for (const child of node.getChildren()) {
32
+ findNodes(child, kind, max).forEach(node => {
33
+ if (max > 0) {
34
+ arr.push(node);
35
+ }
36
+ max--;
37
+ });
38
+
39
+ if (max <= 0) {
40
+ break;
41
+ }
42
+ }
43
+ }
44
+
45
+ return arr;
46
+ }
47
+
48
+
49
+
50
+ export function getSourceNodes(sourceFile: ts.SourceFile): ts.Node[] {
51
+ const nodes: ts.Node[] = [sourceFile];
52
+ const result = [];
53
+
54
+ while (nodes.length > 0) {
55
+ const node = nodes.shift();
56
+
57
+ if (node) {
58
+ result.push(node);
59
+ if (node.getChildCount(sourceFile) >= 0) {
60
+ nodes.unshift(...node.getChildren());
61
+ }
62
+ }
63
+ }
64
+
65
+ return result;
66
+ }
67
+
68
+ export function findNode(node: ts.Node, kind: ts.SyntaxKind, text: string): ts.Node | null {
69
+ if (node.kind === kind && node.getText() === text) {
70
+ // throw new Error(node.getText());
71
+ return node;
72
+ }
73
+
74
+ let foundNode: ts.Node | null = null;
75
+ ts.forEachChild(node, childNode => {
76
+ foundNode = foundNode || findNode(childNode, kind, text);
77
+ });
78
+
79
+ return foundNode;
80
+ }
81
+
82
+
83
+ /**
84
+ * Helper for sorting nodes.
85
+ * @return function to sort nodes in increasing order of position in sourceFile
86
+ */
87
+ function nodesByPosition(first: ts.Node, second: ts.Node): number {
88
+ return first.getStart() - second.getStart();
89
+ }
90
+
91
+
92
+ /**
93
+ * Insert `toInsert` after the last occurence of `ts.SyntaxKind[nodes[i].kind]`
94
+ * or after the last of occurence of `syntaxKind` if the last occurence is a sub child
95
+ * of ts.SyntaxKind[nodes[i].kind] and save the changes in file.
96
+ *
97
+ * @param nodes insert after the last occurence of nodes
98
+ * @param toInsert string to insert
99
+ * @param file file to insert changes into
100
+ * @param fallbackPos position to insert if toInsert happens to be the first occurence
101
+ * @param syntaxKind the ts.SyntaxKind of the subchildren to insert after
102
+ * @return Change instance
103
+ * @throw Error if toInsert is first occurence but fall back is not set
104
+ */
105
+ export function insertAfterLastOccurrence(nodes: ts.Node[],
106
+ toInsert: string,
107
+ file: string,
108
+ fallbackPos: number,
109
+ syntaxKind?: ts.SyntaxKind): Change {
110
+ let lastItem = nodes.sort(nodesByPosition).pop();
111
+ if (!lastItem) {
112
+ //throw new Error();
113
+ // No imports exist....
114
+ new InsertChange(file, 0, toInsert);
115
+ }
116
+ if (syntaxKind) {
117
+ lastItem = findNodes(lastItem, syntaxKind).sort(nodesByPosition).pop();
118
+ }
119
+ if (!lastItem && fallbackPos == undefined) {
120
+ throw new Error(`tried to insert ${toInsert} as first occurence with no fallback position`);
121
+ }
122
+ const lastItemPosition: number = lastItem ? lastItem.getEnd() : fallbackPos;
123
+
124
+ return new InsertChange(file, lastItemPosition, toInsert);
125
+ }
126
+
127
+
128
+ export function getContentOfKeyLiteral(_source: ts.SourceFile, node: ts.Node): string | null {
129
+ if (node.kind == ts.SyntaxKind.Identifier) {
130
+ return (node as ts.Identifier).text;
131
+ } else if (node.kind == ts.SyntaxKind.StringLiteral) {
132
+ return (node as ts.StringLiteral).text;
133
+ } else {
134
+ return null;
135
+ }
136
+ }
137
+
138
+
139
+ function _angularImportsFromNode(node: ts.ImportDeclaration,
140
+ _sourceFile: ts.SourceFile): {[name: string]: string} {
141
+ const ms = node.moduleSpecifier;
142
+ let modulePath: string;
143
+ switch (ms.kind) {
144
+ case ts.SyntaxKind.StringLiteral:
145
+ modulePath = (ms as ts.StringLiteral).text;
146
+ break;
147
+ default:
148
+ return {};
149
+ }
150
+
151
+ if (!modulePath.startsWith('@angular/')) {
152
+ return {};
153
+ }
154
+
155
+ if (node.importClause) {
156
+ if (node.importClause.name) {
157
+ // This is of the form `import Name from 'path'`. Ignore.
158
+ return {};
159
+ } else if (node.importClause.namedBindings) {
160
+ const nb = node.importClause.namedBindings;
161
+ if (nb.kind == ts.SyntaxKind.NamespaceImport) {
162
+ // This is of the form `import * as name from 'path'`. Return `name.`.
163
+ return {
164
+ [(nb as ts.NamespaceImport).name.text + '.']: modulePath,
165
+ };
166
+ } else {
167
+ // This is of the form `import {a,b,c} from 'path'`
168
+ const namedImports = nb as ts.NamedImports;
169
+
170
+ return namedImports.elements
171
+ .map((is: ts.ImportSpecifier) => is.propertyName ? is.propertyName.text : is.name.text)
172
+ .reduce((acc: {[name: string]: string}, curr: string) => {
173
+ acc[curr] = modulePath;
174
+
175
+ return acc;
176
+ }, {});
177
+ }
178
+ }
179
+
180
+ return {};
181
+ } else {
182
+ // This is of the form `import 'path';`. Nothing to do.
183
+ return {};
184
+ }
185
+ }
186
+
187
+
188
+ export function getDecoratorMetadata(source: ts.SourceFile, identifier: string,
189
+ module: string): ts.Node[] {
190
+ const angularImports: {[name: string]: string}
191
+ = findNodes(source, ts.SyntaxKind.ImportDeclaration)
192
+ .map((node: ts.ImportDeclaration) => _angularImportsFromNode(node, source))
193
+ .reduce((acc: {[name: string]: string}, current: {[name: string]: string}) => {
194
+ for (const key of Object.keys(current)) {
195
+ acc[key] = current[key];
196
+ }
197
+
198
+ return acc;
199
+ }, {});
200
+
201
+ return getSourceNodes(source)
202
+ .filter(node => {
203
+ return node.kind == ts.SyntaxKind.Decorator
204
+ && (node as ts.Decorator).expression.kind == ts.SyntaxKind.CallExpression;
205
+ })
206
+ .map(node => (node as ts.Decorator).expression as ts.CallExpression)
207
+ .filter(expr => {
208
+ if (expr.expression.kind == ts.SyntaxKind.Identifier) {
209
+ const id = expr.expression as ts.Identifier;
210
+
211
+ return id.getFullText(source) == identifier
212
+ && angularImports[id.getFullText(source)] === module;
213
+ } else if (expr.expression.kind == ts.SyntaxKind.PropertyAccessExpression) {
214
+ // This covers foo.NgModule when importing * as foo.
215
+ const paExpr = expr.expression as ts.PropertyAccessExpression;
216
+ // If the left expression is not an identifier, just give up at that point.
217
+ if (paExpr.expression.kind !== ts.SyntaxKind.Identifier) {
218
+ return false;
219
+ }
220
+
221
+ const id = paExpr.name.text;
222
+ const moduleId = (paExpr.expression as ts.Identifier).getText(source);
223
+
224
+ return id === identifier && (angularImports[moduleId + '.'] === module);
225
+ }
226
+
227
+ return false;
228
+ })
229
+ .filter(expr => expr.arguments[0]
230
+ && expr.arguments[0].kind == ts.SyntaxKind.ObjectLiteralExpression)
231
+ .map(expr => expr.arguments[0] as ts.ObjectLiteralExpression);
232
+ }
233
+
234
+ function findClassDeclarationParent(node: ts.Node): ts.ClassDeclaration|undefined {
235
+ if (ts.isClassDeclaration(node)) {
236
+ return node;
237
+ }
238
+
239
+ return node.parent && findClassDeclarationParent(node.parent);
240
+ }
241
+
242
+ /**
243
+ * Given a source file with @NgModule class(es), find the name of the first @NgModule class.
244
+ *
245
+ * @param source source file containing one or more @NgModule
246
+ * @returns the name of the first @NgModule, or `undefined` if none is found
247
+ */
248
+ export function getFirstNgModuleName(source: ts.SourceFile): string|undefined {
249
+ // First, find the @NgModule decorators.
250
+ const ngModulesMetadata = getDecoratorMetadata(source, 'NgModule', '@angular/core');
251
+ if (ngModulesMetadata.length === 0) {
252
+ return undefined;
253
+ }
254
+
255
+ // Then walk parent pointers up the AST, looking for the ClassDeclaration parent of the NgModule
256
+ // metadata.
257
+ const moduleClass = findClassDeclarationParent(ngModulesMetadata[0]);
258
+ if (!moduleClass || !moduleClass.name) {
259
+ return undefined;
260
+ }
261
+
262
+ // Get the class name of the module ClassDeclaration.
263
+ return moduleClass.name.text;
264
+ }
265
+
266
+ export function addSymbolToNgModuleMetadata(
267
+ source: ts.SourceFile,
268
+ ngModulePath: string,
269
+ metadataField: string,
270
+ symbolName: string,
271
+ importPath: string | null = null,
272
+ ): Change[] {
273
+ const nodes = getDecoratorMetadata(source, 'NgModule', '@angular/core');
274
+ let node: any = nodes[0]; // tslint:disable-line:no-any
275
+
276
+ // Find the decorator declaration.
277
+ if (!node) {
278
+ return [];
279
+ }
280
+
281
+ // Get all the children property assignment of object literals.
282
+ const matchingProperties: ts.ObjectLiteralElement[] =
283
+ (node as ts.ObjectLiteralExpression).properties
284
+ .filter(prop => prop.kind == ts.SyntaxKind.PropertyAssignment)
285
+ // Filter out every fields that's not "metadataField". Also handles string literals
286
+ // (but not expressions).
287
+ .filter((prop: ts.PropertyAssignment) => {
288
+ const name = prop.name;
289
+ switch (name.kind) {
290
+ case ts.SyntaxKind.Identifier:
291
+ return (name as ts.Identifier).getText(source) == metadataField;
292
+ case ts.SyntaxKind.StringLiteral:
293
+ return (name as ts.StringLiteral).text == metadataField;
294
+ }
295
+
296
+ return false;
297
+ });
298
+
299
+ // Get the last node of the array literal.
300
+ if (!matchingProperties) {
301
+ return [];
302
+ }
303
+ if (matchingProperties.length == 0) {
304
+ // We haven't found the field in the metadata declaration. Insert a new field.
305
+ const expr = node as ts.ObjectLiteralExpression;
306
+ let position: number;
307
+ let toInsert: string;
308
+ if (expr.properties.length == 0) {
309
+ position = expr.getEnd() - 1;
310
+ toInsert = ` ${metadataField}: [${symbolName}]\n`;
311
+ } else {
312
+ node = expr.properties[expr.properties.length - 1];
313
+ position = node.getEnd();
314
+ // Get the indentation of the last element, if any.
315
+ const text = node.getFullText(source);
316
+ const matches = text.match(/^\r?\n\s*/);
317
+ if (matches.length > 0) {
318
+ toInsert = `,${matches[0]}${metadataField}: [${symbolName}]`;
319
+ } else {
320
+ toInsert = `, ${metadataField}: [${symbolName}]`;
321
+ }
322
+ }
323
+ if (importPath !== null) {
324
+ return [
325
+ new InsertChange(ngModulePath, position, toInsert),
326
+ insertImport(source, ngModulePath, symbolName.replace(/\..*$/, ''), importPath),
327
+ ];
328
+ } else {
329
+ return [new InsertChange(ngModulePath, position, toInsert)];
330
+ }
331
+ }
332
+ const assignment = matchingProperties[0] as ts.PropertyAssignment;
333
+
334
+ // If it's not an array, nothing we can do really.
335
+ if (assignment.initializer.kind !== ts.SyntaxKind.ArrayLiteralExpression) {
336
+ return [];
337
+ }
338
+
339
+ const arrLiteral = assignment.initializer as ts.ArrayLiteralExpression;
340
+ if (arrLiteral.elements.length == 0) {
341
+ // Forward the property.
342
+ node = arrLiteral;
343
+ } else {
344
+ node = arrLiteral.elements;
345
+ }
346
+
347
+ if (!node) {
348
+ console.log('No app module found. Please add your new class to your component.');
349
+
350
+ return [];
351
+ }
352
+
353
+ if (Array.isArray(node)) {
354
+ const nodeArray = node as {} as Array<ts.Node>;
355
+ const symbolsArray = nodeArray.map(node => node.getText());
356
+ if (symbolsArray.includes(symbolName)) {
357
+ return [];
358
+ }
359
+
360
+ node = node[node.length - 1];
361
+ }
362
+
363
+ let toInsert: string;
364
+ let position = node.getEnd();
365
+ if (node.kind == ts.SyntaxKind.ObjectLiteralExpression) {
366
+ // We haven't found the field in the metadata declaration. Insert a new
367
+ // field.
368
+ const expr = node as ts.ObjectLiteralExpression;
369
+ if (expr.properties.length == 0) {
370
+ position = expr.getEnd() - 1;
371
+ toInsert = ` ${metadataField}: [${symbolName}]\n`;
372
+ } else {
373
+ node = expr.properties[expr.properties.length - 1];
374
+ position = node.getEnd();
375
+ // Get the indentation of the last element, if any.
376
+ const text = node.getFullText(source);
377
+ if (text.match('^\r?\r?\n')) {
378
+ toInsert = `,${text.match(/^\r?\n\s+/)[0]}${metadataField}: [${symbolName}]`;
379
+ } else {
380
+ toInsert = `, ${metadataField}: [${symbolName}]`;
381
+ }
382
+ }
383
+ } else if (node.kind == ts.SyntaxKind.ArrayLiteralExpression) {
384
+ // We found the field but it's empty. Insert it just before the `]`.
385
+ position--;
386
+ toInsert = `${symbolName}`;
387
+ } else {
388
+ // Get the indentation of the last element, if any.
389
+ const text = node.getFullText(source);
390
+ if (text.match(/^\r?\n/)) {
391
+ toInsert = `,${text.match(/^\r?\n(\r?)\s+/)[0]}${symbolName}`;
392
+ } else {
393
+ toInsert = `, ${symbolName}`;
394
+ }
395
+ }
396
+ if (importPath !== null) {
397
+ return [
398
+ new InsertChange(ngModulePath, position, toInsert),
399
+ insertImport(source, ngModulePath, symbolName.replace(/\..*$/, ''), importPath),
400
+ ];
401
+ }
402
+
403
+ return [new InsertChange(ngModulePath, position, toInsert)];
404
+ }
405
+
406
+ /**
407
+ * Custom function to insert a declaration (component, pipe, directive)
408
+ * into NgModule declarations. It also imports the component.
409
+ */
410
+ export function addDeclarationToModule(source: ts.SourceFile,
411
+ modulePath: string, classifiedName: string,
412
+ importPath: string): Change[] {
413
+ return addSymbolToNgModuleMetadata(
414
+ source, modulePath, 'declarations', classifiedName, importPath);
415
+ }
416
+
417
+ /**
418
+ * Custom function to insert an NgModule into NgModule imports. It also imports the module.
419
+ */
420
+ export function addImportToModule(source: ts.SourceFile,
421
+ modulePath: string, classifiedName: string,
422
+ importPath: string): Change[] {
423
+
424
+ return addSymbolToNgModuleMetadata(source, modulePath, 'imports', classifiedName, importPath);
425
+ }
426
+
427
+ /**
428
+ * Custom function to insert a provider into NgModule. It also imports it.
429
+ */
430
+ export function addProviderToModule(source: ts.SourceFile,
431
+ modulePath: string, classifiedName: string,
432
+ importPath: string): Change[] {
433
+ return addSymbolToNgModuleMetadata(source, modulePath, 'providers', classifiedName, importPath);
434
+ }
435
+
436
+ /**
437
+ * Custom function to insert an export into NgModule. It also imports it.
438
+ */
439
+ export function addExportToModule(source: ts.SourceFile,
440
+ modulePath: string, classifiedName: string,
441
+ importPath: string): Change[] {
442
+ return addSymbolToNgModuleMetadata(source, modulePath, 'exports', classifiedName, importPath);
443
+ }
444
+
445
+ /**
446
+ * Custom function to insert an export into NgModule. It also imports it.
447
+ */
448
+ export function addBootstrapToModule(source: ts.SourceFile,
449
+ modulePath: string, classifiedName: string,
450
+ importPath: string): Change[] {
451
+ return addSymbolToNgModuleMetadata(source, modulePath, 'bootstrap', classifiedName, importPath);
452
+ }
453
+
454
+ /**
455
+ * Determine if an import already exists.
456
+ */
457
+ export function isImported(source: ts.SourceFile,
458
+ classifiedName: string,
459
+ importPath: string): boolean {
460
+ const allNodes = getSourceNodes(source);
461
+ const matchingNodes = allNodes
462
+ .filter(node => node.kind === ts.SyntaxKind.ImportDeclaration)
463
+ .filter((imp: ts.ImportDeclaration) => imp.moduleSpecifier.kind === ts.SyntaxKind.StringLiteral)
464
+ .filter((imp: ts.ImportDeclaration) => {
465
+ return (<ts.StringLiteral> imp.moduleSpecifier).text === importPath;
466
+ })
467
+ .filter((imp: ts.ImportDeclaration) => {
468
+ if (!imp.importClause) {
469
+ return false;
470
+ }
471
+ const nodes = findNodes(imp.importClause, ts.SyntaxKind.ImportSpecifier)
472
+ .filter(n => n.getText() === classifiedName);
473
+
474
+ return nodes.length > 0;
475
+ });
476
+
477
+ return matchingNodes.length > 0;
478
+ }