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

Function getFileExportIndex

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

Source from the content-addressed store, hash-verified

285}
286
287function getFileExportIndex(filePath: string, context: ResolutionContext): FileExportIndex {
288 let perFile = fileExportIndexes.get(context);
289 if (!perFile) {
290 perFile = new Map();
291 fileExportIndexes.set(context, perFile);
292 }
293 let idx = perFile.get(filePath);
294 if (!idx) {
295 idx = { byName: new Map(), defaultComponent: undefined, defaultFnClass: undefined, members: new Map() };
296 // Python has no export keyword: every module-level def is importable, and
297 // the extractor never flags one isExported. Without this a Python named
298 // import could only ever resolve through the bare-name matcher.
299 const exported = PYTHON_MODULE_FILE.test(filePath)
300 ? context.getNodesInFile(filePath).filter((n) => n.isExported || isPythonModuleLevelDef(n))
301 : context.getExportedNodesInFile?.(filePath) ?? context.getNodesInFile(filePath).filter((n) => n.isExported);
302 const jsFamily = JS_FAMILY_FILE.test(filePath);
303 for (const n of exported) {
304 if (jsFamily && n.qualifiedName !== n.name) {
305 if (!idx.members.has(n.name)) idx.members.set(n.name, n);
306 continue;
307 }
308 if (!idx.byName.has(n.name)) idx.byName.set(n.name, n);
309 if (idx.defaultComponent === undefined && n.kind === 'component') idx.defaultComponent = n;
310 if (idx.defaultFnClass === undefined && (n.kind === 'function' || n.kind === 'class')) idx.defaultFnClass = n;
311 }
312 perFile.set(filePath, idx);
313 }
314 return idx;
315}
316
317/**
318 * `nodes` with the members of something else in their JS/TS file (an

Callers 3

commonJsDefaultExportFunction · 0.85
isStatedDefaultExportFunction · 0.85
findExportedSymbolWalkFunction · 0.85

Calls 6

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

Tested by

no test coverage detected