MCPcopy Create free account
hub / github.com/nodejs/node / searchForImportsOfExport

Function searchForImportsOfExport

test/fixtures/snapshot/typescript.js:137808–137844  ·  view source on GitHub ↗

Search for all imports of a given exported symbol using `State.getImportSearches`.

(exportLocation, exportSymbol, exportInfo, state)

Source from the content-addressed store, hash-verified

137806 }());
137807 /** Search for all imports of a given exported symbol using `State.getImportSearches`. */
137808 function searchForImportsOfExport(exportLocation, exportSymbol, exportInfo, state) {
137809 var _a = state.getImportSearches(exportSymbol, exportInfo), importSearches = _a.importSearches, singleReferences = _a.singleReferences, indirectUsers = _a.indirectUsers;
137810 // For `import { foo as bar }` just add the reference to `foo`, and don't otherwise search in the file.
137811 if (singleReferences.length) {
137812 var addRef = state.referenceAdder(exportSymbol);
137813 for (var _i = 0, singleReferences_1 = singleReferences; _i < singleReferences_1.length; _i++) {
137814 var singleRef = singleReferences_1[_i];
137815 if (shouldAddSingleReference(singleRef, state))
137816 addRef(singleRef);
137817 }
137818 }
137819 // For each import, find all references to that import in its source file.
137820 for (var _b = 0, importSearches_1 = importSearches; _b < importSearches_1.length; _b++) {
137821 var _c = importSearches_1[_b], importLocation = _c[0], importSymbol = _c[1];
137822 getReferencesInSourceFile(importLocation.getSourceFile(), state.createSearch(importLocation, importSymbol, 1 /* ImportExport.Export */), state);
137823 }
137824 if (indirectUsers.length) {
137825 var indirectSearch = void 0;
137826 switch (exportInfo.exportKind) {
137827 case 0 /* ExportKind.Named */:
137828 indirectSearch = state.createSearch(exportLocation, exportSymbol, 1 /* ImportExport.Export */);
137829 break;
137830 case 1 /* ExportKind.Default */:
137831 // Search for a property access to '.default'. This can't be renamed.
137832 indirectSearch = state.options.use === 2 /* FindReferencesUse.Rename */ ? undefined : state.createSearch(exportLocation, exportSymbol, 1 /* ImportExport.Export */, { text: "default" });
137833 break;
137834 case 2 /* ExportKind.ExportEquals */:
137835 break;
137836 }
137837 if (indirectSearch) {
137838 for (var _d = 0, indirectUsers_1 = indirectUsers; _d < indirectUsers_1.length; _d++) {
137839 var indirectUser = indirectUsers_1[_d];
137840 searchForName(indirectUser, indirectSearch, state);
137841 }
137842 }
137843 }
137844 }
137845 function eachExportReference(sourceFiles, checker, cancellationToken, exportSymbol, exportingModuleSymbol, exportName, isDefaultExport, cb) {
137846 var importTracker = FindAllReferences.createImportTracker(sourceFiles, new ts.Set(sourceFiles.map(function (f) { return f.fileName; })), checker, cancellationToken);
137847 var _a = importTracker(exportSymbol, { exportKind: isDefaultExport ? 1 /* ExportKind.Default */ : 0 /* ExportKind.Named */, exportingModuleSymbol: exportingModuleSymbol }, /*isForRename*/ false), importSearches = _a.importSearches, indirectUsers = _a.indirectUsers, singleReferences = _a.singleReferences;

Calls 4

shouldAddSingleReferenceFunction · 0.85
addRefFunction · 0.85
searchForNameFunction · 0.85

Tested by

no test coverage detected