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

Function declarationsFor

src/resolution/ambient-modules.ts:780–803  ·  view source on GitHub ↗

The script declarations of `specifier` an import in `fromFile` can mean (see reachesProgram), the files nearest it first.

(specifier: string, fromFile: string, context: ResolutionContext)

Source from the content-addressed store, hash-verified

778
779/** The script declarations of `specifier` an import in `fromFile` can mean (see reachesProgram), the files nearest it first. */
780function 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. */
806function kindRank(refKind: UnresolvedRef['referenceKind'], kind: Node['kind']): number {

Callers 2

findAmbientModuleExportFunction · 0.85
findAmbientModuleFileFunction · 0.85

Calls 9

reachesProgramFunction · 0.85
NumberInterface · 0.85
mapMethod · 0.80
scannedFunction · 0.70
memoForFunction · 0.70
isTestCodeFunction · 0.70
sharedFunction · 0.70
getMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected