rsvelte

Architecture

An overview for contributors.

Parse once, share the results

  1. A parser reads the source and builds syntax trees. rsvelte parses JavaScript and TypeScript with oxc. After parsing, nothing changes a tree, with one exception: the semantic analysis of oxc writes scope and symbol IDs into the trees of oxc.
  2. Semantic analysis records facts, such as the scope of each variable, in tables beside the trees. A database per file holds the trees and the tables.
  3. A plugin, such as the Svelte linter, adds tasks. A task is one job that runs on each file. Its name is the plugin's name and a kind: svelte.lint/default is the lint task of the svelte.lint plugin. A task asks the database for the results it needs. The database computes a missing result once and shares it with the other tasks of that file.
  4. Each worker thread takes one file at a time, so files run in parallel. A type check task also runs once after all files, to check the whole project.

Crates

DirectoryWhat it holds
crates/language_independent/Code that does not depend on a language: the database and the task scheduler (kernel), and the interface between hosts and plugins (plugin_interface). It also holds documents, positions and diagnostics, and the shared code of lint tools, formatters and test runners.
crates/languages/<language>/Each language's parser and analysis, and its tools: compile, lint, format and check.
crates/bridges/Cross-framework compilers, such as one that compiles Vue components for the Svelte runtime. The rsvelte command does not include them.
crates/hosts/Programs that combine plugins and run them: the rsvelte command (command_line) and the WebAssembly build (browser).

Each tool is a crate that registers its tasks, such as svelte.compile/client. rsvelte format is the one command without tasks: it runs oxfmt's file handling, which calls the Svelte formatter.

Type checking

typecheck turns each Svelte component into TypeScript code. It passes that code and a map back to the original positions to the TypeScript 7 type checker. The checker uses the map to report each error at its position in the Svelte file. The conversion lives in crates/languages/svelte/typescript_projection.

Comparison with the official tools

corpus/ holds real Svelte 5 files from projects under permissive licenses, such as MIT, and files written for this project. The official tools, such as svelte and svelte-check, produce the expected output.

cargo test compares rsvelte's output with the expected output. A ledger (corpus/_registry/parity/) records, for each task, whether each file matches: its verdict. When a verdict changes, the test fails. To accept an intended change, run it with UPDATE_EXPECT=1.

Contributing

cargo test                                        # the Rust tests
cargo test -p rsvelte_command_line --test corpus  # the comparison with the official tools
pnpm install && pnpm run check                    # the TypeScript side

AGENTS.md has the rules for contributors, and crates/README.md describes the crates.