Skip to content

fix(js): keep this.X = function members in every enclosing-function form (#3408) - #3423

Closed
abhay-codes07 wants to merge 1 commit into
Graphify-Labs:v8from
abhay-codes07:fix/js-this-member-expressions
Closed

abhay-codes07 wants to merge 1 commit into
Graphify-Labs:v8from
abhay-codes07:fix/js-this-member-expressions

Conversation

@abhay-codes07

Copy link
Copy Markdown
Contributor

Closes #3408.

The problem

#1322's fix captured this.X = function members only when the enclosing function was a function declaration. Every expression form — const F = function(){…}, an arrow, an IIFE, a callback argument — silently dropped them. The callback form is the AngularJS registration shape (.service('name', function(){ this.load = … })), which is how the issue's measured corpus ends up 87% file-node-only on its frontend: the graph cannot answer "where is this behaviour implemented" for any of it. All five forms reproduce on 0.9.56.

The member scan lived inline in the function-declaration branch of _extract_generic, and expression-form bodies never pass through that branch.

The change

The scan is factored into _js_scan_member_assignments (a pure move of the existing logic, including the api.X = fn object-binding case and its #1077 flood guard) and now runs from every enclosing form:

  • Declaration branch — unchanged behavior, now via the helper.
  • const F = function(){…} / const F = () => {…} — the lexical-declaration branch that already materializes F() scans its body too; members become method edges owned by F, same as the declaration case.
  • Module-level call statements — callIt(function(){…}), the AngularJS .service(…) chain, (function(){…})() — each TOPMOST closure body (reusing _js_topmost_closures, so nested closures stay with their own scope) is scanned. The enclosing function is anonymous, so members attach to the file node as contains edges with file-qualified ids — the same shape exports.X members already have, and the Extraction noise: scope-blind identifier collision + over-eager markdown fragment nodes #1077 phantom-god-node guard's requirement.

Tests

tests/test_js_this_member_expressions.py — 5 tests: the issue's five-form repro extracts every member; const F = function(){…} members are methods owned by F; the AngularJS service shape yields both members hanging off the file node with file-qualified ids; a const local inside a callback still produces no node (#1077 control); and the declaration form emits exactly one node and one method edge (no double scan). With the fix reverted, 4 of 5 fail (the locals control rightly keeps passing). The JS/TS suites are unchanged (1072 passed; the two failing names fail identically on clean v8 on this Windows machine); the full suite matches a fresh same-version v8 (0.9.56) baseline.

🤖 Generated with Claude Code

https://claude.ai/code/session_01JJbLfztSxm2tH5cJwBbe9q

Copilot AI lite review requested due to automatic review settings September 8, 2026 18:23

Copilot AI left a comment

Copy link
Copy Markdown

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.

@graphify-labs graphify-labs Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Graphify reviewed this change.

Looks safe to merge — no coupling regressions and no blocking issues, checked against the code graph (not a self-assessment).

Formal verification. No changes could be formally verified in this run.


Graphify review — findings

Captures this.X = function members across all enclosing-function forms in JS/TS, not just function declarations, by extracting the member-assignment scan into shared _js_scan_member_assignments. Members on function expressions, const-bound arrows, and IIFEs now attach as .X() method edges to their named owner, while closures passed as call arguments (e.g. the AngularJS .service(...) pattern) or immediately invoked attach as X() contains edges under the file node since the enclosing function is anonymous. Object-literal factory members keep their existing scope-proof binding and single-contains-edge dedup guard.

No blocking issues surfaced. 3 lower-confidence candidates did not survive cross-model review.

Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 663 functions depend on the 222 functions this change touches.

Health — this change adds coupling hotspots:

  • new: _extract_generic() — 18 callers, 26 callees
  • new: extract_js() — 85 callers, 4 callees
  • new: extract_xaml() — 19 callers, 17 callees
  • new: extract_objc() — 27 callers, 9 callees
  • new: extract_julia() — 17 callers, 7 callees
  • new: extract_cpp() — 27 callers, 3 callees
  • new: extract_vue() — 10 callers, 7 callees
  • new: walk() — 1 callers, 58 callees
  • …and 8 more — each is listed as a finding

Verification — 663 functions in the blast radius were not formally verified this run (proofs are advisory here).

Gate & verification

graphify gate

PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.

Advisory (not blocking):

  • verification_scope: 603 function(s) in the blast radius were not formally verified this run

Test selection

Test selection

22 of 260 test file(s) selected (8%) via static blast radius.

  • tests/test_astro_extraction.py — impact
  • tests/test_build.py — impact
  • tests/test_cjs_module_extension.py — impact
  • tests/test_cpp_nested_and_cli.py — impact
  • tests/test_dotnet.py — impact
  • tests/test_extract.py — impact
  • tests/test_import_extension_resolution.py — impact
  • tests/test_indirect_dispatch.py — impact
  • tests/test_indirect_dispatch_assign_return.py — impact
  • tests/test_indirect_dispatch_getattr.py — impact
  • tests/test_js_exported_scalar_bindings.py — impact
  • tests/test_js_this_member_expressions.py — impact, changed-test
  • tests/test_languages.py — impact
  • tests/test_multilang.py — impact
  • tests/test_python_underscore_resolution.py — impact
  • tests/test_rationale.py — impact
  • tests/test_ruby_resolution.py — impact
  • tests/test_scala_self_type.py — impact
  • tests/test_swift_computed_properties.py — impact
  • tests/test_ts_new_expression_calls.py — impact
  • tests/test_typescript_module_extensions.py — impact
  • tests/test_vue_extraction.py — impact

Selection is safe under the controlled-regression assumption; always-run tests + a periodic full run are the backstops. Advisory — it never changes the check verdict.

Formal verification

Could not verify: Could not verify \_extract\_generic.

The verifier did not have enough to check \_extract\_generic, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: parameter `path` is annotated `Path` — outside the synthesizable primitive/collection set

Could not verify: Could not verify \_js\_extra\_walk.

The verifier did not have enough to check \_js\_extra\_walk, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: not verifiable: all 200 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous (mostly AttributeError — names the real obstacle, not a sampling gap)

· 1 grounded finding(s) anchored inline below; 15 more finding(s) on lines outside this diff (see the check run).

function_bodies.append((m_nid, m_body))


def _js_extra_walk(node, source: bytes, file_nid: str, stem: str, str_path: str,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Health regression — _js_extra_walk()

fans out to 9 callees (efferent coupling).

Grounded coupling-delta finding (deterministic), not an LLM guess.

@safishamsi

Copy link
Copy Markdown
Member

Shipped in v0.9.57 — landed on v8 via cherry-pick with your authorship preserved. Thanks @abhay-codes07 — this.X = function members are now captured in every enclosing-function form, not just declarations. Release: https://github.com/Graphify-Labs/graphify/releases/tag/v0.9.57

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.

JS: this.X = function is extracted only inside a function *declaration* — every function-expression form drops it (incomplete fix of #1322)

3 participants