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

Function getFileExportIndex

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

Source from the content-addressed store, hash-verified

304}
305
306function getFileExportIndex(filePath: string, context: ResolutionContext): FileExportIndex {
307 let perFile = fileExportIndexes.get(context);
308 if (!perFile) {
309 perFile = new Map();
310 fileExportIndexes.set(context, perFile);
311 }
312 let idx = perFile.get(filePath);
313 if (!idx) {
314 idx = { byName: new Map(), defaultComponent: undefined, defaultFnClass: undefined, members: new Map() };
315 // Python has no export keyword: every module-level def is importable, and
316 // the extractor never flags one isExported. Without this a Python named
317 // import could only ever resolve through the bare-name matcher.
318 const exported = PYTHON_MODULE_FILE.test(filePath)
319 ? context.getNodesInFile(filePath).filter((n) => n.isExported || isPythonModuleLevelDef(n))
320 : context.getExportedNodesInFile?.(filePath) ?? context.getNodesInFile(filePath).filter((n) => n.isExported);
321 const jsFamily = JS_FAMILY_FILE.test(filePath);
322 for (const n of exported) {
323 if (jsFamily && n.qualifiedName !== n.name) {
324 if (!idx.members.has(n.name)) idx.members.set(n.name, n);
325 continue;
326 }
327 if (!idx.byName.has(n.name)) idx.byName.set(n.name, n);
328 if (idx.defaultComponent === undefined && n.kind === 'component') idx.defaultComponent = n;
329 if (idx.defaultFnClass === undefined && (n.kind === 'function' || n.kind === 'class')) idx.defaultFnClass = n;
330 }
331 perFile.set(filePath, idx);
332 }
333 return idx;
334}
335
336/**
337 * `nodes` with the members of something else in their JS/TS file (an

Callers 4

commonJsDefaultExportFunction · 0.85
isStatedDefaultExportFunction · 0.85
namespaceExportModuleFunction · 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