MCPcopy Index your code
hub / github.com/nodejs/node / createExistingImportMap

Function createExistingImportMap

test/fixtures/snapshot/typescript.js:153313–153344  ·  view source on GitHub ↗
(checker, importingFile, compilerOptions)

Source from the content-addressed store, hash-verified

153311 });
153312 }
153313 function createExistingImportMap(checker, importingFile, compilerOptions) {
153314 var importMap;
153315 for (var _i = 0, _a = importingFile.imports; _i < _a.length; _i++) {
153316 var moduleSpecifier = _a[_i];
153317 var i = ts.importFromModuleSpecifier(moduleSpecifier);
153318 if (ts.isVariableDeclarationInitializedToRequire(i.parent)) {
153319 var moduleSymbol = checker.resolveExternalModuleName(moduleSpecifier);
153320 if (moduleSymbol) {
153321 (importMap || (importMap = ts.createMultiMap())).add(ts.getSymbolId(moduleSymbol), i.parent);
153322 }
153323 }
153324 else if (i.kind === 266 /* SyntaxKind.ImportDeclaration */ || i.kind === 265 /* SyntaxKind.ImportEqualsDeclaration */) {
153325 var moduleSymbol = checker.getSymbolAtLocation(moduleSpecifier);
153326 if (moduleSymbol) {
153327 (importMap || (importMap = ts.createMultiMap())).add(ts.getSymbolId(moduleSymbol), i);
153328 }
153329 }
153330 }
153331 return {
153332 getImportsForExportInfo: function (_a) {
153333 var moduleSymbol = _a.moduleSymbol, exportKind = _a.exportKind, targetFlags = _a.targetFlags, symbol = _a.symbol;
153334 // Can't use an es6 import for a type in JS.
153335 if (!(targetFlags & 111551 /* SymbolFlags.Value */) && ts.isSourceFileJS(importingFile))
153336 return ts.emptyArray;
153337 var matchingDeclarations = importMap === null || importMap === void 0 ? void 0 : importMap.get(ts.getSymbolId(moduleSymbol));
153338 if (!matchingDeclarations)
153339 return ts.emptyArray;
153340 var importKind = getImportKind(importingFile, exportKind, compilerOptions);
153341 return matchingDeclarations.map(function (declaration) { return ({ declaration: declaration, importKind: importKind, symbol: symbol, targetFlags: targetFlags }); });
153342 }
153343 };
153344 }
153345 function shouldUseRequire(sourceFile, program) {
153346 // 1. TypeScript files don't use require variable declarations
153347 if (!ts.isSourceFileJS(sourceFile)) {

Callers 2

getImportFixesFunction · 0.85

Calls 4

getImportKindFunction · 0.85
addMethod · 0.65
getMethod · 0.65
mapMethod · 0.65

Tested by

no test coverage detected