Skip to content

feat(index): Svelte support + TS arrow function extraction - #390

Merged
ajianaz merged 1 commit into
developfrom
feat/svelte-ts-arrow-support
Jul 27, 2026
Merged

feat(index): Svelte support + TS arrow function extraction#390
ajianaz merged 1 commit into
developfrom
feat/svelte-ts-arrow-support

Conversation

@ajianaz

@ajianaz ajianaz commented Jul 27, 2026

Copy link
Copy Markdown
Collaborator

Summary

Closes #384 — adds Svelte support and TS arrow function extraction to the AST indexer.

Phase 1: TS Arrow Functions

Previously, lexical_declaration and variable_declaration only captured ALL_CAPS constants. Now also captures:

  • Arrow functions: export const handler = () => { ... }
  • Function expressions: const cb = function doStuff() { ... }
  • Call edges from arrow function bodies (via extract_calls_from_node)

Phase 2: Svelte Support

No tree-sitter-svelte dependency needed. Instead:

  1. Extract <script> blocks from .svelte files via regex
  2. Detect lang="ts" / lang="js" attribute (default: JS)
  3. Parse extracted content using existing tree-sitter-typescript / tree-sitter-javascript grammar
  4. Adjust line numbers with offset from script tag position
  5. Handle both inline (<script>code</script>) and multi-line script blocks

What's NOT captured (expected)

  • Svelte runes ($state, $derived, $props) — not valid TS/JS syntax
  • Component name from filename — AST parser works on code, not file names
  • Template calls (onclick={handler}) — HTML template is not parsed
  • Nested arrow functions inside callbacks — scope limitation

Test Results

  • 7 new unit tests: all pass
  • Updated 1 existing Svelte test for AST behavior
  • Full suite: 739/740 pass (1 pre-existing Ruby test failure, unrelated)
  • Real-world validated on cora-api SvelteKit project:
    • 86 .svelte files indexed
    • Functions extracted with correct line numbers
    • Svelte symbols appear in brain search
    • Arrow functions in .ts files captured (SvelteKit load functions)

Files Changed

  • src/index/ast.rsextract_svelte(), arrow function support in extract_typescript(), 7 tests
  • src/index/extract.rs — Svelte bypass in 3 get_language() gates, updated Svelte test
  • Cargo.toml — version bump to 0.8.3

Phase 1 - TS arrow functions:
- Capture exported const arrow functions: export const handler = () => {}
- Capture function expressions: const cb = function doStuff() {}
- Extract call edges from arrow function bodies

Phase 2 - Svelte support:
- Extract <script> blocks from .svelte files via regex
- Parse extracted content as TypeScript/JavaScript
- Support lang=ts and lang=js attributes
- Handle inline and multi-line script blocks
- Correct line number offset adjustment
- Zero new dependencies (reuses tree-sitter-typescript)

Tests:
- 7 new tests: arrow functions, function expressions, Svelte basic,
  line numbers, no-script, JS lang, inline script
- Updated existing Svelte test for AST behavior
- 739/740 pass (1 pre-existing Ruby test failure)

Real-world validated on cora-api SvelteKit project (86 .svelte files).
+13 symbols indexed in cora-code itself from arrow functions.
@ajianaz
ajianaz merged commit 23583dd into develop Jul 27, 2026
10 checks passed
@ajianaz
ajianaz deleted the feat/svelte-ts-arrow-support branch July 27, 2026 04:43
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.

TypeScript index coverage gaps — functions and handlers not indexed

1 participant