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

Function getContainersOfSymbol

test/fixtures/snapshot/typescript.js:51603–51659  ·  view source on GitHub ↗

* Attempts to find the symbol corresponding to the container a symbol is in - usually this * is just its' `.parent`, but for locals, this value is `undefined`

(symbol, enclosingDeclaration, meaning)

Source from the content-addressed store, hash-verified

51601 * is just its' `.parent`, but for locals, this value is `undefined`
51602 */
51603 function getContainersOfSymbol(symbol, enclosingDeclaration, meaning) {
51604 var container = getParentOfSymbol(symbol);
51605 // Type parameters end up in the `members` lists but are not externally visible
51606 if (container && !(symbol.flags & 262144 /* SymbolFlags.TypeParameter */)) {
51607 var additionalContainers = ts.mapDefined(container.declarations, fileSymbolIfFileSymbolExportEqualsContainer);
51608 var reexportContainers = enclosingDeclaration && getAlternativeContainingModules(symbol, enclosingDeclaration);
51609 var objectLiteralContainer = getVariableDeclarationOfObjectLiteral(container, meaning);
51610 if (enclosingDeclaration &&
51611 container.flags & getQualifiedLeftMeaning(meaning) &&
51612 getAccessibleSymbolChain(container, enclosingDeclaration, 1920 /* SymbolFlags.Namespace */, /*externalOnly*/ false)) {
51613 return ts.append(ts.concatenate(ts.concatenate([container], additionalContainers), reexportContainers), objectLiteralContainer); // This order expresses a preference for the real container if it is in scope
51614 }
51615 // we potentially have a symbol which is a member of the instance side of something - look for a variable in scope with the container's type
51616 // which may be acting like a namespace (eg, `Symbol` acts like a namespace when looking up `Symbol.toStringTag`)
51617 var firstVariableMatch = !(container.flags & getQualifiedLeftMeaning(meaning))
51618 && container.flags & 788968 /* SymbolFlags.Type */
51619 && getDeclaredTypeOfSymbol(container).flags & 524288 /* TypeFlags.Object */
51620 && meaning === 111551 /* SymbolFlags.Value */
51621 ? forEachSymbolTableInScope(enclosingDeclaration, function (t) {
51622 return ts.forEachEntry(t, function (s) {
51623 if (s.flags & getQualifiedLeftMeaning(meaning) && getTypeOfSymbol(s) === getDeclaredTypeOfSymbol(container)) {
51624 return s;
51625 }
51626 });
51627 }) : undefined;
51628 var res = firstVariableMatch ? __spreadArray(__spreadArray([firstVariableMatch], additionalContainers, true), [container], false) : __spreadArray(__spreadArray([], additionalContainers, true), [container], false);
51629 res = ts.append(res, objectLiteralContainer);
51630 res = ts.addRange(res, reexportContainers);
51631 return res;
51632 }
51633 var candidates = ts.mapDefined(symbol.declarations, function (d) {
51634 if (!ts.isAmbientModule(d) && d.parent) {
51635 // direct children of a module
51636 if (hasNonGlobalAugmentationExternalModuleSymbol(d.parent)) {
51637 return getSymbolOfNode(d.parent);
51638 }
51639 // export ='d member of an ambient module
51640 if (ts.isModuleBlock(d.parent) && d.parent.parent && resolveExternalModuleSymbol(getSymbolOfNode(d.parent.parent)) === symbol) {
51641 return getSymbolOfNode(d.parent.parent);
51642 }
51643 }
51644 if (ts.isClassExpression(d) && ts.isBinaryExpression(d.parent) && d.parent.operatorToken.kind === 63 /* SyntaxKind.EqualsToken */ && ts.isAccessExpression(d.parent.left) && ts.isEntityNameExpression(d.parent.left.expression)) {
51645 if (ts.isModuleExportsAccessExpression(d.parent.left) || ts.isExportsIdentifier(d.parent.left.expression)) {
51646 return getSymbolOfNode(ts.getSourceFileOfNode(d));
51647 }
51648 checkExpressionCached(d.parent.left.expression);
51649 return getNodeLinks(d.parent.left.expression).resolvedSymbol;
51650 }
51651 });
51652 if (!ts.length(candidates)) {
51653 return undefined;
51654 }
51655 return ts.mapDefined(candidates, function (candidate) { return getAliasForSymbolInContainer(candidate, symbol) ? candidate : undefined; });
51656 function fileSymbolIfFileSymbolExportEqualsContainer(d) {
51657 return container && getFileSymbolIfFileSymbolExportEqualsContainer(d, container);
51658 }
51659 }
51660 function getVariableDeclarationOfObjectLiteral(symbol, meaning) {

Callers 2

isAnySymbolAccessibleFunction · 0.85
getSymbolChainFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…