Skip to content

fix(js-ts): reference functions consumed via casts, currying, member assignment, call args, param defaults, and shorthand methods#667

Merged
vitali87 merged 2 commits into
mainfrom
fix/ts-cast-wrapped-arrow-binding
Jul 8, 2026
Merged

fix(js-ts): reference functions consumed via casts, currying, member assignment, call args, param defaults, and shorthand methods#667
vitali87 merged 2 commits into
mainfrom
fix/ts-cast-wrapped-arrow-binding

Conversation

@vitali87

@vitali87 vitali87 commented Jul 8, 2026

Copy link
Copy Markdown
Owner

Summary

Dogfooding cgr dead-code against pmndrs/zustand surfaced six systematic JS/TS false-positive classes. All are "a function is consumed by syntax the call/reference pass did not scan," fixed with revive-only reference emission. zustand goes 32 -> 0 dead-code false positives.

Fix classes (each RED -> GREEN)

  1. Cast-wrapped arrow bindings (test_ts_cast_wrapped_arrow_binding.py): export const createStore = ((s) => ... createStoreImpl) as CreateStore lost ALL body call/ref edges. _js_ts_arrow_binding_name required the arrow to be the declarator's direct value; it now climbs paren/cast wrappers, matching the def pass.
  2. Curried inner arrows (test_ts_curried_arrow_references.py): (config) => (set, get, api) => {...} has no return_statement; the expression body IS the implicit return. The returned-function pass now references function-typed bodies, including through unowned anon layers.
  3. Member-assigned inline functions (test_ts_member_assigned_function_references.py): api.setState = (state, replace) => {...}. Two composing gaps: the assignment walk stopped at every function boundary (assignments inside anonymous curried arrows scanned by nobody), and only the position-named registration was referenced, never the property-named one (persistImpl.setState).
  4. Inline args to unresolved callees (test_ts_inline_arg_to_unresolved_callee.py): an arrow passed to a param callee (set((state) => ...)) or cast-wrapped callee (;(set as NamedSet)(...)) was consumed invisibly. Every inline function argument is now referenced from the calling scope, and calls nested purely in anonymous scopes bubble to module scope instead of nobody.
  5. Default parameter values + shorthand methods (test_ts_default_param_and_shorthand_method_refs.py): useStore(api, selector = identity as any) and persist's thenable { then(x) {...}, catch(x) {...} } (method_definition nodes, which the dispatch-table scan skipped as non-pairs).
  6. Nested pair-key paths (test_ts_nested_pair_key_value_refs.py): configure({ onCreated: (s) => { s.setEvents({ compute: ... }) } }) registers as Canvas.onCreated.compute, but the scan built Canvas.compute; candidates now include ancestor pair keys.

Also guards _emit_callback_edge to callable targets only (a default value can resolve a cast's TYPE name to an Interface node, which is schema-invalid as a reference target).

Verification

  • Full suite: 4628 passed, 0 failed
  • zustand: 32 -> 0
  • gson unchanged (52), no cross-language drift (all new passes JS/TS-gated; shared walks no-op for other languages)

…assignment, call args, param defaults, and shorthand methods
@vitali87

vitali87 commented Jul 8, 2026

Copy link
Copy Markdown
Owner Author

@greptile review

@greptile-apps

greptile-apps Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR expands JS/TS call-graph reference detection for callable values consumed through syntax that was previously missed. The main changes are:

  • Cast- and paren-wrapped arrow/function bindings now keep body call edges attributed to the bound function.
  • Curried anonymous arrows, inline call arguments, member assignments, and default parameter values now emit callable reference edges.
  • Object-literal shorthand methods and nested pair-key paths now resolve to registered function candidates.
  • New tests cover each false-positive class reported from the cgr dead-code dogfooding run.

Confidence Score: 5/5

Safe to merge with minimal risk.

The changes are localized to JS/TS reference emission and include targeted tests for each fixed syntax class. No functional or security issues were identified in the changed paths.

No files require special attention.

T-Rex T-Rex Logs

What T-Rex did

  • The direct focused pytest proof documents the exact six-file command and the setup traceback for patch('codebase_rag.cli._maybe_start_stack').
  • The import smoke proof shows that importing codebase_rag.cli failed with ModuleNotFoundError: No module named 'mgclient'.
  • A workaround harness injects a minimal codebase_rag.cli module with _maybe_start_stack before rerunning pytest on the same six files.
  • The successful execution proof shows CLI_STUB_ACTIVE: True True, 13 collected tests, all 13 passing, and EXIT_CODE: 0.

View all artifacts

T-Rex Ran code and verified through T-Rex

Important Files Changed

Filename Overview
codebase_rag/parsers/call_processor.py Extends JS/TS callable reference ingestion for cast-wrapped bindings, anonymous curried scopes, assignment/default/call-argument references, shorthand methods, and nested object key paths.
codebase_rag/tests/test_ts_cast_wrapped_arrow_binding.py Adds tests for calls inside cast-wrapped arrow/function-expression bindings being attributed to the bound function.
codebase_rag/tests/test_ts_curried_arrow_references.py Adds tests for expression-bodied curried arrows keeping returned anonymous functions reachable.
codebase_rag/tests/test_ts_default_param_and_shorthand_method_refs.py Adds tests for default parameter callable references and object-literal shorthand method references.
codebase_rag/tests/test_ts_inline_arg_to_unresolved_callee.py Adds tests for inline function arguments passed to parameter or cast-wrapped unresolved callees.
codebase_rag/tests/test_ts_member_assigned_function_references.py Adds tests for member/local assignment of inline functions within unowned anonymous scopes.
codebase_rag/tests/test_ts_nested_pair_key_value_refs.py Adds tests for nested object pair key paths when referencing inline function values.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
participant Scope as JS/TS caller scope
participant CallProcessor as CallProcessor scans
participant Registry as Function registry
participant Ingestor as Relationship ingestor

Scope->>CallProcessor: Traverse calls, assignments, returns, params, object literals
CallProcessor->>CallProcessor: Unwrap casts/parens and bubble unowned anonymous scopes
CallProcessor->>Registry: Probe named, anonymous-position, property, and pair-path candidates
Registry-->>CallProcessor: Existing callable target variants
CallProcessor->>Ingestor: Emit REFERENCES/CALLS edges to callable targets
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
participant Scope as JS/TS caller scope
participant CallProcessor as CallProcessor scans
participant Registry as Function registry
participant Ingestor as Relationship ingestor

Scope->>CallProcessor: Traverse calls, assignments, returns, params, object literals
CallProcessor->>CallProcessor: Unwrap casts/parens and bubble unowned anonymous scopes
CallProcessor->>Registry: Probe named, anonymous-position, property, and pair-path candidates
Registry-->>CallProcessor: Existing callable target variants
CallProcessor->>Ingestor: Emit REFERENCES/CALLS edges to callable targets
Loading

Reviews (3): Last reviewed commit: "fix(js): scan assignment_pattern default..." | Re-trigger Greptile

@codecov-commenter

codecov-commenter commented Jul 8, 2026

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 99.08257% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
codebase_rag/parsers/call_processor.py 98.90% 1 Missing ⚠️
...sts/test_ts_member_assigned_function_references.py 96.42% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request enhances the JS/TS call and reference ingestion logic in call_processor.py to handle various edge cases such as TS cast-wrapped arrow bindings, curried arrows, default parameters, inline call arguments, member-assigned functions, nested pair keys, and shorthand methods. A critical issue was identified in the default parameter ingestion logic where cs.FIELD_VALUE is used instead of cs.TS_FIELD_RIGHT to retrieve the default value of a parameter in JS/TS, which would cause the ingestion to be a no-op.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread codebase_rag/parsers/call_processor.py Outdated
@greptile-apps

greptile-apps Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR expands JS/TS call graph reference handling for functions consumed through less direct syntax. The main changes are:

  • Cast- and paren-wrapped arrow/function bindings now keep their body call edges.
  • Curried expression-bodied arrows now reference returned inner functions.
  • Member-assigned and locally reassigned inline functions are referenced from anonymous curried scopes.
  • Inline function arguments are referenced even when the callee is unresolved or cast-wrapped.
  • Default parameter values, shorthand object methods, and nested object-pair key paths now emit callable references.
  • Focused tests cover each reported false-positive class.

Confidence Score: 5/5

Safe to merge with minimal risk.

The changes are scoped to JS/TS reference recovery paths and use registry checks before emitting callable edges. Focused tests cover each syntax class described in the PR. No review findings were identified.

No files require special attention.

T-Rex T-Rex Logs

What T-Rex did

  • Validated the test-regression run used a temporary shim to bypass the missing native pymgclient.
  • Recorded the exact commands, working directory, environment notes, setup blocker traces, shim creation entry, and final pytest output in the ts-reference-regressions.log.
  • Executed the final command timeout 180s uv run --no-sync pytest -vv on six targeted files, which exited with code 0 and reported 12 tests passed in 5.15s.
  • Removed the repo-local mgclient.py after validation and left the copied mgclient_test_shim.py as the active shim.

View all artifacts

T-Rex Ran code and verified through T-Rex

Important Files Changed

Filename Overview
codebase_rag/parsers/call_processor.py Extends JS/TS reference ingestion for cast-wrapped bindings, anonymous curried scopes, inline call arguments, default parameters, shorthand methods, and nested pair-key registrations.
codebase_rag/tests/test_ts_cast_wrapped_arrow_binding.py Adds tests for cast- and paren-wrapped arrow/function-expression bindings retaining body call edges.
codebase_rag/tests/test_ts_curried_arrow_references.py Adds tests for expression-bodied curried arrows referencing returned inner anonymous functions.
codebase_rag/tests/test_ts_default_param_and_shorthand_method_refs.py Adds tests for default parameter callable references and object-literal shorthand method references.
codebase_rag/tests/test_ts_inline_arg_to_unresolved_callee.py Adds tests for inline function arguments passed to unresolved or cast-wrapped callees.
codebase_rag/tests/test_ts_member_assigned_function_references.py Adds tests for member- and local-assigned inline functions in anonymous curried scopes.
codebase_rag/tests/test_ts_nested_pair_key_value_refs.py Adds tests for nested object-pair key paths when referencing inline function values.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
participant CP as CallProcessor
participant AST as JS/TS AST
participant Reg as FunctionRegistry
participant Ing as Ingestor

CP->>AST: Walk caller/module scope
AST-->>CP: Calls, assignments, params, returns, object literals
CP->>CP: Unwrap TS casts/parens and bubble unowned anonymous scopes
CP->>Reg: Check function/method candidates and variants
Reg-->>CP: Registered callable targets
CP->>Ing: Emit REFERENCES/CALLS edges
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
participant CP as CallProcessor
participant AST as JS/TS AST
participant Reg as FunctionRegistry
participant Ing as Ingestor

CP->>AST: Walk caller/module scope
AST-->>CP: Calls, assignments, params, returns, object literals
CP->>CP: Unwrap TS casts/parens and bubble unowned anonymous scopes
CP->>Reg: Check function/method candidates and variants
Reg-->>CP: Registered callable targets
CP->>Ing: Emit REFERENCES/CALLS edges
Loading

Reviews (2): Last reviewed commit: "fix(js-ts): reference functions consumed..." | Re-trigger Greptile

@vitali87

vitali87 commented Jul 8, 2026

Copy link
Copy Markdown
Owner Author

@greptile review

@vitali87
vitali87 merged commit 5487805 into main Jul 8, 2026
13 of 20 checks passed
@vitali87
vitali87 deleted the fix/ts-cast-wrapped-arrow-binding branch July 8, 2026 22:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants