Skip to content

fix(parser): retain enclosing context for calls in anonymous callbacks (JS/TS) (#1570) - #1629

Open
Shriraj888 wants to merge 1 commit into
CodeGraphContext:mainfrom
Shriraj888:fix/js-ts-anonymous-callback-call-graph
Open

fix(parser): retain enclosing context for calls in anonymous callbacks (JS/TS) (#1570)#1629
Shriraj888 wants to merge 1 commit into
CodeGraphContext:mainfrom
Shriraj888:fix/js-ts-anonymous-callback-call-graph

Conversation

@Shriraj888

Copy link
Copy Markdown

Description

Fixes #1570

When a function call is located inside an anonymous callback (such as arrow functions or function expressions passed to setTimeout, .then, app.use, event listeners, array methods, etc.), _get_parent_context in the TypeScript and JavaScript parsers previously stopped its AST traversal at the anonymous function node. Because anonymous functions lack an identifier name, name_node resolved to None, causing _get_parent_context to immediately return (None, curr.type, line).

Consequently, the call was attributed to a nameless caller, dropping the (Function)-[:CALLS]->(...) edge from the call graph and causing find_callers to miss the enclosing function.

Changes Made

  • TypeScript & JavaScript AST Context Traversal (typescript.py, javascript.py):
    • Updated _get_parent_context to continue ascending parent AST nodes until a named enclosing scope (function_declaration, class_declaration, method_definition, or named/assigned arrow_function/function_expression) is found.
    • Added support for resolving names from variable declarators, member assignment expressions (obj.fn = ...), object pairs ({ fn: ... }), and class field definitions (field_definition, public_field_definition, property_definition).
    • TSX (typescriptjsx.py) automatically inherits the fix.
  • Consistency Across Parsers (cpp.py, csharp.py, go.py, lua.py):
    • Ensured _get_parent_context only returns when a name is resolved and continues walking up otherwise.
  • Tests Added:
    • tests/unit/parsers/test_typescript_parser.py: Unit tests for single- and multi-level nested callbacks and top-level anonymous IIFEs.
    • tests/unit/parsers/test_javascript_parser.py: Unit tests for callback functions and class method callbacks in JS.
    • tests/unit/tools/test_cross_lang_call_resolution_patterns.py: End-to-end call graph resolution tests verifying that build_function_call_groups outputs CALLS edges from the enclosing named caller function in TS, TSX, and JS.

Verification

  • Ran parser unit tests and call resolution test suites:
    pytest tests/unit/parsers/test_typescript_parser.py tests/unit/parsers/test_javascript_parser.py tests/unit/tools/test_cross_lang_call_resolution_patterns.py

Copilot AI lite review requested due to automatic review settings August 14, 2026 17:25
@github-project-automation github-project-automation Bot moved this to Backlog tasks in CGC Progress Board Aug 14, 2026
@vercel

vercel Bot commented Aug 14, 2026

Copy link
Copy Markdown

@Shriraj888 is attempting to deploy a commit to the shashankss1205's projects Team on Vercel.

A member of the Team first needs to authorize it.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@Shriraj888

Copy link
Copy Markdown
Author

@Shashankss1205 could you please review my PR when you get a chance?

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

Labels

None yet

Projects

Status: Backlog tasks

Development

Successfully merging this pull request may close these issues.

Calls inside anonymous callbacks are dropped from the call graph (JS/TS) — find_callers misses them

2 participants