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

Function getFileExportIndex

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

Source from the content-addressed store, hash-verified

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