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

Function reachesAmbientModule

src/resolution/import-resolver.ts:4038–4055  ·  view source on GitHub ↗
(ref: UnresolvedRef, specifier: string, declaringFile: string, context: ResolutionContext)

Source from the content-addressed store, hash-verified

4036 * count for the file (see declaringFileAnswers).
4037 */
4038export function reachesAmbientModule(ref: UnresolvedRef, specifier: string, declaringFile: string, context: ResolutionContext): boolean {
4039 const answers = declaringFileAnswers(declaringFile, ref.filePath, context);
4040 if (answers && isInModuleBlock(ref.filePath, ref.line, ref.column ?? 0, specifier, context)) return true;
4041 const mappings = context.getImportMappings(ref.filePath, ref.language);
4042 const relative = (source: string): boolean => source.startsWith('.') || source.startsWith('/');
4043 const leadsTo = (source: string, through: (file: string) => boolean): boolean => {
4044 if (source === specifier) return answers;
4045 if (!relative(source)) return false;
4046 const file = resolveImportPath(source, ref.filePath, ref.language, context);
4047 return file !== null && (file === declaringFile || through(file));
4048 };
4049 const head = ref.referenceName.split('.')[0]!;
4050 const binding = mappings.find((m) => m.localName === head);
4051 if (binding) {
4052 return leadsTo(binding.source, (file) => context.getImportMappings(file, ref.language).some((m) => m.source === specifier));
4053 }
4054 return LAST_NAME_KINDS.has(ref.referenceKind) && mappings.some((m) => leadsTo(m.source, () => false));
4055}
4056
4057/**
4058 * The file's import mappings as a Python dotted reference reads them. Its

Callers 1

resolveOneInMethod · 0.90

Calls 5

declaringFileAnswersFunction · 0.90
isInModuleBlockFunction · 0.90
leadsToFunction · 0.85
getImportMappingsMethod · 0.80
hasMethod · 0.80

Tested by

no test coverage detected