What the compiler writes

2 min·Assumes: state, events

When you
a .tsrx file, it becomes small pieces with stable IDs, before the page runs anywhere.
import { state } from '@markless/core';

export default function Chat() @{
	let draft = state('Hi');

	<>
		<p>Typing: {draft}</p>
		<input
			onInput={(e) => (draft = e.target.value)}
		/>
	</>
}

draft becomes the node state:draft. {draft} becomes symbol:1, a small function that sets that one line's text when draft changes. onInput becomes symbol:0.

Every line becomes named pieces

A symbol is one small function with a stable ID, in a module of its own:

  • each state() becomes a node, like state:draft
  • each handler becomes a symbol, like symbol:0
  • each spot that shows a value becomes an update symbol, like symbol:1

Each colour joins a span of the source to the piece it became. Hover one, then press Edit and change the code. The compiler runs in your browser:

chat.tsrx
3 pieces
  1. import { state } from '@markless/core';
  2. export default function Chat() @{
  3. let draft = state('Hi');
  4. <>
  5. <p>Typing: {draft}</p>
  6. <input
  7. onInput={(e) => (draft = e.target.value)}
  8. />
  9. </>
  10. }

… 0 more lines

state:drafta watched value
symbol:1updates the <p>
symbol:0runs on input

… and 0 more

Doesn’t compile yet:

The chat box compiles to three pieces: state:draft, symbol:1 for the text update, and symbol:0 for the input handler.

  • Each piece points back at the line it came from.
  • Change state('Hi') to a plain 'Hi': the node and its update disappear, and the build names the handler that still writes it.

The pieces are planned by a chain of passes

A pass is one small step with named inputs and outputs. The first one runs the analyzer and writes the semantic graph: every value, element, read and write in the file. The 16 passes, in the order they run:

  1. tsrx-semantic-graphReads the file into the semantic graph.
  2. state-loweringTurns state reads and writes into graph reads and writes.
  3. payload-arenaPlans the state record and the view record.
  4. symbol-resolverPlans one symbol per handler and per update.
  5. render-dataSplits the elements into fixed HTML and the slots that change.
  6. projection-armsFinds the {children} a redrawn @if, @switch or @try arm would freeze.
  7. public-render-planCollects scoped styles and decides what the render modules can write.
  8. capture-analysisChecks that each symbol reads only what can cross to the browser.
  9. protocol-stateWrites the state record.
  10. protocol-viewWrites the view record, with symbol IDs on each entry.
  11. public-render-moduleWrites the browser and server render modules.
  12. server-only-propsStops the compile if browser code reads a prop the server keeps to itself.
  13. payload-scriptsWrites the markless/state and markless/view script tags.
  14. symbol-modulesWrites one module per symbol.
  15. runtime-demand-mapLists the runtime code each symbol and record needs.
  16. trigger-groupsGroups each event with the state, records and symbols it touches.
  17. symbol-resolver-moduleWrites the module that loads symbols by ID.

For a component this simple, the browser module is a direct module: it keeps state:draft in a plain Map and puts the listener on the input itself. Props, child components, a scoped <style> or a computed() send a component down the general path instead.

The payload shows what a server sends with these pieces.