MCPcopy
hub / github.com/angular/angular-cli / isImported

Function isImported

packages/schematics/angular/utility/ast-utils.ts:547–570  ·  view source on GitHub ↗
(
  source: ts.SourceFile,
  classifiedName: string,
  importPath: string,
)

Source from the content-addressed store, hash-verified

545 * Determine if an import already exists.
546 */
547export function isImported(
548 source: ts.SourceFile,
549 classifiedName: string,
550 importPath: string,
551): boolean {
552 const allNodes = getSourceNodes(source);
553 const matchingNodes = allNodes
554 .filter(ts.isImportDeclaration)
555 .filter(
556 (imp) => ts.isStringLiteral(imp.moduleSpecifier) && imp.moduleSpecifier.text === importPath,
557 )
558 .filter((imp) => {
559 if (!imp.importClause) {
560 return false;
561 }
562 const nodes = findNodes(imp.importClause, ts.isImportSpecifier).filter(
563 (n) => n.getText() === classifiedName,
564 );
565
566 return nodes.length > 0;
567 });
568
569 return matchingNodes.length > 0;
570}
571
572/**
573 * Returns the RouterModule declaration from NgModule metadata, if any.

Callers

nothing calls this directly

Calls 2

getSourceNodesFunction · 0.85
findNodesFunction · 0.85

Tested by

no test coverage detected