Skip to content

fix(ts): preserve declarations after import type arguments - #3185

Closed
hopstreax wants to merge 1 commit into
Graphify-Labs:v8from
hopstreax:fix/3154-ts-import-type-arguments
Closed

fix(ts): preserve declarations after import type arguments#3185
hopstreax wants to merge 1 commit into
Graphify-Labs:v8from
hopstreax:fix/3154-ts-import-type-arguments

Conversation

@hopstreax

Copy link
Copy Markdown
Contributor

Summary

Fixes #3154.

TypeScript import(...) types used as explicit call-expression type arguments, such as:

f<typeof import("mod")>()
f<import("mod").Foo>()

were incorrectly parsed by tree-sitter as comparison expressions. The resulting recovery could swallow declarations later in the file, causing them to be missing from Graphify's extracted graph.

What changed

  • Added byte-length-preserving normalization for import(...) types inside explicit TypeScript call-expression type arguments.
  • Applied the normalization to .ts, .tsx, .mts, and .cts extraction.
  • Applied the same normalization to TypeScript/TSX Vue script blocks.
  • Preserved byte offsets and newline positions so source locations remain accurate.
  • Added regression coverage for TypeScript and TSX, including multiline type arguments and declarations following the affected expression.

Validation

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

Formal verification. No changes could be formally verified in this run.


Graphify review — findings

Fixes silent symbol loss in TypeScript/TSX files where import(...) types inside call-expression type arguments (e.g. f<typeof import("mod")>()) trip up tree-sitter's parser, whose error recovery otherwise absorbs subsequent declarations into a malformed comparison expression. extract_js and extract_vue now run _normalize_ts_import_types over the source before parsing, rewriting the offending import(...) to a same-byte-length type identifier so declarations after the expression are extracted while source locations and offsets stay exact. The normalization is a no-op (returns None) when no import( appears, and any read failure falls back to unmodified parsing.

Worth a look

  • TypeScript import-type normalization skips legal whitespace before '('graphify/extract.py:1285 · Escalate · medium
    • agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
  • Normalizer skips valid whitespace before import-type parenthesesgraphify/extract.py:1286 · 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 — 1677 functions depend on the 228 functions this change touches.

Health — this change adds coupling hotspots:

  • new: extract() — 502 callers, 42 callees
  • new: _rebuild_code() — 98 callers, 50 callees
  • new: extract_js() — 85 callers, 4 callees
  • new: extract_xaml() — 19 callers, 17 callees
  • new: dispatch_command() — 2 callers, 122 callees
  • new: _get_extractor() — 26 callers, 6 callees
  • new: run_pipeline() — 8 callers, 13 callees
  • new: collect_files() — 17 callers, 6 callees
  • …and 23 more — each is listed as a finding

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

Formal verification

Could not verify: Could not verify extract\_js.

The verifier did not have enough to check extract\_js, 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: parameter `path` is annotated `Path` — outside the synthesizable primitive/collection set

Could not verify: Could not verify extract\_vue.

The verifier did not have enough to check extract\_vue, 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: parameter `path` is annotated `Path` — outside the synthesizable primitive/collection set

· 1 grounded finding(s) anchored inline below; 30 more finding(s) on lines outside this diff (see the check run).

Comment thread graphify/extract.py
@@ -1271,13 +1313,21 @@ def extract_python(path: Path) -> dict:
def extract_js(path: Path) -> dict:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Health regressionextract_js()

85 callers depend on it (afferent coupling).

Grounded coupling-delta finding (deterministic), not an LLM guess.

safishamsi pushed a commit that referenced this pull request Aug 29, 2026
An `import(...)` used as a call type-argument (f<typeof import('mod')>()) could make the
parser drop declarations that follow it. Rewrite the import-type to a byte-length- and
newline-preserving placeholder before parsing so trailing declarations survive with exact
source locations; the dynamic-import edge is still recovered by re-reading the original
file. On the pinned tree-sitter-typescript (0.23.2) only the multiline form regresses today;
the single-line/member/TSX tests guard against regressions on future grammar bumps.
safishamsi added a commit that referenced this pull request Aug 29, 2026
Ships three batches: php new Foo() calls (#3115), inherited-field receivers (#3151), objc
field-table remap (#3150), ts type-only-import cycles (#3123) and import-type args (#3185);
razor @Inject cross-file (partial #3187), MCP prs isError + get_node resolver parity,
project-scoped bare hook command (#3129); and T-SQL routine recovery (#3164), watch
markdown->semantic reconcile (#3190), --help completeness, and a deepseek pricing fix. The
#3155 provenance backfill was reverted (regressed the orphan prune).

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

Copy link
Copy Markdown
Collaborator

Shipped in v0.9.52 via authorship-preserving cherry-pick so you keep contributor-graph credit. Thanks @hopstreax! Release: https://github.com/Graphify-Labs/graphify/releases/tag/v0.9.52

@safishamsi safishamsi closed this Aug 29, 2026
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.

TypeScript: an import(...) type used as an explicit type argument is a syntax error, dropping symbols after it

2 participants