sveltejs/svelte
There are two distinct data pipelines. The compile-time pipeline moves a `.svelte` string through a hand-written state-machine parser into a Svelte AST, through a zimmerframe scope/analysis walk that attaches `metadata` and binding information, and out through target-specific ESTree builders into code + sourcemap + CSS. The runtime pipeline moves user mutations into `Source` signals, propagates dirtiness lazily through deriveds, collects affected effects into a `Batch`, and flushes them to write DOM. The two never share code — an ESLint rule enforces that runtime files cannot import from `../compiler/` or `#compiler`. State ownership is module-global on both sides: the compiler owns `compiler/state.js`, the runtime owns `active_reaction`/`active_effect`/`current_batch`.
- Input boundary for compilation is `remove_bom(source)` followed by `state.reset({ warning, filename })`, which clears `warnings`, `source`, `dev`, `runes`, and installs the user's `warningFilter` — every compile starts from a wiped module-global.
- Options arrive from two merged sources: the caller's `CompileOptions` (validated) and `<svelte:options>` attributes parsed out of the source into `parsed.options`, with the in-file values overriding the caller's for `css` and `runes`.
- TypeScript is detected before parsing via a `lang=` regex over `<script>` tags in the `Parser` constructor (setting `this.ts`), and TS nodes are then stripped from `fragment`/`instance`/`module` by `remove_typescript_nodes` before analysis ever sees them.
- The parser is a mutable state machine: `Parser` holds `index`, `stack`, `fragments`, and loops `state = state(this) || fragment` over `template.length`, with states in `1-parse/state/{fragment,element,tag,text}.js`.
- Analysis is a zimmerframe walk over a per-node-type visitor table; the fallthrough `_` visitor reconstructs `svelte-ignore` scope by scanning preceding `Comment` siblings and `leadingComments`, pushing onto `ignore_stack` in `compiler/state.js`.
- Scope and binding resolution is separated into `phases/scope.js` (`create_scopes`, `Scope`, `ScopeRoot`, `get_rune`, `set_scope`), and cyclic reactive statements are caught by `utils/check_graph_for_cycles.js`.
- CSS flows through its own sub-pipeline inside analysis — `analyze_css`, then `prune` (matching selectors against the template), then `warn_unused` — before `render_stylesheet` emits the final stylesheet in the transform phase.
- The output boundary merges sourcemaps twice: `esrap`'s `print` emits a map with `sourceMapContent: source`, then `merge_with_preprocessor_map(js, options, js_source_name)` folds in any preprocessor map supplied via `options.sourcemap`.
- On the runtime side, `$state` values pass through `proxy()` in `internal/client/proxy.js`, which refuses non-objects, anything already carrying `STATE_SYMBOL`, anything with `COMPONENT_SYMBOL`, and any object whose prototype is neither `Object.prototype` nor `Array.prototype`.
- Dependency tracking is a read-side side effect of `get(signal)`: when `active_reaction` is set and not `untracking`, the signal is appended to `new_deps` (or counted as `skipped_deps` when the read order matches the previous run, avoiding array allocation).
- Writes go through `internal_set` in `reactivity/sources.js`, which bumps the global `write_version` (via `increment_write_version` in runtime.js) and schedules dependents; `old_values` is a module-level `Map` used to restore pre-batch values.
- Effects are not run on write — they are collected into the singleton `current_batch` (`Batch.ensure()`), which owns `schedule`, `capture`, `apply`, `flush`, `discard`, and `settled`, and clears `collected_effects`/`legacy_updates`/`old_values` in its `finally` block.
- Server output is accumulated as an array of strings and nested `Renderer` children in `#out`, with `head()` creating a second Renderer tagged `type = 'head'` so head content can be emitted out of document order.
- Escaping is centralised in the standalone `src/escaping.js`: `escape_html(value, is_attr)` uses `/[&"<]/g` for attributes and `/[&<]/g` for content, escaping only `&`, `"`, and `<`.
- Compile-time and runtime data are kept structurally disjoint by a bespoke ESLint rule `no_compiler_imports`, which string-searches every file under `src/` (excluding `src/compiler/`) for `../compiler/` or `#compiler` and reports a hard error.