Subtle bug in modules and imports#632
Subtle bug in modules and imports#632Sahilbhatane wants to merge 2 commits intoCodeGraphContext:mainfrom
Conversation
|
@Sahilbhatane is attempting to deploy a commit to the shashankss1205's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
@Shashankss1205 created new PR for #495. |
There was a problem hiding this comment.
Pull request overview
This PR implements support for finding JavaScript module dependencies by export names, import aliases, and default exports, not just module paths. This addresses issue #495 where cgc analyze deps could only search by exact module paths like ./exporter.js but failed when searching by export names like exportedFunction or import aliases like defaultExport.
Changes:
- Added export parsing capability to JavaScript parser to extract all export statements (named, default, and re-exported)
- Extended graph database schema with Export nodes and EXPORTS relationships to track JavaScript exports
- Enhanced module dependency search with 4 strategies: direct module name, export name, import alias, and imported name matching
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
tests/unit/parsers/test_javascript_parser.py |
New unit tests verifying parser extracts exports with correct structure (name, original_name, is_default, line_number) |
src/codegraphcontext/tools/languages/javascript.py |
Added _find_exports() method to parse export statements and updated parse() to include exports in returned data |
src/codegraphcontext/tools/graph_builder.py |
Added Export node constraint, created logic to store exports in graph with EXPORTS relationships, unified module naming between imports and exports |
src/codegraphcontext/tools/code_finder.py |
Refactored find_module_dependencies() with 4 search strategies and result deduplication to support searching by names/aliases |
src/codegraphcontext/cli/main.py |
Enhanced user messaging when no dependencies found, suggesting re-indexing or alternate search terms |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@Shashankss1205 this PR is ready to merge and solves the bug. |
Summary
Fixes #495 -
cgc analyze depsnow supports finding JavaScript module dependencies by export names, not just module paths.Problem
Previously,
cgc analyze depscould only find dependencies by exact module path (e.g.,./exporter.js). It failed when searching by:exportedFunction,ExportedClass)defaultExport)This happened because:
Solution
Phase 1: Track Exports
File:
src/codegraphcontext/tools/languages/javascript.py_find_exports()method to parse export statementsexport default,export function/class,export const/let/var,export { name1, name2 }parse()to include exports in returned dictionaryFile:
src/codegraphcontext/tools/graph_builder.pycreate_schema()add_file_to_graph()to create Export nodes for JavaScript filesPhase 2: Enhanced Search
File:
src/codegraphcontext/tools/code_finder.pyfind_module_dependencies()with 4 search strategies:Testing
Tested with
tests/sample_project_javascriptScreenshots