(ref: UnresolvedRef, specifier: string, declaringFile: string, context: ResolutionContext)
| 3788 | * count for the file (see declaringFileAnswers). |
| 3789 | */ |
| 3790 | export function reachesAmbientModule(ref: UnresolvedRef, specifier: string, declaringFile: string, context: ResolutionContext): boolean { |
| 3791 | const answers = declaringFileAnswers(declaringFile, ref.filePath, context); |
| 3792 | if (answers && isInModuleBlock(ref.filePath, ref.line, ref.column ?? 0, specifier, context)) return true; |
| 3793 | const mappings = context.getImportMappings(ref.filePath, ref.language); |
| 3794 | const relative = (source: string): boolean => source.startsWith('.') || source.startsWith('/'); |
| 3795 | const leadsTo = (source: string, through: (file: string) => boolean): boolean => { |
| 3796 | if (source === specifier) return answers; |
| 3797 | if (!relative(source)) return false; |
| 3798 | const file = resolveImportPath(source, ref.filePath, ref.language, context); |
| 3799 | return file !== null && (file === declaringFile || through(file)); |
| 3800 | }; |
| 3801 | const head = ref.referenceName.split('.')[0]!; |
| 3802 | const binding = mappings.find((m) => m.localName === head); |
| 3803 | if (binding) { |
| 3804 | return leadsTo(binding.source, (file) => context.getImportMappings(file, ref.language).some((m) => m.source === specifier)); |
| 3805 | } |
| 3806 | return LAST_NAME_KINDS.has(ref.referenceKind) && mappings.some((m) => leadsTo(m.source, () => false)); |
| 3807 | } |
| 3808 | |
| 3809 | /** |
| 3810 | * The file's import mappings as a Python dotted reference reads them. Its |
no test coverage detected