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

Function tryGetModuleNameFromAmbientModule

test/fixtures/snapshot/typescript.js:122336–122380  ·  view source on GitHub ↗
(moduleSymbol, checker)

Source from the content-addressed store, hash-verified

122334 return sortedPaths;
122335 }
122336 function tryGetModuleNameFromAmbientModule(moduleSymbol, checker) {
122337 var _a;
122338 var decl = (_a = moduleSymbol.declarations) === null || _a === void 0 ? void 0 : _a.find(function (d) { return ts.isNonGlobalAmbientModule(d) && (!ts.isExternalModuleAugmentation(d) || !ts.isExternalModuleNameRelative(ts.getTextOfIdentifierOrLiteral(d.name))); });
122339 if (decl) {
122340 return decl.name.text;
122341 }
122342 // the module could be a namespace, which is export through "export=" from an ambient module.
122343 /**
122344 * declare module "m" {
122345 * namespace ns {
122346 * class c {}
122347 * }
122348 * export = ns;
122349 * }
122350 */
122351 // `import {c} from "m";` is valid, in which case, `moduleSymbol` is "ns", but the module name should be "m"
122352 var ambientModuleDeclareCandidates = ts.mapDefined(moduleSymbol.declarations, function (d) {
122353 var _a, _b, _c, _d;
122354 if (!ts.isModuleDeclaration(d))
122355 return;
122356 var topNamespace = getTopNamespace(d);
122357 if (!(((_a = topNamespace === null || topNamespace === void 0 ? void 0 : topNamespace.parent) === null || _a === void 0 ? void 0 : _a.parent)
122358 && ts.isModuleBlock(topNamespace.parent) && ts.isAmbientModule(topNamespace.parent.parent) && ts.isSourceFile(topNamespace.parent.parent.parent)))
122359 return;
122360 var exportAssignment = (_d = (_c = (_b = topNamespace.parent.parent.symbol.exports) === null || _b === void 0 ? void 0 : _b.get("export=")) === null || _c === void 0 ? void 0 : _c.valueDeclaration) === null || _d === void 0 ? void 0 : _d.expression;
122361 if (!exportAssignment)
122362 return;
122363 var exportSymbol = checker.getSymbolAtLocation(exportAssignment);
122364 if (!exportSymbol)
122365 return;
122366 var originalExportSymbol = (exportSymbol === null || exportSymbol === void 0 ? void 0 : exportSymbol.flags) & 2097152 /* SymbolFlags.Alias */ ? checker.getAliasedSymbol(exportSymbol) : exportSymbol;
122367 if (originalExportSymbol === d.symbol)
122368 return topNamespace.parent.parent;
122369 function getTopNamespace(namespaceDeclaration) {
122370 while (namespaceDeclaration.flags & 4 /* NodeFlags.NestedNamespace */) {
122371 namespaceDeclaration = namespaceDeclaration.parent;
122372 }
122373 return namespaceDeclaration;
122374 }
122375 });
122376 var ambientModuleDeclare = ambientModuleDeclareCandidates[0];
122377 if (ambientModuleDeclare) {
122378 return ambientModuleDeclare.name.text;
122379 }
122380 }
122381 function tryGetModuleNameFromPaths(relativeToBaseUrlWithIndex, relativeToBaseUrl, paths) {
122382 for (var key in paths) {
122383 for (var _i = 0, _a = paths[key]; _i < _a.length; _i++) {

Callers 1

Calls 3

getTopNamespaceFunction · 0.85
findMethod · 0.65
getMethod · 0.65

Tested by

no test coverage detected