Repository navigation
fix(js): resolve calls through namespace imports and whole-module require (#5114) - #5129
mohitdixit02 wants to merge 1 commit into
Conversation
|
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. |
There was a problem hiding this comment.
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— impacttests/test_4992_ts_import_types.py— impacttests/test_astro_extraction.py— impacttests/test_build.py— impacttests/test_cjs_module_extension.py— impacttests/test_cpp_nested_and_cli.py— impacttests/test_csharp_extension_calls.py— impacttests/test_csharp_extension_metadata.py— impacttests/test_csharp_extension_resolution.py— impacttests/test_csharp_partial_classes.py— impacttests/test_dotnet.py— impacttests/test_ejs_extractor.py— impacttests/test_ext_tagged_id_clash.py— impacttests/test_extract.py— impacttests/test_extract_php_closures.py— impacttests/test_forwarding_review_findings.py— impacttests/test_go_type_alias.py— impacttests/test_import_extension_resolution.py— impacttests/test_indirect_call_block_scoped_shadow.py— impacttests/test_indirect_dispatch.py— impacttests/test_indirect_dispatch_assign_return.py— impacttests/test_indirect_dispatch_getattr.py— impacttests/test_java_member_calls.py— impacttests/test_js_exported_scalar_bindings.py— impacttests/test_js_member_collisions.py— impacttests/test_js_namespace_import_call_edges.py— impact, changed-testtests/test_js_walk_order.py— impacttests/test_language_override_imports.py— impacttests/test_languages.py— impacttests/test_loose_sibling_import_resolution.py— impacttests/test_multilang.py— impacttests/test_package_json_subpath_imports.py— impacttests/test_pascal.py— impacttests/test_pascal_resolution.py— impacttests/test_phantom_external_import.py— impacttests/test_php_unparsed_casts.py— impacttests/test_pr10_resolution_overrides.py— impacttests/test_python_import_resolution.py— impacttests/test_python_inherited_method_calls.py— impacttests/test_python_injected_factory_calls.py— impacttests/test_python_member_call_language_gate.py— impacttests/test_python_parse_memoization.py— impacttests/test_python_property_reads.py— impacttests/test_python_pytest_fixture_receivers.py— impacttests/test_python_underscore_resolution.py— impacttests/test_rationale.py— impacttests/test_resolution_one_parse_per_file.py— impacttests/test_ruby_resolution.py— impacttests/test_scala_context_bounds.py— impacttests/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).
|
Landed on |
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-filecallsedges when invokinghelpers.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 = requirestatements. During member call resolution, calls against an unshadowed namespace alias resolve through the target module's exported candidates to emit the appropriatecallsedge.Fixes #5114
Type of change
Verification & Invariants
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.pyGraphify-specific checklist