CodeVetter · Repo Unpack · Feature catalog
sveltejs/svelte
There are no routes or screens — the user-facing surface is a set of npm subpath exports and a compiler API. Broadly: the compiler API (`compile`, `compileModule`, `parse`, `parseCss`, `preprocess`, `print`, `migrate`), the component runtime lifecycle API (`mount`, `hydrate`, `unmount`, `flushSync`, `fork`, `tick`, `untrack`, `settled`), context and lifecycle helpers, and a set of reactive standard-library classes. Around those sit optional subpackages for transitions, animations, easing, motion springs, stores, attachments, and events. Compiler behaviour is configurable through a validated options table, and two experimental features — async mode and `hydratable` — gate themselves on a runtime flag.
- `compile(source, options)` returns `{ js, css, warnings, metadata: { runes }, ast }`, where `ast` is post-processed by `to_public_ast` into either a modern AST (metadata stripped via a zimmerframe walk) or a Svelte 4-shaped legacy AST via `convert` from `compiler/legacy.js`.
- `parseCss(source)` is a standalone CSS-only entry point that uses `Parser.forCss` — a static factory that `Object.create`s a Parser prototype and skips all Svelte component parsing setup — returning a `StyleSheetFile` node with collected `css_comments`.
- `migrate(source, { filename, use_ts })` (2,003 lines in `compiler/migrate/index.js`) is a Svelte 4 → 5 source-to-source codemod exposed publicly through `svelte/compiler`.
- `preprocess` accepts a `PreprocessorGroup` or array and applies hooks in a fixed order per preprocessor — `markup`, then `script`, then `style` — matching `<script>`/`<style>` blocks with dedicated regexes and stitching sourcemaps back together.
- Compiler options are a declarative validator table in `validate-options.js`: `css` ('injected'|'external'), `cssHash`, `dev`, `discloseVersion`, `hmr`, `modernAst`, `namespace` ('html'|'mathml'|'svg'), `preserveComments`, `preserveWhitespace`, `fragments` ('html'|'tree'), `warningFilter`, and `experimental.async`.
- `mount(component, options)` and `hydrate(component, options)` are the two client entry points; both funnel into `_mount`, which accepts `target`, `anchor`, `props`, `events`, `context`, `intro`, and `transformError`.
- The top-level `svelte` export surfaces `onMount`, `onDestroy`, `beforeUpdate`, `afterUpdate`, `createEventDispatcher`, `getAbortSignal`, plus re-exports of `flushSync`/`fork`, the context family, `hydratable`, `mount`/`hydrate`/`unmount`, `tick`/`untrack`/`settled`, and `createRawSnippet`.
- `getAbortSignal()` lazily creates an `AbortController` on the active reaction (`active_reaction.ac ??= new AbortController()`) and throws `get_abort_signal_outside_reaction` if called outside a derived/effect; the abort reason is the shared `STALE_REACTION` singleton error.
- `svelte/reactivity` ships seven reactive primitives: `SvelteDate`, `SvelteSet`, `SvelteMap`, `SvelteURL`, `SvelteURLSearchParams`, `MediaQuery`, and `createSubscriber`.
- `svelte/attachments` provides `createAttachmentKey()` (a `Symbol(ATTACHMENT_KEY)` recognised when spread onto an element) and `fromAction()`, which adapts a legacy `use:` action into the newer `{@attach}` form.
- `render(component, options)` on the server accepts `props`, `context`, `idPrefix`, `csp`, and `transformError`, and hard-errors with `invalid_csp` if both `csp.hash` and `csp.nonce` are supplied.
- `hydratable(key, fn)` is an experimental server→client data-transfer feature: the server side serialises values with `devalue` into a lookup keyed by string, and the client side reads them back out of `window.__svelte.h`; both sides throw `experimental_async_required` when `async_mode_flag` is false.
- Legacy Svelte 4 compatibility is a first-class subpackage: `svelte/legacy` exports `createClassComponent`, `asClassComponent`, `run`, and `createBubbler` for imperative/class-component migration.
- Dev-mode-only features live under `internal/client/dev/`: `hmr.js` (block-based component hot swap), `ownership.js` (mutation-of-non-bound-prop validation), `inspect.js`, `tracing.js`, `console-log.js`, and `debug.js`.
- The sandbox playground offers `pnpm download <url|github-repo|test-name>` and `--create-test`, which drives a headless Chromium via Playwright to pull a reproduction into a local sample directory.