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

Function getFileExportIndex

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

Source from the content-addressed store, hash-verified

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