Skip to content

fix(js): resolve calls through namespace imports and whole-module require (#5114) - #5129

Closed
mohitdixit02 wants to merge 1 commit into
Graphify-Labs:v8from
mohitdixit02:fix/js-namespace-import-call-edges-5114
Closed

mohitdixit02 wants to merge 1 commit into
Graphify-Labs:v8from
mohitdixit02:fix/js-namespace-import-call-edges-5114

Conversation

@mohitdixit02

Copy link
Copy Markdown
Contributor

What does this PR do?

In JavaScript and TypeScript corpora, calling an exported module function through a namespace import (import * as helpers from './helpers') or a whole-module CommonJS require (const helpers = require('./helpers')) dropped cross-file calls edges when invoking helpers.format(x). While destructured require and named imports resolved directly, member call resolution lacked namespace import mappings and misidentified top-level CommonJS require declarators as local receiver shadowing.

This PR records namespace import bindings mapping alias identifiers to the required module path across ESM namespace imports, CommonJS whole-module requires, and TypeScript import = require statements. During member call resolution, calls against an unshadowed namespace alias resolve through the target module's exported candidates to emit the appropriate calls edge.

// helpers.ts
export function format(x: string): string { return x; }

// user.ts
import * as helpers from './helpers';
export function go(x: string) { return helpers.format(x); } // now emits calls edge go -> format

Fixes #5114

Type of change

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

Verification & Invariants

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

How was this tested?

    uv run pytest tests/test_js_namespace_import_call_edges.py
    uv run pytest tests/test_js_extends_require_4688.py tests/test_js_require_binding_shadow.py
    uv run pytest tests/test_js_import_resolution.py
    uv run ruff check graphify/extractors/engine.py graphify/extractors/resolution.py tests/test_js_namespace_import_call_edges.py

Graphify-specific checklist

  • I updated generated skill artifacts (uv run python -m tools.skillgen --bless) when changing their source fragments.
  • 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, @mohitdixit02. 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.

@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) (5 not verified).

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

Not verified on this run: \_js\_direct\_lexical\_names (vacuous: never exercised), \_apply\_symbol\_resolution\_facts (unsupported), \_collect\_js\_symbol\_resolution\_facts (unsupported), \_js\_cjs\_export\_facts (vacuous: never exercised), \_js\_cjs\_require\_bindings (vacuous: never exercised).


Graphify review — findings

Adds call-edge resolution for JS/TS namespace imports (import * as X), TS import X = require(), and whole-module CommonJS require, so helpers.format(x) now links to the exported format when the target resolves to exactly one candidate, and otherwise falls back to the existing default-export member lookup. Namespace imports are recorded as * facts, require bindings emit both * and default, and module.exports = { method() {} } shorthand methods are now picked up as exports. _js_direct_lexical_names now skips require(...) declarators when collecting local names, which changes how a function-scoped require binding interacts with shadow detection of an outer import receiver.

Worth a look

  • Function-scoped require() bindings no longer shadow outer import receivers — graphify/extractors/engine.py:2951 · Escalate · medium
    • NOT verified (no proof, no reproducing execution) — needs human review
Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 4252 functions depend on the 601 functions this change touches.

Health — this change adds coupling hotspots:

  • worse: extract() — 1178 callers, 71 callees
  • worse: _collect_js_symbol_resolution_facts() — 4 callers, 32 callees

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

Test selection

Test selection

65 of 542 test file(s) selected (12%) via static blast radius.

  • tests/test_4909_reference_binding_scale.py — impact
  • tests/test_4992_ts_import_types.py — impact
  • 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_csharp_extension_calls.py — impact
  • tests/test_csharp_extension_metadata.py — impact
  • tests/test_csharp_extension_resolution.py — impact
  • tests/test_csharp_partial_classes.py — impact
  • tests/test_dotnet.py — impact
  • tests/test_ejs_extractor.py — impact
  • tests/test_ext_tagged_id_clash.py — impact
  • tests/test_extract.py — impact
  • tests/test_extract_php_closures.py — impact
  • tests/test_forwarding_review_findings.py — impact
  • tests/test_go_type_alias.py — impact
  • tests/test_import_extension_resolution.py — impact
  • tests/test_indirect_call_block_scoped_shadow.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_java_member_calls.py — impact
  • tests/test_js_exported_scalar_bindings.py — impact
  • tests/test_js_member_collisions.py — impact
  • tests/test_js_namespace_import_call_edges.py — impact, changed-test
  • tests/test_js_walk_order.py — impact
  • tests/test_language_override_imports.py — impact
  • tests/test_languages.py — impact
  • tests/test_loose_sibling_import_resolution.py — impact
  • tests/test_multilang.py — impact
  • tests/test_package_json_subpath_imports.py — impact
  • tests/test_pascal.py — impact
  • tests/test_pascal_resolution.py — impact
  • tests/test_phantom_external_import.py — impact
  • tests/test_php_unparsed_casts.py — impact
  • tests/test_pr10_resolution_overrides.py — impact
  • tests/test_python_import_resolution.py — impact
  • tests/test_python_inherited_method_calls.py — impact
  • tests/test_python_injected_factory_calls.py — impact
  • tests/test_python_member_call_language_gate.py — impact
  • tests/test_python_parse_memoization.py — impact
  • tests/test_python_property_reads.py — impact
  • tests/test_python_pytest_fixture_receivers.py — impact
  • tests/test_python_underscore_resolution.py — impact
  • tests/test_rationale.py — impact
  • tests/test_resolution_one_parse_per_file.py — impact
  • tests/test_ruby_resolution.py — impact
  • tests/test_scala_context_bounds.py — impact
  • tests/test_scala_extension_methods.py — impact
  • … and 15 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.

Formal verification

Could not verify: Could not verify \_js\_direct\_lexical\_names.

The verifier did not have enough to check \_js\_direct\_lexical\_names, 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: not verifiable: all 230 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)

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

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

Could not verify: Could not verify \_js\_cjs\_export\_facts.

The verifier did not have enough to check \_js\_cjs\_export\_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: not verifiable: all 232 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)

Could not verify: Could not verify \_js\_cjs\_require\_bindings.

The verifier did not have enough to check \_js\_cjs\_require\_bindings, 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: not verifiable: all 225 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)

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

@safishamsi

Copy link
Copy Markdown
Member

Landed on v8 and shipped in 0.9.106 (now on PyPI). I cherry-picked your commit with -x so it keeps your authorship. Thanks for resolving calls through ESM namespace imports and whole-module require (#5114), @mohitdixit02.

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/TS: calls through namespace imports and whole-module CommonJS require lose call edges

2 participants