Skip to content

TypeScript and Astro

Mikhail Deynekin edited this page Nov 22, 2026 · 1 revision

TypeScript, JavaScript and Astro: what counts as a fact

Why this page exists. An outside review of release 0.11.0 on a TypeScript + Astro project found that call graphs and dead_code could not be trusted there, and that .astro files were not indexed at all. This page states what the index does with those languages now, what it refuses to claim, and where the code for each statement lives.

What became symbols

Construct Symbol Where the rule lives
function f() {} function PROFILES["typescript"].functions
const f = () => {} function LangProfile.function_values (arrow_function)
const f = function () {} function function_values (function_expression)
const g = function* () {} function function_values (generator_function)
const port = 8080 none the value is not functional
type Id = string | number type_alias LangProfile.type_aliases

Two fields instead of one exist for a reason: treating every variable_declarator as a function would have turned any constant into a symbol with no calls, and dead_code would have received a false target.

How a cross-file call is bound

A call that the extractor cannot resolve becomes an @ext:<name> placeholder. A post-pass of the indexer (Indexer._resolve_js_imports, module src/ragraf/imports_js.py) reads the import lines and replaces the placeholder with an edge to the real definition:

  • evidence_kind="import", provenance="derived", confidence 0.9;
  • the evidence address (path:line) is taken from the placeholder being replaced — that is exactly where the call is written. Before 0.13.0 the answer carried app.ts:None;
  • package specifiers (react, @scope/pkg) are not bound: there is no file to bind them to;
  • tsconfig.paths aliases are not supported — a named gap, not a quiet approximation;
  • the same pass creates an imports edge (file → file), which also counts as an incoming reference for dead_code.

dead_code: the verdict and the unproven

The answer keeps two lists apart:

  • files — the verdict: no references at all, including no incoming imports;
  • unproven — files whose calls could not be bound (evidence_kind="external_call"). «No reference found» is not the same fact as «the reference was not built», so such files never reach the verdict; their call names and the reason are named, and extra["unproven_count"] counts them.

Astro

.astro files are indexed: the frontmatter and every <script> block are parsed as TypeScript with the markup masked, and line numbers are preserved, so path:line points at the real line of the page. Markup itself does not become symbols — a template is not a call graph. The astro format is a registry entry like any other: it is visible and switchable in the panel, and disabling it counts files in skipped_formats.

The set of tree-parsed languages is {"php","css","html","astro"} | set(PROFILES) (Indexer._parse_languages): astro is not a grammar profile but its own extractor, and without that line the file went down the text path — measured before the fix: four files in the corpus, and the page contributed only a file node.

Where the index lives, and what happens when it cannot

The index is .ragraf/ inside the project root — not a setting, because the corpus checksum and the **/.ragraf/** self-exclusion are computed from that root. If the directory is protected, ragraf index stops with exit code 3 and names the reason (util.dir_blocker) instead of failing inside sqlite with «file does not exist». Index a copy in a writable location.

How this is verified

Check What it holds
tests/test_client_report.py 30 properties: TS symbols, import binding, dead_code, Astro and line numbers, index_status, db.enabled, journal kind, neighbors with two corpora, damaged registry
tests/test_drift_restore.py 8 properties: change → warning → file restored → no warning, journal keeps both records
tests/test_lang_routing.py, tests/test_new_languages.py language set agrees with the profiles (set comparison, no numbers)
tests/test_formats.py every extension of the language map belongs to a format

The layer document in the product tree is docs/03_implementation/TYPESCRIPT-AND-ASTRO.md.

Clone this wiki locally