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

Function getSymbolChain

test/fixtures/snapshot/typescript.js:53424–53489  ·  view source on GitHub ↗

@param endOfChain Set to false for recursive calls; non-recursive calls should always output something.

(symbol, meaning, endOfChain)

Source from the content-addressed store, hash-verified

53422 return chain;
53423 /** @param endOfChain Set to false for recursive calls; non-recursive calls should always output something. */
53424 function getSymbolChain(symbol, meaning, endOfChain) {
53425 var accessibleSymbolChain = getAccessibleSymbolChain(symbol, context.enclosingDeclaration, meaning, !!(context.flags & 128 /* NodeBuilderFlags.UseOnlyExternalAliasing */));
53426 var parentSpecifiers;
53427 if (!accessibleSymbolChain ||
53428 needsQualification(accessibleSymbolChain[0], context.enclosingDeclaration, accessibleSymbolChain.length === 1 ? meaning : getQualifiedLeftMeaning(meaning))) {
53429 // Go up and add our parent.
53430 var parents_1 = getContainersOfSymbol(accessibleSymbolChain ? accessibleSymbolChain[0] : symbol, context.enclosingDeclaration, meaning);
53431 if (ts.length(parents_1)) {
53432 parentSpecifiers = parents_1.map(function (symbol) {
53433 return ts.some(symbol.declarations, hasNonGlobalAugmentationExternalModuleSymbol)
53434 ? getSpecifierForModuleSymbol(symbol, context)
53435 : undefined;
53436 });
53437 var indices = parents_1.map(function (_, i) { return i; });
53438 indices.sort(sortByBestName);
53439 var sortedParents = indices.map(function (i) { return parents_1[i]; });
53440 for (var _i = 0, sortedParents_1 = sortedParents; _i < sortedParents_1.length; _i++) {
53441 var parent = sortedParents_1[_i];
53442 var parentChain = getSymbolChain(parent, getQualifiedLeftMeaning(meaning), /*endOfChain*/ false);
53443 if (parentChain) {
53444 if (parent.exports && parent.exports.get("export=" /* InternalSymbolName.ExportEquals */) &&
53445 getSymbolIfSameReference(parent.exports.get("export=" /* InternalSymbolName.ExportEquals */), symbol)) {
53446 // parentChain root _is_ symbol - symbol is a module export=, so it kinda looks like it's own parent
53447 // No need to lookup an alias for the symbol in itself
53448 accessibleSymbolChain = parentChain;
53449 break;
53450 }
53451 accessibleSymbolChain = parentChain.concat(accessibleSymbolChain || [getAliasForSymbolInContainer(parent, symbol) || symbol]);
53452 break;
53453 }
53454 }
53455 }
53456 }
53457 if (accessibleSymbolChain) {
53458 return accessibleSymbolChain;
53459 }
53460 if (
53461 // If this is the last part of outputting the symbol, always output. The cases apply only to parent symbols.
53462 endOfChain ||
53463 // If a parent symbol is an anonymous type, don't write it.
53464 !(symbol.flags & (2048 /* SymbolFlags.TypeLiteral */ | 4096 /* SymbolFlags.ObjectLiteral */))) {
53465 // If a parent symbol is an external module, don't write it. (We prefer just `x` vs `"foo/bar".x`.)
53466 if (!endOfChain && !yieldModuleSymbol && !!ts.forEach(symbol.declarations, hasNonGlobalAugmentationExternalModuleSymbol)) {
53467 return;
53468 }
53469 return [symbol];
53470 }
53471 function sortByBestName(a, b) {
53472 var specifierA = parentSpecifiers[a];
53473 var specifierB = parentSpecifiers[b];
53474 if (specifierA && specifierB) {
53475 var isBRelative = ts.pathIsRelative(specifierB);
53476 if (ts.pathIsRelative(specifierA) === isBRelative) {
53477 // Both relative or both non-relative, sort by number of parts
53478 return ts.moduleSpecifiers.countPathComponents(specifierA) - ts.moduleSpecifiers.countPathComponents(specifierB);
53479 }
53480 if (isBRelative) {
53481 // A is non-relative, B is relative: prefer A

Callers 1

lookupSymbolChainWorkerFunction · 0.85

Calls 14

getAccessibleSymbolChainFunction · 0.85
needsQualificationFunction · 0.85
getQualifiedLeftMeaningFunction · 0.85
getContainersOfSymbolFunction · 0.85
getSymbolIfSameReferenceFunction · 0.85
someMethod · 0.80
sortMethod · 0.80
concatMethod · 0.80
mapMethod · 0.65
getMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…