Repository navigation
fix(extract): parse TS 5 export type star re-exports (#3942) - #4303
ayushcodes10 wants to merge 2 commits into
Conversation
export type star from a module has no equivalent in tree sitter typescript 0.23, the latest release: the grammar raises an error on the type keyword in this position, and the whole file is dropped, losing every symbol, not just the one statement. A barrel file that only re exports types this way reported a syntax error and contributed nothing to the graph. The construct is erased at compile time, the same as import type and export type with a brace list, so the graph only needs the re export edge, not the type only distinction. Blank out the type keyword, keeping every other byte and offset identical, before parsing, so the grammar reads the ordinary, already supported star re export form instead. Unlike the existing import call type argument workaround, this prefix is never ambiguous with a runtime expression, so no AST based disambiguation pass is needed here, only a direct text match. Fixes Graphify-Labs#3942.
Covers the syntax error disappearing, the re export edge and the target file's own symbol both surviving, the already working named form staying untouched, and the normalize helper itself: it blanks only the type keyword at the right byte offsets, and returns none when there is no star form to rewrite. Confirmed to fail against pre fix code with an import error, since the helper did not exist yet.
|
Thanks for the pull request, @ayushcodes10. 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 1 changed function(s) (1 sampled, not proven).
Formal verification. PR-changed functions: 1/1 verified (0 proven, 1 may-equivalent, 0 distinguished) · 0 not verified.
Graphify review — findings
Fixes TypeScript files containing export type * from "..." being dropped entirely: tree-sitter-typescript 0.23 errors on that type keyword. _normalize_ts_export_type_star now blanks the keyword in place, preserving byte offsets, so the file parses as a plain export * from and keeps its re-export edge and symbols. extract_js runs the existing import(...) type normalization on top of that rewrite; star re-exports lose their type-only distinction, while export type { X } keeps its type_only stamp.
Worth a look
- Type-only star re-exports now emit runtime re-export edges without the type_only stamp —
graphify/extract.py:2021· Escalate · medium- agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
Analysis details — impact, health, verification
Impact & health
Graphify review
Impact — 2627 functions depend on the 293 functions this change touches.
Health — this change adds coupling hotspots:
- worse:
extract()— 844 callers, 51 callees - worse:
extract_js()— 87 callers, 6 callees
Verification — 2627 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: 2428 function(s) in the blast radius were not formally verified this run
Test selection
Test selection
163 of 362 test file(s) selected (45%) via static blast radius.
tests/test_astro_extraction.py— impacttests/test_astro_import_ids.py— impacttests/test_blade_extractor.py— impacttests/test_build.py— impacttests/test_builtin_global_type_refs.py— impacttests/test_cache.py— impacttests/test_case_sensitive_resolution.py— impacttests/test_cjs_module_extension.py— impacttests/test_cobol_extractor.py— impacttests/test_cpp_method_declarations.py— impacttests/test_cpp_nested_and_cli.py— impacttests/test_cpp_objc_cross_file_calls.py— impacttests/test_cross_extension_reexport_self_cycle.py— impacttests/test_cross_language_call_resolution.py— impacttests/test_cross_repo_external_call_guards.py— impacttests/test_cross_repo_member_calls.py— impacttests/test_csharp_call_site_generic_args.py— impacttests/test_csharp_enum_members.py— impacttests/test_csharp_field_generic_args.py— impacttests/test_csharp_generic_callsites.py— impacttests/test_csharp_interface_dispatch.py— impacttests/test_csharp_member_calls.py— impacttests/test_csharp_member_chain_calls.py— impacttests/test_csharp_member_nodes.py— impacttests/test_csharp_object_creation.py— impacttests/test_csharp_partial_classes.py— impacttests/test_csharp_tuple_type_refs.py— impacttests/test_csharp_type_resolution.py— impacttests/test_definition_file_portability.py— impacttests/test_detect.py— impacttests/test_dotnet.py— impacttests/test_duplicate_annotation_edges.py— impacttests/test_elixir_import_resolution.py— impacttests/test_elixir_keyword_def_calls.py— impacttests/test_elixir_qualified_calls.py— impacttests/test_elixir_unqualified_call_scope.py— impacttests/test_erlang_extractor.py— impacttests/test_extract.py— impacttests/test_extract_cache_location.py— impacttests/test_extract_path_memo.py— impacttests/test_extract_php_closures.py— impacttests/test_file_label_disambiguation.py— impacttests/test_file_node_id_spec.py— impacttests/test_forwarding_review_findings.py— impacttests/test_go_builtin_call_targets.py— impacttests/test_go_import_repoint.py— impacttests/test_go_interface_methods.py— impacttests/test_go_qualified_resolution.py— impacttests/test_import_extension_resolution.py— impacttests/test_import_self_loops.py— impact- … and 113 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
No difference found (not proven): No behavior difference found in extract\_js (not a proof).
The verifier ran both versions of extract\_js 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.
· 2 more finding(s) on lines outside this diff (see the check run).
Landed from PR #4303 (squashed, authorship preserved).
|
Landed in 0.9.85 (now on PyPI) via an authorship-preserving cherry-pick, so your commit authorship is retained. Thank you, @ayushcodes10! |
Addresses the TypeScript half of #3942 (the Svelte half already shipped in v0.9.76 via #3984).
export type * from "./x"(TS 5.0's type-only star re-export) has no equivalent intree-sitter-typescript0.23 — currently the latest release on PyPI, confirmed by checking available versions. The grammar raises anERRORnode on thetypekeyword in this exact position, and the whole file is dropped, losing every symbol in it, not just the one statement. A barrel file that only re-exports types this way reported a syntax error and contributed nothing to the graph.The construct is erased at compile time, the same as
import type/export type { X }(both already handled correctly), so the graph only needs the re-export edge, not the type-only distinction. Added_normalize_ts_export_type_star, which blanks out just thetypekeyword — same byte length, same offsets — before parsing, so the grammar reads the ordinary, already-supportedexport * from "./x"form instead. Threaded intoextract_js's existing TS source-normalization chain (alongside the existingimport(...)type-argument workaround, composing cleanly with it since they target disjoint syntax).Unlike that existing workaround, this prefix is never ambiguous with a runtime expression (
export type *can only ever mean the type-only star re-export), so no AST-based disambiguation pass is needed — a direct regex match is sufficient and safe.Verified against the issue's exact repro: before,
index.tsreported a syntax error and extracted zero symbols; after, it correctly produces a re-export edge totypes.ts, andtypes.ts's ownFetchFntype survives. Confirmed the already-working named form (export type { X } from "./y") is untouched — still correctly stampedtype_onlyfor import-cycle exclusion (#1241/#3123). Four new regression tests intests/test_ts_export_type_star.py, confirmed to fail against pre-fix code (import error, since the function didn't exist). Full suite passes clean — the only failures were the known editable-install-trap pattern (confirmed via a targeted rerun with correct module resolution: 110/110 pass) plus one pre-existing unrelated Erlang gap.