Skip to content

feat: add Svelte and Vue import parsing to dependency graph#9

Open
pineapplestrikesback wants to merge 1 commit intogiancarloerra:mainfrom
pineapplestrikesback:feat/svelte-import-parsing
Open

feat: add Svelte and Vue import parsing to dependency graph#9
pineapplestrikesback wants to merge 1 commit intogiancarloerra:mainfrom
pineapplestrikesback:feat/svelte-import-parsing

Conversation

@pineapplestrikesback
Copy link
Contributor

Summary

Svelte and Vue files were included in the dependency graph as leaf nodes but their imports were never extracted (no ast-grep grammar exists for these languages). This adds support with zero new dependencies by:

  1. Parsing .svelte/.vue files as HTML (built-in Lang.Html grammar)
  2. Extracting <script> block content (script_elementraw_text)
  3. Re-parsing script content as TypeScript (Lang.TypeScript)
  4. Running existing JS/TS import extraction on the inner AST

Changes

File Change
code-graph.ts Register .svelte and .vue in getAstGrepLang()
graph-imports.ts Add Svelte/Vue handler; refactor JS/TS extraction into shared extractJsTsImportsFromNode() helper
graph-resolution.ts Add "svelte"/"vue" resolution with .svelte/.vue as first-priority extensions
graph-imports.test.ts 7 new tests covering static imports, dynamic imports, <script module>, no-script, and plain JS

Before/After (real-world Svelte monorepo)

Metric Before After
data/types/external.ts dependents 31 (only .ts files) ~101 (includes .svelte consumers)
Orphan file count 168+ (inflated) Significantly reduced

Known limitations

  • Path aliases ($lib/, @/) are not resolved — treated as external packages (same as current JS/TS behavior). Could be added as follow-up work.
  • CSS @import in <style> blocks is not tracked (consistent with existing CSS behavior).

Test plan

  • All 488 unit tests pass (including 7 new Svelte/Vue tests)
  • TypeScript build passes (tsc)
  • Integration test: rebuild graph on a Svelte project and verify .svelte file imports are extracted
  • Verify no regression for existing JS/TS/Python/etc. graph builds

Svelte and Vue files were included in the graph as leaf nodes (targets
of import edges) but their own imports were never extracted because
no ast-grep grammar exists for these languages.

This adds support by parsing .svelte/.vue files as HTML (built-in
grammar), extracting <script> block content, and re-parsing it as
TypeScript to extract imports using the existing JS/TS logic.

Changes:
- code-graph.ts: register .svelte and .vue in getAstGrepLang()
- graph-imports.ts: add Svelte/Vue script extraction handler; refactor
  JS/TS import extraction into shared extractJsTsImportsFromNode()
  helper to avoid duplication
- graph-resolution.ts: add "svelte" and "vue" cases to resolveImport(),
  with .svelte/.vue as first-priority extension resolution
- graph-imports.test.ts: add tests for Svelte (static, dynamic, module,
  no-script, JS-only) and Vue import extraction

Zero new dependencies — uses the built-in Lang.Html and Lang.TypeScript
grammars from @ast-grep/napi.

Known limitation: path aliases ($lib/, @/) are not resolved and will be
treated as external packages (same as current JS/TS behavior).
@cstuncsik
Copy link
Contributor

Nice!
I hope this gets merged soon

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.

2 participants