feat: add Svelte and Vue import parsing to dependency graph#9
Open
pineapplestrikesback wants to merge 1 commit intogiancarloerra:mainfrom
Open
feat: add Svelte and Vue import parsing to dependency graph#9pineapplestrikesback wants to merge 1 commit intogiancarloerra:mainfrom
pineapplestrikesback wants to merge 1 commit intogiancarloerra:mainfrom
Conversation
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).
Contributor
|
Nice! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
.svelte/.vuefiles as HTML (built-inLang.Htmlgrammar)<script>block content (script_element→raw_text)Lang.TypeScript)Changes
code-graph.ts.svelteand.vueingetAstGrepLang()graph-imports.tsextractJsTsImportsFromNode()helpergraph-resolution.ts"svelte"/"vue"resolution with.svelte/.vueas first-priority extensionsgraph-imports.test.ts<script module>, no-script, and plain JSBefore/After (real-world Svelte monorepo)
data/types/external.tsdependentsKnown limitations
$lib/,@/) are not resolved — treated as external packages (same as current JS/TS behavior). Could be added as follow-up work.@importin<style>blocks is not tracked (consistent with existing CSS behavior).Test plan
tsc)