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

Function getReferencedExportContainer

test/fixtures/snapshot/typescript.js:86783–86816  ·  view source on GitHub ↗
(nodeIn, prefixLocals)

Source from the content-addressed store, hash-verified

86781 // When resolved as an expression identifier, if the given node references an exported entity, return the declaration
86782 // node of the exported entity's container. Otherwise, return undefined.
86783 function getReferencedExportContainer(nodeIn, prefixLocals) {
86784 var _a;
86785 var node = ts.getParseTreeNode(nodeIn, ts.isIdentifier);
86786 if (node) {
86787 // When resolving the export container for the name of a module or enum
86788 // declaration, we need to start resolution at the declaration's container.
86789 // Otherwise, we could incorrectly resolve the export container as the
86790 // declaration if it contains an exported member with the same name.
86791 var symbol = getReferencedValueSymbol(node, /*startInDeclarationContainer*/ isNameOfModuleOrEnumDeclaration(node));
86792 if (symbol) {
86793 if (symbol.flags & 1048576 /* SymbolFlags.ExportValue */) {
86794 // If we reference an exported entity within the same module declaration, then whether
86795 // we prefix depends on the kind of entity. SymbolFlags.ExportHasLocal encompasses all the
86796 // kinds that we do NOT prefix.
86797 var exportSymbol = getMergedSymbol(symbol.exportSymbol);
86798 if (!prefixLocals && exportSymbol.flags & 944 /* SymbolFlags.ExportHasLocal */ && !(exportSymbol.flags & 3 /* SymbolFlags.Variable */)) {
86799 return undefined;
86800 }
86801 symbol = exportSymbol;
86802 }
86803 var parentSymbol_1 = getParentOfSymbol(symbol);
86804 if (parentSymbol_1) {
86805 if (parentSymbol_1.flags & 512 /* SymbolFlags.ValueModule */ && ((_a = parentSymbol_1.valueDeclaration) === null || _a === void 0 ? void 0 : _a.kind) === 305 /* SyntaxKind.SourceFile */) {
86806 var symbolFile = parentSymbol_1.valueDeclaration;
86807 var referenceFile = ts.getSourceFileOfNode(node);
86808 // If `node` accesses an export and that export isn't in the same file, then symbol is a namespace export, so return undefined.
86809 var symbolIsUmdExport = symbolFile !== referenceFile;
86810 return symbolIsUmdExport ? undefined : symbolFile;
86811 }
86812 return ts.findAncestor(node.parent, function (n) { return ts.isModuleOrEnumDeclaration(n) && getSymbolOfNode(n) === parentSymbol_1; });
86813 }
86814 }
86815 }
86816 }
86817 // When resolved as an expression identifier, if the given node references an import, return the declaration of
86818 // that import. Otherwise, return undefined.
86819 function getReferencedImportDeclaration(nodeIn) {

Callers

nothing calls this directly

Calls 5

getReferencedValueSymbolFunction · 0.85
getMergedSymbolFunction · 0.85
getParentOfSymbolFunction · 0.85
getSymbolOfNodeFunction · 0.85

Tested by

no test coverage detected