@ngneat/helipopper 4.1.1 → 5.0.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 (54) hide show
  1. package/README.md +2 -1
  2. package/esm2020/lib/defaults.mjs +25 -0
  3. package/esm2020/lib/tippy.directive.mjs +345 -0
  4. package/esm2020/lib/tippy.module.mjs +28 -0
  5. package/esm2020/lib/tippy.service.mjs +73 -0
  6. package/esm2020/lib/tippy.types.mjs +12 -0
  7. package/{esm2015/lib/utils.js → esm2020/lib/utils.mjs} +3 -2
  8. package/{esm2015/ngneat-helipopper.js → esm2020/ngneat-helipopper.mjs} +1 -1
  9. package/{esm2015/public-api.js → esm2020/public-api.mjs} +0 -0
  10. package/fesm2015/{ngneat-helipopper.js → ngneat-helipopper.mjs} +115 -66
  11. package/fesm2015/ngneat-helipopper.mjs.map +1 -0
  12. package/fesm2020/ngneat-helipopper.mjs +562 -0
  13. package/fesm2020/ngneat-helipopper.mjs.map +1 -0
  14. package/lib/tippy.directive.d.ts +3 -0
  15. package/lib/tippy.module.d.ts +5 -0
  16. package/lib/tippy.service.d.ts +3 -0
  17. package/lib/tippy.types.d.ts +5 -2
  18. package/ngneat-helipopper.d.ts +1 -1
  19. package/package.json +23 -11
  20. package/bundles/ngneat-helipopper.umd.js +0 -897
  21. package/bundles/ngneat-helipopper.umd.js.map +0 -1
  22. package/esm2015/lib/defaults.js +0 -19
  23. package/esm2015/lib/tippy.directive.js +0 -308
  24. package/esm2015/lib/tippy.module.js +0 -23
  25. package/esm2015/lib/tippy.service.js +0 -60
  26. package/esm2015/lib/tippy.types.js +0 -12
  27. package/fesm2015/ngneat-helipopper.js.map +0 -1
  28. package/ngneat-helipopper.metadata.json +0 -1
  29. package/schematics/collection.json +0 -12
  30. package/schematics/ng-add/index.js +0 -73
  31. package/schematics/ng-add/index.js.map +0 -1
  32. package/schematics/ng-add/index.ts +0 -79
  33. package/schematics/ng-add/schema.js +0 -3
  34. package/schematics/ng-add/schema.js.map +0 -1
  35. package/schematics/ng-add/schema.json +0 -18
  36. package/schematics/ng-add/schema.ts +0 -10
  37. package/schematics/schematics.consts.js +0 -5
  38. package/schematics/schematics.consts.js.map +0 -1
  39. package/schematics/schematics.consts.ts +0 -1
  40. package/schematics/utils/ast-utils.js +0 -500
  41. package/schematics/utils/ast-utils.js.map +0 -1
  42. package/schematics/utils/ast-utils.ts +0 -596
  43. package/schematics/utils/change.js +0 -127
  44. package/schematics/utils/change.js.map +0 -1
  45. package/schematics/utils/change.ts +0 -162
  46. package/schematics/utils/find-module.js +0 -113
  47. package/schematics/utils/find-module.js.map +0 -1
  48. package/schematics/utils/find-module.ts +0 -125
  49. package/schematics/utils/package.js +0 -22
  50. package/schematics/utils/package.js.map +0 -1
  51. package/schematics/utils/package.ts +0 -22
  52. package/schematics/utils/projects.js +0 -31
  53. package/schematics/utils/projects.js.map +0 -1
  54. package/schematics/utils/projects.ts +0 -31
@@ -1,596 +0,0 @@
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 { ImportClause } from 'typescript';
9
- import * as ts from 'typescript';
10
- import { Change, InsertChange, NoopChange } from './change';
11
-
12
- /**
13
- * Add Import `import { symbolName } from fileName` if the import doesn't exit
14
- * already. Assumes fileToEdit can be resolved and accessed.
15
- * @param fileToEdit (file we want to add import to)
16
- * @param symbolName (item to import)
17
- * @param fileName (path to the file)
18
- * @param isDefault (if true, import follows style for importing default exports)
19
- * @return Change
20
- */
21
- export function insertImport(
22
- source: ts.SourceFile,
23
- fileToEdit: string,
24
- symbolName: string,
25
- fileName: string,
26
- isDefault = false
27
- ): Change {
28
- const rootNode = source;
29
- const allImports = findNodes(rootNode, ts.SyntaxKind.ImportDeclaration);
30
-
31
- allImports.forEach(node => {
32
- node.getChildren().forEach(child => {
33
- if (child.kind === ts.SyntaxKind.ImportClause) {
34
- child.getChildren().forEach((c: any) => {
35
- if (!c.elements) return;
36
- c.elements.forEach(elem => {
37
- symbolName = symbolName
38
- .split(', ')
39
- .filter(symbol => {
40
- return elem.name.text !== symbol;
41
- })
42
- .join(', ');
43
- });
44
- });
45
- }
46
- });
47
- });
48
-
49
- if (!symbolName) {
50
- return new NoopChange();
51
- }
52
-
53
- // get nodes that map to import statements from the file fileName
54
- const relevantImports = allImports.filter(node => {
55
- // StringLiteral of the ImportDeclaration is the import file (fileName in this case).
56
- const importFiles = node
57
- .getChildren()
58
- .filter(child => child.kind === ts.SyntaxKind.StringLiteral)
59
- .map(n => (n as ts.StringLiteral).text);
60
- return importFiles.filter(file => file === fileName).length === 1;
61
- });
62
-
63
- if (relevantImports.length > 0) {
64
- let importsAsterisk = false;
65
- // imports from import file
66
- const imports: ts.Node[] = [];
67
- relevantImports.forEach(n => {
68
- Array.prototype.push.apply(imports, findNodes(n, ts.SyntaxKind.Identifier));
69
- if (findNodes(n, ts.SyntaxKind.AsteriskToken).length > 0) {
70
- importsAsterisk = true;
71
- }
72
- });
73
-
74
- // if imports * from fileName, don't add symbolName
75
- if (importsAsterisk) {
76
- return new NoopChange();
77
- }
78
-
79
- const importTextNodes = imports.filter(n => (n as ts.Identifier).text === symbolName);
80
-
81
- // insert import if it's not there
82
- if (importTextNodes.length === 0) {
83
- const fallbackPos =
84
- findNodes(relevantImports[0], ts.SyntaxKind.CloseBraceToken)[0].getStart() ||
85
- findNodes(relevantImports[0], ts.SyntaxKind.FromKeyword)[0].getStart();
86
-
87
- return insertAfterLastOccurrence(imports, `, ${symbolName}`, fileToEdit, fallbackPos);
88
- }
89
-
90
- return new NoopChange();
91
- }
92
-
93
- // no such import declaration exists
94
- const useStrict = findNodes(rootNode, ts.SyntaxKind.StringLiteral).filter(
95
- (n: ts.StringLiteral) => n.text === 'use strict'
96
- );
97
- let fallbackPos = 0;
98
- if (useStrict.length > 0) {
99
- fallbackPos = useStrict[0].end;
100
- }
101
- const open = isDefault ? '' : '{ ';
102
- const close = isDefault ? '' : ' }';
103
- // if there are no imports or 'use strict' statement, insert import at beginning of file
104
- const insertAtBeginning = allImports.length === 0 && useStrict.length === 0;
105
- const separator = insertAtBeginning ? '' : ';\n';
106
- const toInsert =
107
- `${separator}import ${open}${symbolName}${close}` + ` from '${fileName}'${insertAtBeginning ? ';\n' : ''}`;
108
-
109
- return insertAfterLastOccurrence(allImports, toInsert, fileToEdit, fallbackPos, ts.SyntaxKind.StringLiteral);
110
- }
111
-
112
- /**
113
- * Find all nodes from the AST in the subtree of node of SyntaxKind kind.
114
- * @param node
115
- * @param kind
116
- * @param max The maximum number of items to return.
117
- * @return all nodes of kind, or [] if none is found
118
- */
119
- export function findNodes(node: ts.Node, kind: ts.SyntaxKind, max = Infinity): ts.Node[] {
120
- if (!node || max == 0) {
121
- return [];
122
- }
123
-
124
- const arr: ts.Node[] = [];
125
- if (node.kind === kind) {
126
- arr.push(node);
127
- max--;
128
- }
129
- if (max > 0) {
130
- for (const child of node.getChildren()) {
131
- findNodes(child, kind, max).forEach(node => {
132
- if (max > 0) {
133
- arr.push(node);
134
- }
135
- max--;
136
- });
137
-
138
- if (max <= 0) {
139
- break;
140
- }
141
- }
142
- }
143
-
144
- return arr;
145
- }
146
-
147
- /**
148
- * Get all the nodes from a source.
149
- * @param sourceFile The source file object.
150
- * @returns {Observable<ts.Node>} An observable of all the nodes in the source.
151
- */
152
- export function getSourceNodes(sourceFile: ts.SourceFile): ts.Node[] {
153
- const nodes: ts.Node[] = [sourceFile];
154
- const result = [];
155
-
156
- while (nodes.length > 0) {
157
- const node = nodes.shift();
158
-
159
- if (node) {
160
- result.push(node);
161
- if (node.getChildCount(sourceFile) >= 0) {
162
- nodes.unshift(...node.getChildren());
163
- }
164
- }
165
- }
166
-
167
- return result;
168
- }
169
-
170
- export function findNode(node: ts.Node, kind: ts.SyntaxKind, text: string): ts.Node | null {
171
- if (node.kind === kind && node.getText() === text) {
172
- // throw new Error(node.getText());
173
- return node;
174
- }
175
-
176
- let foundNode: ts.Node | null = null;
177
- ts.forEachChild(node, childNode => {
178
- foundNode = foundNode || findNode(childNode, kind, text);
179
- });
180
-
181
- return foundNode;
182
- }
183
-
184
- /**
185
- * Helper for sorting nodes.
186
- * @return function to sort nodes in increasing order of position in sourceFile
187
- */
188
- function nodesByPosition(first: ts.Node, second: ts.Node): number {
189
- return first.getStart() - second.getStart();
190
- }
191
-
192
- /**
193
- * Insert `toInsert` after the last occurence of `ts.SyntaxKind[nodes[i].kind]`
194
- * or after the last of occurence of `syntaxKind` if the last occurence is a sub child
195
- * of ts.SyntaxKind[nodes[i].kind] and save the changes in file.
196
- *
197
- * @param nodes insert after the last occurence of nodes
198
- * @param toInsert string to insert
199
- * @param file file to insert changes into
200
- * @param fallbackPos position to insert if toInsert happens to be the first occurence
201
- * @param syntaxKind the ts.SyntaxKind of the subchildren to insert after
202
- * @return Change instance
203
- * @throw Error if toInsert is first occurence but fall back is not set
204
- */
205
- export function insertAfterLastOccurrence(
206
- nodes: ts.Node[],
207
- toInsert: string,
208
- file: string,
209
- fallbackPos: number,
210
- syntaxKind?: ts.SyntaxKind
211
- ): Change {
212
- // sort() has a side effect, so make a copy so that we won't overwrite the parent's object.
213
- let lastItem = [...nodes].sort(nodesByPosition).pop();
214
- if (!lastItem) {
215
- throw new Error();
216
- }
217
- if (syntaxKind) {
218
- lastItem = findNodes(lastItem, syntaxKind)
219
- .sort(nodesByPosition)
220
- .pop();
221
- }
222
- if (!lastItem && fallbackPos == undefined) {
223
- throw new Error(`tried to insert ${toInsert} as first occurence with no fallback position`);
224
- }
225
- const lastItemPosition: number = lastItem ? lastItem.getEnd() : fallbackPos;
226
-
227
- return new InsertChange(file, lastItemPosition, toInsert);
228
- }
229
-
230
- export function getContentOfKeyLiteral(_source: ts.SourceFile, node: ts.Node): string | null {
231
- if (node.kind == ts.SyntaxKind.Identifier) {
232
- return (node as ts.Identifier).text;
233
- } else if (node.kind == ts.SyntaxKind.StringLiteral) {
234
- return (node as ts.StringLiteral).text;
235
- } else {
236
- return null;
237
- }
238
- }
239
-
240
- function _angularImportsFromNode(node: ts.ImportDeclaration, _sourceFile: ts.SourceFile): { [name: string]: string } {
241
- const ms = node.moduleSpecifier;
242
- let modulePath: string;
243
- switch (ms.kind) {
244
- case ts.SyntaxKind.StringLiteral:
245
- modulePath = (ms as ts.StringLiteral).text;
246
- break;
247
- default:
248
- return {};
249
- }
250
-
251
- if (!modulePath.startsWith('@angular/')) {
252
- return {};
253
- }
254
-
255
- if (node.importClause) {
256
- if (node.importClause.name) {
257
- // This is of the form `import Name from 'path'`. Ignore.
258
- return {};
259
- } else if (node.importClause.namedBindings) {
260
- const nb = node.importClause.namedBindings;
261
- if (nb.kind == ts.SyntaxKind.NamespaceImport) {
262
- // This is of the form `import * as name from 'path'`. Return `name.`.
263
- return {
264
- [(nb as ts.NamespaceImport).name.text + '.']: modulePath
265
- };
266
- } else {
267
- // This is of the form `import {a,b,c} from 'path'`
268
- const namedImports = nb as ts.NamedImports;
269
-
270
- return namedImports.elements
271
- .map((is: ts.ImportSpecifier) => (is.propertyName ? is.propertyName.text : is.name.text))
272
- .reduce((acc: { [name: string]: string }, curr: string) => {
273
- acc[curr] = modulePath;
274
-
275
- return acc;
276
- }, {});
277
- }
278
- }
279
-
280
- return {};
281
- } else {
282
- // This is of the form `import 'path';`. Nothing to do.
283
- return {};
284
- }
285
- }
286
-
287
- export function getDecoratorMetadata(source: ts.SourceFile, identifier: string, module: string): ts.Node[] {
288
- const angularImports: { [name: string]: string } = findNodes(source, ts.SyntaxKind.ImportDeclaration)
289
- .map((node: ts.ImportDeclaration) => _angularImportsFromNode(node, source))
290
- .reduce((acc: { [name: string]: string }, current: { [name: string]: string }) => {
291
- for (const key of Object.keys(current)) {
292
- acc[key] = current[key];
293
- }
294
-
295
- return acc;
296
- }, {});
297
-
298
- return getSourceNodes(source)
299
- .filter(node => {
300
- return (
301
- node.kind == ts.SyntaxKind.Decorator && (node as ts.Decorator).expression.kind == ts.SyntaxKind.CallExpression
302
- );
303
- })
304
- .map(node => (node as ts.Decorator).expression as ts.CallExpression)
305
- .filter(expr => {
306
- if (expr.expression.kind == ts.SyntaxKind.Identifier) {
307
- const id = expr.expression as ts.Identifier;
308
-
309
- return id.getFullText(source) == identifier && angularImports[id.getFullText(source)] === module;
310
- } else if (expr.expression.kind == ts.SyntaxKind.PropertyAccessExpression) {
311
- // This covers foo.NgModule when importing * as foo.
312
- const paExpr = expr.expression as ts.PropertyAccessExpression;
313
- // If the left expression is not an identifier, just give up at that point.
314
- if (paExpr.expression.kind !== ts.SyntaxKind.Identifier) {
315
- return false;
316
- }
317
-
318
- const id = paExpr.name.text;
319
- const moduleId = (paExpr.expression as ts.Identifier).getText(source);
320
-
321
- return id === identifier && angularImports[moduleId + '.'] === module;
322
- }
323
-
324
- return false;
325
- })
326
- .filter(expr => expr.arguments[0] && expr.arguments[0].kind == ts.SyntaxKind.ObjectLiteralExpression)
327
- .map(expr => expr.arguments[0] as ts.ObjectLiteralExpression);
328
- }
329
-
330
- function findClassDeclarationParent(node: ts.Node): ts.ClassDeclaration | undefined {
331
- if (ts.isClassDeclaration(node)) {
332
- return node;
333
- }
334
-
335
- return node.parent && findClassDeclarationParent(node.parent);
336
- }
337
-
338
- /**
339
- * Given a source file with @NgModule class(es), find the name of the first @NgModule class.
340
- *
341
- * @param source source file containing one or more @NgModule
342
- * @returns the name of the first @NgModule, or `undefined` if none is found
343
- */
344
- export function getFirstNgModuleName(source: ts.SourceFile): string | undefined {
345
- // First, find the @NgModule decorators.
346
- const ngModulesMetadata = getDecoratorMetadata(source, 'NgModule', '@angular/core');
347
- if (ngModulesMetadata.length === 0) {
348
- return undefined;
349
- }
350
-
351
- // Then walk parent pointers up the AST, looking for the ClassDeclaration parent of the NgModule
352
- // metadata.
353
- const moduleClass = findClassDeclarationParent(ngModulesMetadata[0]);
354
- if (!moduleClass || !moduleClass.name) {
355
- return undefined;
356
- }
357
-
358
- // Get the class name of the module ClassDeclaration.
359
- return moduleClass.name.text;
360
- }
361
-
362
- export function addSymbolToNgModuleMetadata(
363
- source: ts.SourceFile,
364
- ngModulePath: string,
365
- metadataField: string,
366
- symbolName: string,
367
- importPath: string | null = null,
368
- skipImport = true
369
- ): Change[] {
370
- const nodes = getDecoratorMetadata(source, 'NgModule', '@angular/core');
371
- let node: any = nodes[0]; // tslint:disable-line:no-any
372
-
373
- // Find the decorator declaration.
374
- if (!node) {
375
- return [];
376
- }
377
-
378
- // Get all the children property assignment of object literals.
379
- const matchingProperties: ts.ObjectLiteralElement[] = (node as ts.ObjectLiteralExpression).properties
380
- .filter(prop => prop.kind == ts.SyntaxKind.PropertyAssignment)
381
- // Filter out every fields that's not "metadataField". Also handles string literals
382
- // (but not expressions).
383
- .filter((prop: ts.PropertyAssignment) => {
384
- const name = prop.name;
385
- switch (name.kind) {
386
- case ts.SyntaxKind.Identifier:
387
- return (name as ts.Identifier).getText(source) == metadataField;
388
- case ts.SyntaxKind.StringLiteral:
389
- return (name as ts.StringLiteral).text == metadataField;
390
- }
391
-
392
- return false;
393
- });
394
-
395
- // Get the last node of the array literal.
396
- if (!matchingProperties) {
397
- return [];
398
- }
399
- if (matchingProperties.length == 0) {
400
- // We haven't found the field in the metadata declaration. Insert a new field.
401
- const expr = node as ts.ObjectLiteralExpression;
402
- let position: number;
403
- let toInsert: string;
404
- if (expr.properties.length == 0) {
405
- position = expr.getEnd() - 1;
406
- toInsert = ` ${metadataField}: [${symbolName}]\n`;
407
- } else {
408
- node = expr.properties[expr.properties.length - 1];
409
- position = node.getEnd();
410
- // Get the indentation of the last element, if any.
411
- const text = node.getFullText(source);
412
- const matches = text.match(/^\r?\n\s*/);
413
- if (matches && matches.length > 0) {
414
- toInsert = `,${matches[0]}${metadataField}: [${symbolName}]`;
415
- } else {
416
- toInsert = `, ${metadataField}: [${symbolName}]`;
417
- }
418
- }
419
- if (importPath !== null) {
420
- return [
421
- new InsertChange(ngModulePath, position, toInsert)
422
- // insertImport(source, ngModulePath, symbolName.replace(/\..*$/, ''), importPath)
423
- ];
424
- } else {
425
- return [new InsertChange(ngModulePath, position, toInsert)];
426
- }
427
- }
428
- const assignment = matchingProperties[0] as ts.PropertyAssignment;
429
-
430
- // If it's not an array, nothing we can do really.
431
- if (assignment.initializer.kind !== ts.SyntaxKind.ArrayLiteralExpression) {
432
- return [];
433
- }
434
-
435
- const arrLiteral = assignment.initializer as ts.ArrayLiteralExpression;
436
- if (arrLiteral.elements.length == 0) {
437
- // Forward the property.
438
- node = arrLiteral;
439
- } else {
440
- node = arrLiteral.elements;
441
- }
442
-
443
- if (!node) {
444
- console.error('No app module found. Please add your new class to your component.');
445
-
446
- return [];
447
- }
448
-
449
- if (Array.isArray(node)) {
450
- const nodeArray = (node as {}) as Array<ts.Node>;
451
- const symbolsArray = nodeArray.map(node => node.getText());
452
- if (symbolsArray.includes(symbolName)) {
453
- return [];
454
- }
455
-
456
- node = node[node.length - 1];
457
- }
458
-
459
- let toInsert: string;
460
- let position = node.getEnd();
461
- if (node.kind == ts.SyntaxKind.ObjectLiteralExpression) {
462
- // We haven't found the field in the metadata declaration. Insert a new
463
- // field.
464
- const expr = node as ts.ObjectLiteralExpression;
465
- if (expr.properties.length == 0) {
466
- position = expr.getEnd() - 1;
467
- toInsert = ` ${symbolName}\n`;
468
- } else {
469
- // Get the indentation of the last element, if any.
470
- const text = node.getFullText(source);
471
- if (text.match(/^\r?\r?\n/)) {
472
- toInsert = `,${text.match(/^\r?\n\s*/)[0]}${symbolName}`;
473
- } else {
474
- toInsert = `, ${symbolName}`;
475
- }
476
- }
477
- } else if (node.kind == ts.SyntaxKind.ArrayLiteralExpression) {
478
- // We found the field but it's empty. Insert it just before the `]`.
479
- position--;
480
- toInsert = `${symbolName}`;
481
- } else {
482
- // Get the indentation of the last element, if any.
483
- const text = node.getFullText(source);
484
- if (text.match(/^\r?\n/)) {
485
- toInsert = `,${text.match(/^\r?\n(\r?)\s*/)[0]}${symbolName}`;
486
- } else {
487
- toInsert = `, ${symbolName}`;
488
- }
489
- }
490
- if (importPath !== null) {
491
- return [
492
- new InsertChange(ngModulePath, position, toInsert),
493
- skipImport ? new NoopChange() : insertImport(source, ngModulePath, symbolName.replace(/\..*$/, ''), importPath)
494
- ];
495
- }
496
-
497
- return [new InsertChange(ngModulePath, position, toInsert)];
498
- }
499
-
500
- /**
501
- * Custom function to insert a declaration (component, pipe, directive)
502
- * into NgModule declarations. It also imports the component.
503
- */
504
- export function addDeclarationToModule(
505
- source: ts.SourceFile,
506
- modulePath: string,
507
- classifiedName: string,
508
- importPath: string
509
- ): Change[] {
510
- return addSymbolToNgModuleMetadata(source, modulePath, 'declarations', classifiedName, importPath);
511
- }
512
-
513
- /**
514
- * Custom function to insert an NgModule into NgModule imports. It also imports the module.
515
- */
516
- export function addImportToModule(
517
- source: ts.SourceFile,
518
- modulePath: string,
519
- classifiedName: string,
520
- importPath: string
521
- ): Change[] {
522
- return addSymbolToNgModuleMetadata(source, modulePath, 'imports', classifiedName, importPath);
523
- }
524
-
525
- /**
526
- * Custom function to insert a provider into NgModule. It also imports it.
527
- */
528
- export function addProviderToModule(
529
- source: ts.SourceFile,
530
- modulePath: string,
531
- classifiedName: string,
532
- importPath: string
533
- ): Change[] {
534
- return addSymbolToNgModuleMetadata(source, modulePath, 'providers', classifiedName, importPath);
535
- }
536
-
537
- /**
538
- * Custom function to insert an export into NgModule. It also imports it.
539
- */
540
- export function addExportToModule(
541
- source: ts.SourceFile,
542
- modulePath: string,
543
- classifiedName: string,
544
- importPath: string
545
- ): Change[] {
546
- return addSymbolToNgModuleMetadata(source, modulePath, 'exports', classifiedName, importPath);
547
- }
548
-
549
- /**
550
- * Custom function to insert an export into NgModule. It also imports it.
551
- */
552
- export function addBootstrapToModule(
553
- source: ts.SourceFile,
554
- modulePath: string,
555
- classifiedName: string,
556
- importPath: string
557
- ): Change[] {
558
- return addSymbolToNgModuleMetadata(source, modulePath, 'bootstrap', classifiedName, importPath);
559
- }
560
-
561
- /**
562
- * Custom function to insert an entryComponent into NgModule. It also imports it.
563
- */
564
- export function addEntryComponentToModule(
565
- source: ts.SourceFile,
566
- modulePath: string,
567
- classifiedName: string,
568
- importPath: string
569
- ): Change[] {
570
- return addSymbolToNgModuleMetadata(source, modulePath, 'entryComponents', classifiedName, importPath);
571
- }
572
-
573
- /**
574
- * Determine if an import already exists.
575
- */
576
- export function isImported(source: ts.SourceFile, classifiedName: string, importPath: string): boolean {
577
- const allNodes = getSourceNodes(source);
578
- const matchingNodes = allNodes
579
- .filter(node => node.kind === ts.SyntaxKind.ImportDeclaration)
580
- .filter((imp: ts.ImportDeclaration) => imp.moduleSpecifier.kind === ts.SyntaxKind.StringLiteral)
581
- .filter((imp: ts.ImportDeclaration) => {
582
- return (imp.moduleSpecifier as ts.StringLiteral).text === importPath;
583
- })
584
- .filter((imp: ts.ImportDeclaration) => {
585
- if (!imp.importClause) {
586
- return false;
587
- }
588
- const nodes = findNodes(imp.importClause, ts.SyntaxKind.ImportSpecifier).filter(
589
- n => n.getText() === classifiedName
590
- );
591
-
592
- return nodes.length > 0;
593
- });
594
-
595
- return matchingNodes.length > 0;
596
- }