8000 Subtle bug in modules and imports by Sahilbhatane · Pull Request #632 · CodeGraphContext/CodeGraphContext · GitHub
[go: up one dir, main page]

Skip to content

Subtle bug in modules and imports#632

Open
Sahilbhatane wants to merge 2 commits intoCodeGraphContext:mainfrom
Sahilbhatane:issue-495
Open

Subtle bug in modules and imports#632
Sahilbhatane wants to merge 2 commits intoCodeGraphContext:mainfrom
Sahilbhatane:issue-495

Conversation

@Sahilbhatane
Copy link
Contributor

Summary

Fixes #495 - cgc analyze deps now supports finding JavaScript module dependencies by export names, not just module paths.

Problem

Previously, cgc analyze deps could only find dependencies by exact module path (e.g., ./exporter.js). It failed when searching by:

  • Export names (e.g., exportedFunction, ExportedClass)
  • Import aliases (e.g., defaultExport)
  • Default exports

This happened because:

  1. JavaScript exports were parsed but not stored in the graph database
  2. The search logic only looked for Module nodes by name

Solution

Phase 1: Track Exports

File: src/codegraphcontext/tools/languages/javascript.py

  • Added _find_exports() method to parse export statements
  • Handles: export default, export function/class, export const/let/var, export { name1, name2 }
  • Updated parse() to include exports in returned dictionary

File: src/codegraphcontext/tools/graph_builder.py

  • Added Export node schema constraint in create_schema()
  • Modified add_file_to_graph() to create Export nodes for JavaScript files
  • Links Export nodes to Module nodes via EXPORTS relationship
  • Uses relative paths for module names to match import references

Phase 2: Enhanced Search

File: src/codegraphcontext/tools/code_finder.py

  • Refactored find_module_dependencies() with 4 search strategies:
    1. Direct module name match (existing)
    2. Export name → Module via Export nodes (new)
    3. Import alias matching (new)
    4. Imported name matching (new)
  • Combines and deduplicates results from all strategies
  • Added export information to query results

Testing

Tested with tests/sample_project_javascript

Screenshots

Screenshot 2026-01-18 230240 Screenshot 2026-01-18 230252 image

Copilot AI review requested due to automatic review settings February 11, 2026 17:44
@vercel
Copy link
vercel bot commented Feb 11, 2026

@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.

@Sahilbhatane
Copy link
Contributor Author

@Shashankss1205 created new PR for #495.

Copy link
Contributor
Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Co-authored-by: Cursor <cursoragent@cursor.com>
@Sahilbhatane
Copy link
Contributor Author

@Shashankss1205 this PR is ready to merge and solves the bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Subtle bug in modules and imports

2 participants

0