MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / findAmbientModuleExport

Function findAmbientModuleExport

src/resolution/ambient-modules.ts:836–859  ·  view source on GitHub ↗
(
  specifier: string,
  want: { isDefault: boolean; isNamespace: boolean; exportedName: string; memberName: string | null },
  ref: UnresolvedRef,
  context: ResolutionContext
)

Source from the content-addressed store, hash-verified

834 * then the first.
835 */
836export function findAmbientModuleExport(
837 specifier: string,
838 want: { isDefault: boolean; isNamespace: boolean; exportedName: string; memberName: string | null },
839 ref: UnresolvedRef,
840 context: ResolutionContext
841): Node | undefined {
842 if (want.isNamespace && (!want.memberName || want.memberName.includes('.'))) return undefined;
843 for (const mod of declarationsFor(specifier, ref.filePath, context)) {
844 const members = blockMembers(mod, context);
845 let found: Node[] | undefined;
846 if (want.isDefault) {
847 found = mod.defaultName ? members.get(mod.defaultName) : undefined;
848 } else {
849 const name = want.isNamespace ? want.memberName! : want.exportedName;
850 const local = mod.exportAliases.get(name);
851 // Under an export clause the clause decides; otherwise what the body exports.
852 found = local !== undefined ? members.get(local) : members.get(name)?.filter((n) => n.isExported);
853 }
854 if (found && found.length > 0) {
855 return [...found].sort((a, b) => kindRank(ref.referenceKind, a.kind) - kindRank(ref.referenceKind, b.kind))[0];
856 }
857 }
858 return undefined;
859}
860
861/**
862 * The file node of the declaration file that declares the module `specifier`

Callers 2

findImportedExportFunction · 0.90
ambientModuleDeclaresFunction · 0.85

Calls 4

declarationsForFunction · 0.85
blockMembersFunction · 0.85
kindRankFunction · 0.70
getMethod · 0.65

Tested by

no test coverage detected