Skip to content

fix(js): resolve class extends through CJS require bindings - #4700

Closed
Mpasha17 wants to merge 2 commits into
Graphify-Labs:v8from
Mpasha17:fix/js-extends-require-4688
Closed

Mpasha17 wants to merge 2 commits into
Graphify-Labs:v8from
Mpasha17:fix/js-extends-require-4688

Conversation

@Mpasha17

@Mpasha17 Mpasha17 commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #4688.

What was wrong

#4634 stopped creating a module-scope node for const X = require('./m') so new X() could reach the required class. That fixed the shadowing half of #4621, but class A extends X went through the same missing binding and ended up with no inherits edge at all (webpack AssetGenerator extends Generator is the real-world case).

What changed

In the JS/TS symbol-resolution facts pass:

  • Treat whole-module const/let/var X = require('./m') (and TS import X = require('./m')) as a default import alias, same shape as ESM import X from './m'.
  • Record module.exports = Name / exports.X = … as export facts so that alias can resolve to the class in the required file.
  • Do not recreate the old local binding node.

Follow-up after review: only module.exports = … mints a default export (bare exports = X is ignored), and chained assignments walk to the final RHS so module.exports = exports = Foo exports Foo.

Destructured / require('./m').y forms are left alone — they already have structural imports edges, and minting symbol-import facts for them regresses the EXTRACTED call path.

External require('pkg')

Checked against ESM: import X from 'some-plugin' also has no calls/inherits edge today, only imports_from to a ref_… id. Restoring a local stub would undo #4634. So unresolved package requires stay without a use edge, matching ESM / #4634.

Tests

  • New regressions in tests/test_js_extends_require_4688.py (10 cases: local require extends, let/var/ts, ESM control, import = require, renamed require, new no-regression, external CJS vs ESM, bare exports = ignored, chained module.exports = exports = Foo).
  • Full suite on 3.10 / 3.12 / 3.13 / 3.14 vs unmodified v8: same pre-existing failures on both trees, no new ones.
  • Live CLI e2e on the issue repro + webpack Generator.js / AssetGenerator.js under /workspace/e2e-4688 — before: no A inherits, no AssetGenerator inherits; after: both land on Generator in the required file.

Limitations

Written with help from Grok Bot; I reviewed and tested it.

After Graphify-Labs#4634 stopped minting a module-scope node for
`const X = require('./m')`, `class A extends X` lost its inherits
edge entirely. Record whole-module require bindings and
`module.exports = Name` as symbol import/export facts so heritage
resolves to the required class, matching ESM default imports.

Fixes Graphify-Labs#4688

Co-Authored-By: Grok Bot
@Mpasha17
Mpasha17 requested a review from safishamsi as a code owner October 23, 2026 10:13
@github-actions

Copy link
Copy Markdown

Thanks for the pull request, @Mpasha17. 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 23, 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 2 advisory finding(s) below merit a look before merge.

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

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

Not verified on this run: \_collect\_js\_symbol\_resolution\_facts (unsupported), \_js\_module\_specifier (vacuous: never exercised).


Graphify review — findings

Restores class A extends X inheritance edges for const X = require('./m'), which broke when #4634 stopped minting a module-scope node for the require binding. Whole-module const/let/var requires and TS import X = require("./m") are now recorded as default imports, so heritage resolves through the same alias path as ESM import X from './m'; destructured and require('./m').y forms are deliberately left to the structural imports edges so the EXTRACTED confidence path doesn't regress. Adds CommonJS export facts for module.exports = Name, exports.Foo = ..., and module.exports = { ... }, with the whole-module form also exposed under its own local name. The export-side parsing is the loosest part: it decides which local name and key a require resolves to, and it treats bare exports = X and chained assignments as default exports. Makes _js_module_specifier dig into import_require_clause so TS import x = require(...) yields its module string instead of None.

Worth a look

  • Bare exports = X wrongly recorded as a CommonJS default export — graphify/extractors/resolution.py:2304 · Escalate · medium
    • NOT verified (no proof, no reproducing execution) — needs human review
  • Chained module.exports = exports = Foo exports the wrong local name — graphify/extractors/resolution.py:2270 · Escalate · medium
    • NOT verified (no proof, no reproducing execution) — needs human review
Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 3140 functions depend on the 190 functions this change touches.

Health — this change adds coupling hotspots:

  • worse: extract() — 1008 callers, 60 callees
  • worse: _collect_js_symbol_resolution_facts() — 3 callers, 30 callees

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

Test selection

Test selection

34 of 444 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_ejs_extractor.py — impact
  • tests/test_ext_tagged_id_clash.py — impact
  • tests/test_extract.py — impact
  • tests/test_forwarding_review_findings.py — impact
  • tests/test_import_extension_resolution.py — impact
  • tests/test_indirect_call_block_scoped_shadow.py — impact
  • tests/test_js_exported_scalar_bindings.py — impact
  • tests/test_js_extends_require_4688.py — impact, changed-test
  • tests/test_js_member_collisions.py — impact
  • 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_pr10_resolution_overrides.py — impact
  • tests/test_python_import_resolution.py — impact
  • tests/test_python_parse_memoization.py — impact
  • tests/test_rationale.py — impact
  • tests/test_resolve_memoization.py — impact
  • tests/test_source_key_memoization.py — impact
  • tests/test_src_layout_import_resolution.py — impact
  • tests/test_svelte_extraction.py — impact
  • tests/test_ts_new_expression_calls.py — impact
  • tests/test_typescript_module_extensions.py — impact
  • tests/test_unmapped_at_alias_resolution.py — impact
  • tests/test_vue_extraction.py — impact
  • tests/test_walk_python_tree_iterative.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 \_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\_module\_specifier.

The verifier did not have enough to check \_js\_module\_specifier, 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).

Bare `exports = X` only rebinds the local exports binding in CommonJS and
must not mint a default export. Chained `module.exports = exports = Foo`
must export Foo, not the intermediate name `exports`.

Co-Authored-By: Grok Bot
@Mpasha17

Copy link
Copy Markdown
Contributor Author

Thanks for the review — I checked both with live graphify extract repros and tests:

  1. Bare exports = X as a default export: real, introduced here. exports = Decoy alone was making require() resolve to Decoy; with module.exports = Real after it we still wanted Real. Now only module.exports = … counts as the module default. Fixed in 47cb49e.
  2. Chained module.exports = exports = Foo: real, introduced here. We were taking the intermediate left (exports) as the local name, so the require didn't land on Foo. Walks to the final RHS now. Fixed in 47cb49e.

Couldn't find the 2 out-of-diff findings. The Graphify check run has 0 annotations and its output only lists these 2, so if you can point me to them I'll take a look.

@safishamsi

Copy link
Copy Markdown
Member

Landed in 0.9.102 (published to PyPI), cherry-picked with your authorship preserved. Follow-up: rewrote test_external_require_new_matches_esm_no_calls_edge, which asserted an ESM-parity (no-edge) that no longer holds on the current tree for external requires - a pre-existing CJS/ESM asymmetry outside this PR's intra-project ./ require fix. Fixes #4688. Thanks @Mpasha17.

@safishamsi safishamsi closed this Nov 3, 2026
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.

JS/TS: after #4634, class A extends X with const X = require('./m') gets no inherits edge at all

2 participants