(ref: UnresolvedRef, specifier: string, declaringFile: string, context: ResolutionContext)
| 4036 | * count for the file (see declaringFileAnswers). |
| 4037 | */ |
| 4038 | export 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 |
no test coverage detected