You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Svelte: every .svelte file reports a syntax error at line 1; functions inside <script> are never extracted (extract_svelte feeds the whole file to the JS grammar) #3928
extract_svelte calls _extract_generic(path, _JS_CONFIG) on the raw .svelte file. The HTML template is not JavaScript, so tree-sitter hits a top-level ERROR at line 1 and never reaches function_declaration nodes inside <script>. Only imports survive, via the regex rescue pass. On a SvelteKit app with 394 components, every single one was flagged "syntax errors and may be partially extracted".
This is the same failure mode as #2788 / PR #3902 for Astro. Vue already avoids it via _vue_mask_non_script.
Reproduce (graphify 0.9.71, macOS, Python 3.13)
mkdir t && cd t
printf '<script>\n import { foo } from "./x";\n let n = 1;\n function bump() { n++; }\n</script>\n<button onclick={bump}>{n}</button>\n' > A.svelte
graphify extract . --code-only --no-cluster
Output:
warning: 1 file(s) had syntax errors and may be partially extracted: A.svelte (first error at line 1, 1 symbol(s) extracted)
wrote graphify-out/graph.json — 2 nodes, 1 edges
bump() is missing. Same result with <script lang="ts"> and with Svelte 5 runes ($state, $props).
Fix that works locally
Mirror extract_vue: mask non-script regions with _vue_mask_non_script (regex is generic <script …>…</script>), pick _JS_CONFIG when lang is js/jsx else _TS_CONFIG, run _normalize_ts_import_types, and pass source_override= to _extract_generic. The existing regex import-rescue stays as-is.
Can confirm this on 0.9.66 with a SvelteKit + Svelte 5 codebase (33 components, 30 using runes). Same root cause, same fix.
Before: 63 nodes / 108 edges across the 33 .svelte files, every file flagged "syntax errors ... partially extracted".
After masking non-<script> regions with _vue_mask_non_script and passing source_override= (the snippet you posted): 201 nodes / 341 edges, zero parse warnings.
$props/$derived/$state declarations and functions nested after the first markup error all come through, and line numbers stay correct. No context="module" blocks in this repo, so I can't speak to those.
One note for whoever picks this up: _vue_mask_non_script returns the first block's lang, which is fine for Svelte too, but a component with both <script context="module"> and <script> would only see the first block's lang. Worth handling if you touch it.
Activity
github-actions commentedon Sep 29, 2026
Thanks for opening this issue, @chrisltq97. A maintainer will take a look soon.
If you would like to discuss it in real time, come say hi on our Discord server. For longer-form questions and ideas there is also GitHub Discussions.
To help us triage, please make sure the report includes what you expected, what actually happened, and the steps (and a small sample) to reproduce it.
feat(extract): give .svelte a real AST pass via script masking
feat(extract): give .svelte a real AST pass via script masking
fix(extract): end a Svelte script block's trailing comment and report…
fix(extract): end a Svelte script block's trailing comment and report…
AlienAscension commentedon Oct 4, 2026
Can confirm this on 0.9.66 with a SvelteKit + Svelte 5 codebase (33 components, 30 using runes). Same root cause, same fix.
Before: 63 nodes / 108 edges across the 33
.sveltefiles, every file flagged "syntax errors ... partially extracted".After masking non-
<script>regions with_vue_mask_non_scriptand passingsource_override=(the snippet you posted): 201 nodes / 341 edges, zero parse warnings.$props/$derived/$statedeclarations and functions nested after the first markup error all come through, and line numbers stay correct. Nocontext="module"blocks in this repo, so I can't speak to those.One note for whoever picks this up:
_vue_mask_non_scriptreturns the first block'slang, which is fine for Svelte too, but a component with both<script context="module">and<script>would only see the first block's lang. Worth handling if you touch it.fix(extract): end a Svelte script block's trailing comment and report…
fix(extract): parse only Svelte script blocks in the AST pass