Repository navigation
Description
Problem
Per #254, .svelte files were added to CODE_EXTENSIONS and dispatched to the
JS/TS extractor, with the maintainer noting "template blocks are skipped by the
parser gracefully." This works for imports inside the <script> block, but
silently drops imports inside the markup block — most notably the
canonical SvelteKit lazy-load pattern:
{#await import('./recommendation-carousel.svelte') then { default: Carousel }}
<Carousel ... />
{/await}Because tree-sitter-javascript can't parse the surrounding {#await ... then ... /await}
mustache markup, it bails (or skips) before reaching the import(...) call.
The import is invisible to graphify, so the target component looks like an
orphan unless it's also imported elsewhere.
Why this matters
This pattern is the standard SvelteKit code-splitting idiom — used to defer
loading of heavy components, popovers, modals, command palettes, lazy charts,
etc. In a SvelteKit codebase that leans on it heavily (modern apps targeting
small initial bundles), most component-to-component edges live in markup, not
in <script>.
Repro
Any .svelte file with a markup-level dynamic import. Concrete example from
a 707-.svelte-file production SvelteKit codebase using graphifyy 0.7.0:
<!-- src/lib/components/app-sidebar.svelte (excerpt) -->
<script lang="ts">
// Dynamic loaded on demand to avoid hydration cost
let CommandPalette: ... | undefined = $state()
// ...
if (open && !CommandPalette) {
import('./command-palette.svelte').then((m) => (CommandPalette = m.default))
}
</script>
{#if CommandPalette}
<CommandPalette bind:open {menu} />
{/if}<!-- src/routes/(series)/[id]/(view)/+layout.svelte (excerpt) -->
{#await import('$lib/components/discover/queue-bar.svelte') then { default: QueueBar }}
<QueueBar series_id={series.id} />
{/await}In both cases the target .svelte shows up in graphify as an orphan despite
being live-loaded in production.
(Note: the first example's import(...) is technically inside <script> so
it should work in principle. Empirically it doesn't, suggesting tree-sitter-js
also struggles when the script block contains complex Svelte 5 runes like
$state mixed with dynamic imports. The second example is unambiguously
markup-level and definitely invisible.)
Impact in numbers
Same SvelteKit corpus as #691:
- 707
.sveltesource files - 26 of them flagged as "no incoming edges in graph" by hand-rolled query
- After grep-verification: ~20 of those 26 are actually used via dynamic
import (false positives ≈ 77%) - Knip exhibits the same blind spot for the same reason
Possible fixes (ordered by effort)
-
Regex pre-pass before handing the file to tree-sitter-js: scan the raw
file forimport\(['"]([^'"]+)['"]\)matches, emitimports_fromedges
from those, then continue with the existing JS extraction. ~20 lines, no new
deps. False positives possible (matches inside string literals or comments)
but rare in practice and lower-cost than missing them. -
Strip markup before parsing: for
.sveltefiles, extract just the
<script>and<script lang="ts">blocks with a regex, concatenate, and
feed to tree-sitter-js. Catches in-script dynamic imports reliably.
Misses pure-markup dynamic imports. -
Add
tree-sitter-svelteas an optional language. Proper solution but
requires shipping another grammar and writing aLanguageConfigfor it.
(1) and (2) combined would solve ~95% of the problem at low cost.
Activity
safishamsi commentedon May 4, 2026
Fixed in v0.7.1.
.sveltefiles now get a regex pass over the raw source after tree-sitter AST extraction. Markup-level dynamic imports like{#await import('./Modal.svelte')}in the template layer are captured as edges. Upgrade:pip install --upgrade graphifyy