UNPKG

@taiga-ui/cdk

Version:

Base library for creating Angular components and applications using Taiga UI principles regarding of actual visual appearance

28 lines (27 loc) 1.46 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getNamedImportReferences = void 0; const ng_morph_1 = require("ng-morph"); const constants_1 = require("../constants"); function getNamedImportReferences(namedImport, moduleSpecifier = ['**/**'], files = constants_1.ALL_TS_FILES) { const importDeclarations = (0, ng_morph_1.getImports)(files, { namedImports: [namedImport], moduleSpecifier: Array.isArray(moduleSpecifier) ? moduleSpecifier : [moduleSpecifier, `${moduleSpecifier}/**`], }); const namedImports = importDeclarations.map((declaration) => { var _a; return (_a = declaration .getNamedImports() .find((specifier) => specifier.getName() === namedImport)) === null || _a === void 0 ? void 0 : _a.getNameNode(); }); return (0, ng_morph_1.arrayFlat)(namedImports.map((specifier) => (specifier === null || specifier === void 0 ? void 0 : specifier.findReferencesAsNodes().filter( /** * Otherwise, each `findReferencesAsNodes` will return references across THE WHOLE project. * It will cause a lot of duplicates in the result and significantly slow down the process. */ (ref) => ref.getSourceFile().getFilePath() === (specifier === null || specifier === void 0 ? void 0 : specifier.getSourceFile().getFilePath()))) || [])); } exports.getNamedImportReferences = getNamedImportReferences;