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

Function getFileExportIndex

src/resolution/import-resolver.ts:122–140  ·  view source on GitHub ↗
(filePath: string, context: ResolutionContext)

Source from the content-addressed store, hash-verified

120const fileExportIndexes = new WeakMap<ResolutionContext, Map<string, FileExportIndex>>();
121
122function getFileExportIndex(filePath: string, context: ResolutionContext): FileExportIndex {
123 let perFile = fileExportIndexes.get(context);
124 if (!perFile) {
125 perFile = new Map();
126 fileExportIndexes.set(context, perFile);
127 }
128 let idx = perFile.get(filePath);
129 if (!idx) {
130 idx = { byName: new Map(), defaultComponent: undefined, defaultFnClass: undefined };
131 const exported = context.getExportedNodesInFile?.(filePath) ?? context.getNodesInFile(filePath).filter((n) => n.isExported);
132 for (const n of exported) {
133 if (!idx.byName.has(n.name)) idx.byName.set(n.name, n);
134 if (idx.defaultComponent === undefined && n.kind === 'component') idx.defaultComponent = n;
135 if (idx.defaultFnClass === undefined && (n.kind === 'function' || n.kind === 'class')) idx.defaultFnClass = n;
136 }
137 perFile.set(filePath, idx);
138 }
139 return idx;
140}
141
142/** The file's nodes named `name`, in `getNodesInFile` order. */
143function nodesInFileNamed(filePath: string, name: string, context: ResolutionContext): Node[] {

Callers 1

findExportedSymbolWalkFunction · 0.85

Calls 5

hasMethod · 0.80
getMethod · 0.65
getNodesInFileMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected