Skip to content

ast-bro v2.4.3

Choose a tag to compare

@aeroxy aeroxy released this 06 Jun 06:14
· 37 commits to main since this release

1. High-Level Summary (TL;DR)

  • Impact: [High] - Significantly improves the accuracy of the TypeScript call graph by correctly tracking function calls made inside anonymous closures, arrow functions, and inline callbacks.
  • Key Changes:
    • Updates _lexical_to_decl() to initialize and explicitly extract calls for arrow functions and function expressions.
    • Modifies _walk_calls_in_body() to seamlessly descend into anonymous closures instead of immediately halting traversal.
    • Preserves the traversal boundary for named nested functions to prevent duplicate call attribution.
    • Adds extensive end-to-end tests validating curried arrows, inline callbacks, and const-bound closures.

2. Detailed Change Analysis

TypeScript Adapter (src/adapters/typescript.rs)

  • What Changed: Previously, the AST walker stopped traversing whenever it encountered any function-like node. This caused calls inside inline callbacks (e.g., .map(x => f(x))), curried functions (e.g., a => b => f()), and const-bound arrows to vanish from the call graph. The logic was updated to continue descending through anonymous closures, allowing their inner function calls to bubble up and be correctly attributed to the enclosing declaration.
AST Node Kind Old Traversal Behavior New Traversal Behavior Reason
arrow_function Stopped Descends Attributes inline callback calls to the enclosing scope.
function_expression Stopped Descends Extracts calls from anonymous function expressions.
function Stopped Descends Supports legacy Tree-sitter grammar for function expressions.
function_declaration Stopped Stopped Named nested functions correctly remain their own separate graph nodes.

End-to-End Tests (tests/calls_e2e.rs)

  • What Changed: Introduced comprehensive test cases to validate the new TypeScript call graph extraction logic.
    • typescript_callees_from_arrow_const: Validates extraction from block-body, async, and concise expression-body arrows bound to variables.
    • typescript_callees_descends_into_anonymous_closures: Ensures curried functions and inline array callbacks are processed properly.
    • typescript_callees_bubbles_block_local_const_closure: Confirms that inner const-bound closures bubble their calls up to the outer parent function.
    • typescript_callees_still_stops_at_named_nested_scope: Validates that the fix does not break the intended isolation of named nested functions.

3. Impact & Risk Assessment

  • Breaking Changes: ⚠️ None functionally, but downstream tooling utilizing the call graph will see a denser, more accurate graph with newly discovered edges.