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

Function handleDirectImports

test/fixtures/snapshot/typescript.js:136248–136316  ·  view source on GitHub ↗
(exportingModuleSymbol)

Source from the content-addressed store, hash-verified

136246 return indirectUserDeclarations.map(ts.getSourceFileOfNode);
136247 }
136248 function handleDirectImports(exportingModuleSymbol) {
136249 var theseDirectImports = getDirectImports(exportingModuleSymbol);
136250 if (theseDirectImports) {
136251 for (var _i = 0, theseDirectImports_1 = theseDirectImports; _i < theseDirectImports_1.length; _i++) {
136252 var direct = theseDirectImports_1[_i];
136253 if (!markSeenDirectImport(direct)) {
136254 continue;
136255 }
136256 if (cancellationToken)
136257 cancellationToken.throwIfCancellationRequested();
136258 switch (direct.kind) {
136259 case 208 /* SyntaxKind.CallExpression */:
136260 if (ts.isImportCall(direct)) {
136261 handleImportCall(direct);
136262 break;
136263 }
136264 if (!isAvailableThroughGlobal) {
136265 var parent = direct.parent;
136266 if (exportKind === 2 /* ExportKind.ExportEquals */ && parent.kind === 254 /* SyntaxKind.VariableDeclaration */) {
136267 var name = parent.name;
136268 if (name.kind === 79 /* SyntaxKind.Identifier */) {
136269 directImports.push(name);
136270 break;
136271 }
136272 }
136273 }
136274 break;
136275 case 79 /* SyntaxKind.Identifier */: // for 'const x = require("y");
136276 break; // TODO: GH#23879
136277 case 265 /* SyntaxKind.ImportEqualsDeclaration */:
136278 handleNamespaceImport(direct, direct.name, ts.hasSyntacticModifier(direct, 1 /* ModifierFlags.Export */), /*alreadyAddedDirect*/ false);
136279 break;
136280 case 266 /* SyntaxKind.ImportDeclaration */:
136281 directImports.push(direct);
136282 var namedBindings = direct.importClause && direct.importClause.namedBindings;
136283 if (namedBindings && namedBindings.kind === 268 /* SyntaxKind.NamespaceImport */) {
136284 handleNamespaceImport(direct, namedBindings.name, /*isReExport*/ false, /*alreadyAddedDirect*/ true);
136285 }
136286 else if (!isAvailableThroughGlobal && ts.isDefaultImport(direct)) {
136287 addIndirectUser(getSourceFileLikeForImportDeclaration(direct)); // Add a check for indirect uses to handle synthetic default imports
136288 }
136289 break;
136290 case 272 /* SyntaxKind.ExportDeclaration */:
136291 if (!direct.exportClause) {
136292 // This is `export * from "foo"`, so imports of this module may import the export too.
136293 handleDirectImports(getContainingModuleSymbol(direct, checker));
136294 }
136295 else if (direct.exportClause.kind === 274 /* SyntaxKind.NamespaceExport */) {
136296 // `export * as foo from "foo"` add to indirect uses
136297 addIndirectUser(getSourceFileLikeForImportDeclaration(direct), /** addTransitiveDependencies */ true);
136298 }
136299 else {
136300 // This is `export { foo } from "foo"` and creates an alias symbol, so recursive search will get handle re-exports.
136301 directImports.push(direct);
136302 }
136303 break;
136304 case 200 /* SyntaxKind.ImportType */:
136305 // Only check for typeof import('xyz')

Callers 1

getImportersForExportFunction · 0.85

Calls 8

getDirectImportsFunction · 0.85
handleImportCallFunction · 0.85
handleNamespaceImportFunction · 0.85
addIndirectUserFunction · 0.85
isExportedFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected