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

Function reachesAmbientModule

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

Source from the content-addressed store, hash-verified

3615 * count for the file (see declaringFileAnswers).
3616 */
3617export function reachesAmbientModule(ref: UnresolvedRef, specifier: string, declaringFile: string, context: ResolutionContext): boolean {
3618 const answers = declaringFileAnswers(declaringFile, ref.filePath, context);
3619 if (answers && isInModuleBlock(ref.filePath, ref.line, ref.column ?? 0, specifier, context)) return true;
3620 const mappings = context.getImportMappings(ref.filePath, ref.language);
3621 const relative = (source: string): boolean => source.startsWith('.') || source.startsWith('/');
3622 const leadsTo = (source: string, through: (file: string) => boolean): boolean => {
3623 if (source === specifier) return answers;
3624 if (!relative(source)) return false;
3625 const file = resolveImportPath(source, ref.filePath, ref.language, context);
3626 return file !== null && (file === declaringFile || through(file));
3627 };
3628 const head = ref.referenceName.split('.')[0]!;
3629 const binding = mappings.find((m) => m.localName === head);
3630 if (binding) {
3631 return leadsTo(binding.source, (file) => context.getImportMappings(file, ref.language).some((m) => m.source === specifier));
3632 }
3633 return LAST_NAME_KINDS.has(ref.referenceKind) && mappings.some((m) => leadsTo(m.source, () => false));
3634}
3635
3636/**
3637 * 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