The script declarations of `specifier` an import in `fromFile` can mean (see reachesProgram), the files nearest it first.
(specifier: string, fromFile: string, context: ResolutionContext)
| 778 | |
| 779 | /** The script declarations of `specifier` an import in `fromFile` can mean (see reachesProgram), the files nearest it first. */ |
| 780 | function declarationsFor(specifier: string, fromFile: string, context: ResolutionContext): AmbientModule[] { |
| 781 | const all = scanned(context).bySpecifier.get(specifier); |
| 782 | if (!all) return []; |
| 783 | const memo = memoFor(context); |
| 784 | const key = `${specifier}\0${fromFile}`; |
| 785 | const cached = memo.declarations.get(key); |
| 786 | if (cached) return cached; |
| 787 | const fromTest = isTestCode(fromFile); |
| 788 | const dir = fromFile.slice(0, fromFile.lastIndexOf('/') + 1); |
| 789 | const usable = all.filter((m) => m.script && reachesProgram(m.file, m.test, fromFile, fromTest, context)); |
| 790 | const from = dir.split('/'); |
| 791 | const shared = (file: string): number => { |
| 792 | const parts = file.split('/'); |
| 793 | let k = 0; |
| 794 | while (k < from.length - 1 && k < parts.length - 1 && from[k] === parts[k]) k++; |
| 795 | return k; |
| 796 | }; |
| 797 | const ordered = usable.length < 2 ? usable : usable |
| 798 | .map((m, index) => ({ m, index, near: shared(m.file) })) |
| 799 | .sort((a, b) => Number(a.m.test) - Number(b.m.test) || b.near - a.near || a.index - b.index) |
| 800 | .map((x) => x.m); |
| 801 | memo.declarations.set(key, ordered); |
| 802 | return ordered; |
| 803 | } |
| 804 | |
| 805 | /** The kinds a reference of `refKind` is most likely to mean, first. */ |
| 806 | function kindRank(refKind: UnresolvedRef['referenceKind'], kind: Node['kind']): number { |
no test coverage detected