Skip to content

fix(js): resolve ns.fn() calls through namespace imports (#4619) - #4636

Open
Deepjyoti-Sarmah wants to merge 2 commits into
Graphify-Labs:v8from
Deepjyoti-Sarmah:fix/4619-ts-namespace-calls
Open

Deepjyoti-Sarmah wants to merge 2 commits into
Graphify-Labs:v8from
Deepjyoti-Sarmah:fix/4619-ts-namespace-calls

Conversation

@Deepjyoti-Sarmah

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes #4619. A call through a namespace import made no calls edge:

import * as ops from './ops'
export function dispatch(n: number) { return ops.submit(n) }   // no dispatch -> submit

It failed in both call paths:

  • The symbol-resolution pass (resolution.py) never recorded import * as ops, and kept only bare-identifier callees, so ops.submit was dropped. fix(js): resolve calls inside exported functions, incl. aliased imports (#3346) #3517 fixed aliased named imports here and left namespace imports for later.
  • The per-file engine saw the member call, then looked submit up by bare name in the caller's own file. When that file has its own submit, the call bound to it, so the edge pointed at the wrong function. Otherwise the call was parked, and the cross-file loop skips every member call.

The engine now knows which import binds each receiver. The resolution pass resolves fn against the module's real exports:

 engine: member call ns.fn()
+  if ns is bound by `import * as ns from './m'` (corpus file, not shadowed in the caller)
+    skip the same-file bare-name lookup
+    stamp the raw call with (m, "*")
 resolution pass
+  record `import * as ns` as an import fact with imported name "*"
+  turn each stamped call into a use fact `ns.fn`
+  fn = the one export of m named fn (re-export chains, `export { a as b }`, `export * as ns`)
+  no export of that name -> no edge

The lookup uses the export table that named imports already use (exported_candidates), so it handles renames the same way. Unlike resolve_exported_origin, it doesn't fall back to "a symbol with that name exists in the file", so ns.privateFn() makes no edge.

Before (the issue's repro, v8):

calls dispatch() -> helper()

After:

calls dispatch() -> helper()
calls dispatch() -> submit()
calls dispatch() -> reveal()
calls direct()   -> submit()

I chose this after writing the tests first and running four candidates against them:

A: resolution pass only B: engine + new resolver C: A + class methods + engine guard D: engine binding + export table (this PR)
issue repro (T1) 4/4 4/4 4/4 4/4
class methods, nested functions, .tsx, .mjs (T2) 3/5 5/5 4/5 5/5
through barrels (T3) 3/3 3/3 3/3 3/3
export { a as b }: x.b() edge, x.a() none pass fail pass pass
no edge to an unexported function fail fail fail pass
no edge to a same-named function in the caller's file fail pass pass pass
shadowing, external package, import type (T4) pass pass pass pass

B rebuilt the export table from graph labels. That lost the renamed name and treated every contains child as an export.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Tests or CI
  • Refactor
  • Security fix

Verification & Invariants

A call ns.fn() through import * as ns from './m' has a calls edge to the function m exports as fn, and to nothing else.

  • Read the CONTRIBUTING.md guide.
  • Reproduced the issue and identified the invariant.
  • Made the smallest fix necessary.
  • Added a regression test (if bug fix) or isolated boundary test.
  • Kept the PR description synchronized with the final implementation.
  • Documented any limitations / unsupported cases explicitly.

Merge Danger

Door: two-way. No id changes and no schema bump: JS/TS files skip the per-file AST cache (_JS_CACHE_BYPASS_SUFFIXES), so the next extract gives the new edges, and a revert gives v8 output again.

Blast Radius: small. Only JS/TS graphs change, and only around namespace imports. On a 2876-file TypeScript project, 12 edges were added and 7 removed out of 15567, and I checked each against the source:

  • Removed: 7 calls like ops.add() inside a class method add(), which v8 bound to the class's own .add().
  • Added: those 7 calls, plus ops.list() and ops.wakeNow(), now point at service/ops.ts. 3 more are calls inside it(...) callbacks, through an export * barrel.

Extraction took 37.7 s, against 38.6 s on v8 (median of 3).

Limitations

  • A top-level ns.fn() statement, outside any function, still makes no edge, the same as a bare call. test_ts_import_require.py pins the edges of that case.
  • ops.a.b() and const f = ops.submit; f() still make no edge. new ops.K() and const { submit } = ops; submit() now do. All four are xfail(strict=False), because their wanted behaviour isn't decided.
  • Only relative imports resolve, the same as other JS imports here (_resolve_js_module_path). tsconfig path aliases and Vue/Svelte callers are untested.
  • The "*" import fact goes into the shared alias table. "*" is never an export name, so a bare ops() resolves to nothing.

How was this tested?

New tests in tests/test_js_exported_fn_call_resolution.py, next to the #3346 tests. Each one runs extract() on a small project and asserts (caller, callee, callee file) edges. None of them calls a private helper.

Test v8 This PR
T1: issue repro, each of the 3 namespace edges fail pass
T1: dispatch -> helper pass pass
T2: arrow (.js), class method, nested function, .tsx, .mjs fail pass
T3: export *, export { x } from, export * as ns barrels fail pass
T3b: renamed re-export fail pass
T4: no edge to a same-named function in the caller's file fail: binds to it pass
T4: name not exported, local and parameter shadow, react, import type pass pass
T4b: no edge to an unexported function pass pass
T5: chain, const alias, new, destructure 3 xfail, 1 xpass 2 xfail, 2 xpass
T6: named, aliased (#3346) and default imports, imports_from edges pass pass

On v8 the tests that pass do so because v8 makes no namespace edges at all. They guard against binding by name.

pytest tests/test_js_exported_fn_call_resolution.py (tests on v8 b90b9df7) -> 13 failed, 16 passed, 3 xfailed, 1 xpassed
pytest tests/test_js_exported_fn_call_resolution.py (this branch)           -> 29 passed, 2 xfailed, 2 xpassed
pytest -q -p no:randomly (full suite, --basetemp=/var/tmp)                  -> 8495 passed, 14 skipped, 2 xfailed, 2 xpassed
ruff check (changed files)                                                  -> All checks passed

Graphify-specific checklist

  • I updated generated skill artifacts (uv run python -m tools.skillgen --bless) when changing their source fragments. (N/A: no skill fragments touched.)
  • I confirmed that AST/structural extraction remains deterministic (no ambient state dependencies like ENV variables).
  • I reviewed changes for security implications (no unsafe interpolation into shell/Python).
  • I confirmed no API keys or local-only graph data are included.
  • (If applicable) I disclosed AI authorship in my commit messages.

@github-actions

Copy link
Copy Markdown

Thanks for the pull request, @Deepjyoti-Sarmah. A maintainer will review it soon.

Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions.

A couple of things that speed up review: make sure the test suite passes on Python 3.10 and 3.13, and that the change keeps extraction deterministic.

@github-actions github-actions Bot added the contributor Pull request from a returning community contributor label Oct 21, 2026

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

Worth a look — the grounded gate found no coupling regressions or blocking issues, but 1 advisory finding(s) below merit a look before merge.

Not checked: tests were not run; formal verification proved 0 of 5 changed function(s) (2 sampled, not proven, 3 not verified).

Formal verification. PR-changed functions: 2/5 verified (0 proven, 2 may-equivalent, 0 distinguished) · 3 not verified (3 unsupported).

Not verified on this run: \_extract\_generic (unsupported), \_apply\_symbol\_resolution\_facts (unsupported), \_collect\_js\_symbol\_resolution\_facts (unsupported).


Graphify review — findings

Fixes ns.fn() on TS/JS namespace imports so the call resolves to the imported module's export instead of a same-named function in the calling file. The extractor records each relative import's binding, defers the call when the receiver is an import * as ns binding rather than a local, and stamps the raw call with its module. A new cross-file pass then turns those calls into ns.fn use facts that link only when exactly one export matches, including through export * as ns barrels. The local-call deferral keys on * bindings alone, so barrel-reexported namespaces aren't protected from same-file shadowing, and an import specifier with a non-identifier name maps the alias to itself.

Worth a look

  • Local-call defer only covers * bindings, not named re-exported namespaces — graphify/extractors/engine.py:9464 · Escalate · medium
    • NOT verified (no proof, no reproducing execution) — needs human review
Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 3868 functions depend on the 897 functions this change touches.

Health — this change adds coupling hotspots:

  • worse: extract() — 988 callers, 59 callees
  • worse: _extract_generic() — 20 callers, 47 callees
  • worse: _collect_js_symbol_resolution_facts() — 3 callers, 28 callees
  • worse: _resolve_js_import_target() — 12 callers, 3 callees

Verification — 3868 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: 3623 function(s) in the blast radius were not formally verified this run

Test selection

Test selection

207 of 436 test file(s) selected (47%) via static blast radius.

  • tests/test_affected_overrides.py — impact
  • tests/test_astro_extraction.py — impact
  • tests/test_astro_import_ids.py — impact
  • tests/test_blade_extractor.py — impact
  • tests/test_build.py — impact
  • tests/test_builtin_global_type_refs.py — impact
  • tests/test_c_include_resolution.py — impact
  • tests/test_cache.py — impact
  • tests/test_case_sensitive_resolution.py — impact
  • tests/test_cjs_module_extension.py — impact
  • tests/test_cobol_extractor.py — impact
  • tests/test_cpp_method_declarations.py — impact
  • tests/test_cpp_nested_and_cli.py — impact
  • tests/test_cpp_objc_cross_file_calls.py — impact
  • tests/test_cpp_template_type_params.py — impact
  • tests/test_cross_extension_reexport_self_cycle.py — impact
  • tests/test_cross_language_call_resolution.py — impact
  • tests/test_cross_repo_external_call_guards.py — impact
  • tests/test_cross_repo_member_calls.py — impact
  • tests/test_csharp_call_site_generic_args.py — impact
  • tests/test_csharp_delegate_declarations.py — impact
  • tests/test_csharp_enum_members.py — impact
  • tests/test_csharp_field_generic_args.py — impact
  • tests/test_csharp_foreach_loop_variable.py — impact
  • tests/test_csharp_generic_callsites.py — impact
  • tests/test_csharp_interface_dispatch.py — impact
  • tests/test_csharp_member_calls.py — impact
  • tests/test_csharp_member_chain_calls.py — impact
  • tests/test_csharp_member_nodes.py — impact
  • tests/test_csharp_object_creation.py — impact
  • tests/test_csharp_partial_classes.py — impact
  • tests/test_csharp_tuple_type_refs.py — impact
  • tests/test_csharp_type_resolution.py — impact
  • tests/test_csharp_underscore_collisions.py — impact
  • tests/test_csharp_var_call_return_type.py — impact
  • tests/test_csharp_verbatim_interpolation.py — impact
  • tests/test_definition_file_portability.py — impact
  • tests/test_detect.py — impact
  • tests/test_dotnet.py — impact
  • tests/test_duplicate_annotation_edges.py — impact
  • tests/test_ejs_extractor.py — impact
  • tests/test_elixir_defdelegate.py — impact
  • tests/test_elixir_import_resolution.py — impact
  • tests/test_elixir_keyword_def_calls.py — impact
  • tests/test_elixir_qualified_calls.py — impact
  • tests/test_elixir_unqualified_call_scope.py — impact
  • tests/test_erlang_extractor.py — impact
  • tests/test_ext_tagged_id_clash.py — impact
  • tests/test_extract.py — impact
  • tests/test_extract_cache_location.py — impact
  • … and 157 more

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.

Docs that may be stale (advisory)

Formal verification

No difference found (not proven): No behavior difference found in extract (not a proof).

The verifier ran both versions of extract on many inputs and saw identical behavior every time. Strong evidence the change is safe, but evidence, not a proof.

Guarantee: Empirical: differential testing (both versions run on many generated inputs). A divergence on an untested input remains possible, so this is 'no counterexample found', not 'proven equivalent'.

Note: An input the sampler did not try could still differ.

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: no capturable inputs from the test suite; property tier: parameter `config` is annotated `LanguageConfig` — outside the synthesizable primitive/collection set

Could not verify: Could not verify \_apply\_symbol\_resolution\_facts.

The verifier did not have enough to check \_apply\_symbol\_resolution\_facts, 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: no capturable inputs from the test suite; property tier: parameter `facts` is annotated `_SymbolResolutionFacts` — outside the synthesizable primitive/collection set

No difference found (not proven): No behavior difference found in \_augment\_symbol\_resolution\_edges (not a proof).

The verifier ran both versions of \_augment\_symbol\_resolution\_edges on many inputs and saw identical behavior every time. Strong evidence the change is safe, but evidence, not a proof.

Guarantee: Empirical: differential testing (both versions run on many generated inputs). A divergence on an untested input remains possible, so this is 'no counterexample found', not 'proven equivalent'.

Note: An input the sampler did not try could still differ.

Could not verify: Could not verify \_collect\_js\_symbol\_resolution\_facts.

The verifier did not have enough to check \_collect\_js\_symbol\_resolution\_facts, 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: no capturable inputs from the test suite; property tier: parameter `facts` is annotated `_SymbolResolutionFacts` — outside the synthesizable primitive/collection set

· 4 more finding(s) on lines outside this diff (see the check run).

`import * as ns from './m'; ns.fn()` gives no calls edge, and when the
caller's file has its own `fn`, the call binds to that one instead.
Covers caller shapes, barrels, renamed re-exports, shadowing, external
packages and unexported names. Undecided shapes are xfail(strict=False).
The extractor records which import binds each receiver. For
`import * as ns`, it skips the same-file name lookup and stamps the call
with the module. The symbol-resolution pass turns that into a use fact and
resolves `fn` against the module's exports only, through re-export chains,
`export { a as b }` and `export * as ns`. Shadowed receivers, type-only
imports and external packages make no edge.

JS/TS skip the AST cache, so no schema bump.
@Deepjyoti-Sarmah
Deepjyoti-Sarmah force-pushed the fix/4619-ts-namespace-calls branch from b75d70b to c7be31c Compare November 1, 2026 18:21

This branch has not been deployed

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

Labels

contributor Pull request from a returning community contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: TS/JS: calls through a namespace import (import * as ns; ns.fn()) produce no calls edge (deferred half of #3346)

1 participant