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

Function getSpecifierForModuleSymbol

test/fixtures/snapshot/typescript.js:53531–53591  ·  view source on GitHub ↗
(symbol, context, overrideImportMode)

Source from the content-addressed store, hash-verified

53529 return top;
53530 }
53531 function getSpecifierForModuleSymbol(symbol, context, overrideImportMode) {
53532 var _a;
53533 var file = ts.getDeclarationOfKind(symbol, 305 /* SyntaxKind.SourceFile */);
53534 if (!file) {
53535 var equivalentFileSymbol = ts.firstDefined(symbol.declarations, function (d) { return getFileSymbolIfFileSymbolExportEqualsContainer(d, symbol); });
53536 if (equivalentFileSymbol) {
53537 file = ts.getDeclarationOfKind(equivalentFileSymbol, 305 /* SyntaxKind.SourceFile */);
53538 }
53539 }
53540 if (file && file.moduleName !== undefined) {
53541 // Use the amd name if it is available
53542 return file.moduleName;
53543 }
53544 if (!file) {
53545 if (context.tracker.trackReferencedAmbientModule) {
53546 var ambientDecls = ts.filter(symbol.declarations, ts.isAmbientModule);
53547 if (ts.length(ambientDecls)) {
53548 for (var _i = 0, _b = ambientDecls; _i < _b.length; _i++) {
53549 var decl = _b[_i];
53550 context.tracker.trackReferencedAmbientModule(decl, symbol);
53551 }
53552 }
53553 }
53554 if (ambientModuleSymbolRegex.test(symbol.escapedName)) {
53555 return symbol.escapedName.substring(1, symbol.escapedName.length - 1);
53556 }
53557 }
53558 if (!context.enclosingDeclaration || !context.tracker.moduleResolverHost) {
53559 // If there's no context declaration, we can't lookup a non-ambient specifier, so we just use the symbol name
53560 if (ambientModuleSymbolRegex.test(symbol.escapedName)) {
53561 return symbol.escapedName.substring(1, symbol.escapedName.length - 1);
53562 }
53563 return ts.getSourceFileOfNode(ts.getNonAugmentationDeclaration(symbol)).fileName; // A resolver may not be provided for baselines and errors - in those cases we use the fileName in full
53564 }
53565 var contextFile = ts.getSourceFileOfNode(ts.getOriginalNode(context.enclosingDeclaration));
53566 var resolutionMode = overrideImportMode || (contextFile === null || contextFile === void 0 ? void 0 : contextFile.impliedNodeFormat);
53567 var cacheKey = getSpecifierCacheKey(contextFile.path, resolutionMode);
53568 var links = getSymbolLinks(symbol);
53569 var specifier = links.specifierCache && links.specifierCache.get(cacheKey);
53570 if (!specifier) {
53571 var isBundle_1 = !!ts.outFile(compilerOptions);
53572 // For declaration bundles, we need to generate absolute paths relative to the common source dir for imports,
53573 // just like how the declaration emitter does for the ambient module declarations - we can easily accomplish this
53574 // using the `baseUrl` compiler option (which we would otherwise never use in declaration emit) and a non-relative
53575 // specifier preference
53576 var moduleResolverHost = context.tracker.moduleResolverHost;
53577 var specifierCompilerOptions = isBundle_1 ? __assign(__assign({}, compilerOptions), { baseUrl: moduleResolverHost.getCommonSourceDirectory() }) : compilerOptions;
53578 specifier = ts.first(ts.moduleSpecifiers.getModuleSpecifiers(symbol, checker, specifierCompilerOptions, contextFile, moduleResolverHost, {
53579 importModuleSpecifierPreference: isBundle_1 ? "non-relative" : "project-relative",
53580 importModuleSpecifierEnding: isBundle_1 ? "minimal"
53581 : resolutionMode === ts.ModuleKind.ESNext ? "js"
53582 : undefined,
53583 }, { overrideImportMode: overrideImportMode }));
53584 (_a = links.specifierCache) !== null && _a !== void 0 ? _a : (links.specifierCache = new ts.Map());
53585 links.specifierCache.set(cacheKey, specifier);
53586 }
53587 return specifier;
53588 function getSpecifierCacheKey(path, mode) {

Callers 5

getSymbolChainFunction · 0.85
symbolToTypeNodeFunction · 0.85
serializeSymbolWorkerFunction · 0.85
serializeAsAliasFunction · 0.85

Calls 9

getSpecifierCacheKeyFunction · 0.85
getSymbolLinksFunction · 0.85
filterMethod · 0.65
getMethod · 0.65
lengthMethod · 0.45
testMethod · 0.45
firstMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…