docs / Compiler

IR Format

The ephemeral typed IR: a class hierarchy in ir.ts, consumed by the server and client codegen visitors and by vesk-native-compiler.

The compiler IR is a typed class hierarchy in `packages/compiler/src/ir.ts`. It is ephemeral: created per compilation by ir-generator.ts, consumed immediately by the server and client codegen visitors. Nodes dispatch via `instanceof`.

Root nodes

  • IRRoot — components, imports, staticProps (hoisted `export const props = {...}`), loadFn, topLevelCode.
  • ComponentIR — name, paramNames, propsType, isClient, isAsync, ssrAwait, mode ('expression' | 'statement'), body, style, exported flags.

Node types

Class Meaning
Expression A source-text expression (raw, deps, ast)
StaticNode HTML element with static attrs
TextNode Literal text
DynamicBinding Interpolated expression (text or attribute)
OpaqueDynamicRegion Conditional region
MapRegion List rendering (for...of or .map())
ForLoop / WhileLoop Classic for, for...in, while, do...while
SwitchBlock / TryCatch switch and try/catch fallback
TrackDecl Tracked declaration (&[])
ComponentRef / ComponentCall Child component reference or invocation
SlotNode props.children rendering
ServerBlock / ClientBlock {#server} / {#client} blocks
HeadBlock / RuntimeStatement Head content / verbatim preserved statement

Codegen contract

  • Server walks nodes pushing HTML string chunks to an `__out` array; ServerBlock renders, ClientBlock returns ''.
  • Client walks nodes creating real DOM; ServerBlock returns null, ClientBlock renders.
  • In hydrate mode, `<!--vsk-->` claim markers precede subtrees that need client JS.