Skip to content

fix(extract): resolve alias re-exports and imports through barrels to the defining symbol (#1983)#2034

Closed
HerenderKumar wants to merge 1 commit into
Graphify-Labs:v8from
HerenderKumar:alias-reexport-symbol-ids
Closed

fix(extract): resolve alias re-exports and imports through barrels to the defining symbol (#1983)#2034
HerenderKumar wants to merge 1 commit into
Graphify-Labs:v8from
HerenderKumar:alias-reexport-symbol-ids

Conversation

@HerenderKumar

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #1983. e5a4b51 fixed the issue's direct reproducer, but its rewrite learns old→canonical symbol forms only from symbols a file defines. A barrel defines nothing — so a named re-export or import that resolves through a barrel still synthesizes an absolute-prefixed target no rewrite ever learns: the checkout path leaks into the edge target and the edge dangles.

Verified on current v8 head:

re_exports: src_barrel2 -> <checkout>_src_lib_index_formatdate  (dangling)
imports:    src_consumer -> <checkout>_src_lib_index_formatdate  (dangling)

for export { formatDate } from '@/lib' / import { formatDate } from '@/lib' where src/lib/index.ts is itself a barrel re-exporting from @/lib/utils.

Fix

Three parts, extending existing machinery rather than adding a new pass:

  • _import_js stamps target_file on symbol-level re_exports/imports edges — the same transient hint the file-level edge has carried since Phantom self-cycles: same-basename cross-extension re-exports (X.ts → ./X.mjs) collapse to one node #1814 (no downstream reader; stripped at build).
  • The id-remap post-pass gains a repoint step after the candidates rewrite: decompose a still-unowned target into (canonical file stem, symbol) via the stamp, follow the barrel's own already-canonical re_exports edge to the defining symbol — iterating one hop per pass so multi-hop barrel chains resolve — and, when no chain leads to a real node, canonicalize the prefix anyway so a checkout-specific path never survives in an edge target.
  • The redundant-twin dedup now excludes target_file from edge identity, so an alias edge (stamped) still matches the canonical twin the shared resolver emits (unstamped).

Testing

  • 3 new tests: single-hop barrel re-export resolves to the defining symbol; two-hop chain resolves; no re_exports/imports target contains the checkout prefix (the issue's core "Expected" line).
  • Red-green verified: with the production change reverted, exactly the 3 new tests fail; restored, tests/test_js_import_resolution.py passes 61/61 — including the e5a4b51 owned-symbol guard tests (test_alias_import_does_not_remap_an_owned_symbol_id, test_alias_import_preserves_owned_same_line_symbol_edge).
  • Regression sweep: failure sets for tests/test_extract.py + tests/test_charmap_encoding.py are name-for-name identical between this branch and clean origin/v8 in my environment (31 pre-existing failures from missing grammar packs on both sides).

Fixes #1983.

safishamsi added a commit that referenced this pull request Jul 20, 2026
…2034)

The barrel-chain resolver keyed (source, symbol) -> target as last-write-wins, so
a barrel re-exporting the same local name from two modules collapsed an importer's
edge onto whichever was learned last — a fabricated wrong edge. Learn into a set
per key and refuse to resolve when a name maps to more than one target; the edge
falls to the dangling-canonical fallback (dropped at build) instead. Adds a
regression test.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@safishamsi

Copy link
Copy Markdown
Collaborator

Thanks @HerenderKumar — shipped in v0.9.21, with a follow-up to leave a genuinely ambiguous barrel re-export unresolved rather than guess a target. Released to PyPI: https://github.com/Graphify-Labs/graphify/releases/tag/v0.9.21

@safishamsi safishamsi closed this Jul 20, 2026
@HerenderKumar
HerenderKumar deleted the alias-reexport-symbol-ids branch July 23, 2026 04:29
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.

Alias-based named re-exports emit dangling absolute-path symbol targets

2 participants