Syntax

Braces put a value in text, a colon binds an attribute, a dot toggles a class, an at sign calls a function and a dollar sign names something from the script. Conditions and loops are tags.

Text: {path}

{$name} is the only way to put a value in text, and it works inside attribute strings too: title="Profile of {$name}", href="#user-{$slug}".

routes/examples/syntax/_components/interpolation/interpolation.html

<script>  let name = 'Ada Lovelace'  const slug = () => name.trim().toLowerCase().replaceAll(/\s+/g, '-') || 'anonymous'  const length = () => name.length</script><div>  <label class="interpolation-field">    <span class="label">name</span>    <input class="interpolation-input" autocomplete="off" :model="$name">  </label>  <p class="interpolation-line">Hello {$name}, your name has {$length} characters.</p>  <a class="interpolation-link" href="#user-{$slug}" title="Profile of {$name}">#user-{$slug}</a>  <p class="interpolation-note">Literal braces: <code>{$name}</code> inside code, and \{$name} after a backslash.</p></div><style>  [data-c="interpolation"] {    display: grid;    gap: 0.875rem;    width: 100%;    max-width: 20rem;  }  .interpolation-field {    display: grid;    gap: 0.375rem;  }  .interpolation-input {    width: 100%;    padding: 0.375rem 0.5rem;    border: 1px solid var(--color-line-strong);    background: var(--color-sunken);    color: var(--color-ink);    font-size: 0.875rem;  }  .interpolation-line {    padding: 0.75rem 1rem;    border: 1px solid var(--color-line);    background: var(--color-surface);    overflow-wrap: anywhere;  }  .interpolation-link {    color: var(--color-ink);    font-family: var(--font-mono);    font-size: 0.75rem;    text-decoration: underline;    text-underline-offset: 0.25em;    overflow-wrap: anywhere;  }  .interpolation-note {    color: var(--color-faint);    font-family: var(--font-mono);    font-size: 0.75rem;  }  .interpolation-note code { color: var(--color-ink); }</style>

Live result

Hello Ada Lovelace, your name has 12 characters.

#user-ada-lovelace

Literal braces: {$name} inside code, and {$name} after a backslash.

Type &lt;b&gt;bold&lt;/b&gt; into the field: the value is always escaped text, never HTML.
  • Only paths go between the braces: $x, data.x, shared.cart.total, params.id or a <for> variable. A function from the script is a derived value: {$length} calls length() on every render.
  • Values are escaped; null and undefined print nothing. A page with ssr gets them in the first HTML; otherwise the runtime fills them at boot, and the raw {โ€ฆ} never shows.
  • Braces are literal text inside <code> and <pre>, which is how this page shows them. Anywhere else, \{ writes a literal brace.
  • For a whole value or a boolean attribute use :attr instead (:disabled="$offline"). {} is not allowed in class (use .name) or in a component prop (pass a path: :title="$title").

Values are paths, never expressions

Every directive takes a path of the form root.a.b. The roots are $x (a name from the owner's script: state, prop, constant or function), data (the load result), shared.store, params, query, page.loading / page.error and the variable of an enclosing <for>. Properties work, so $items.length is fine; calls, indexes and operators are not.

The only operator is !, and only in <if>, <else-if>, :show and .class. Anything derived (a total, a label, an aria-* string) is a function in the script, const total = () => โ€ฆ, which is what every example below does.

Bindings: :attr, :aria-*, :data-*

:href, :title, :disabled or any other :attr sets the whole attribute: false, null and undefined remove it, true sets it empty. Toggle the switch: while the service is down the link has no href at all.

aria-* states need the strings 'true' / 'false', because boolean false removes the attribute. :data-tone is the hook for a style with many values: the component's CSS selects [data-tone="ok"] without touching classes. Only the bound form is allowed; a hand-written data-tone="ok" fails check with html/data-attribute.

routes/examples/syntax/_components/bindings/bindings.html

<script>  let online = false  const offline = () => !online  const pressed = () => (online ? 'true' : 'false')  const tone = () => (online ? 'ok' : 'down')  const heading = () => (online ? 'Operational' : 'Down')  const link = () => online && '#bindings'  const linkTitle = () => online && 'Jump to this example'  const linkLabel = () => (online ? 'Open status page' : 'No status page while down')  function toggle() {    online = !online  }</script><div>  <button type="button" class="bindings-switch" :aria-pressed="$pressed" @click="toggle">    <span class="bindings-knob" aria-hidden="true"></span>    <span>Service online</span>  </button>  <article class="bindings-card" :data-tone="$tone" aria-live="polite">    <p class="bindings-status">{$heading}</p>    <a class="bindings-link" :href="$link" :title="$linkTitle">{$linkLabel}</a>  </article>  <button type="button" class="btn btn-small" :disabled="$offline">Deploy</button></div><style>  [data-c="bindings"] {    display: grid;    justify-items: start;    gap: 1rem;    width: 100%;    max-width: 18rem;  }  .bindings-switch {    display: inline-flex;    align-items: center;    gap: 0.75rem;    color: var(--color-ink);    font-family: var(--font-mono);    font-size: 0.75rem;    cursor: pointer;  }  .bindings-knob {    position: relative;    width: 2.25rem;    height: 1.25rem;    border: 1px solid var(--color-line-strong);    background: var(--color-sunken);    transition: border-color 0.18s var(--ease-out);  }  .bindings-knob::after {    content: "";    position: absolute;    inset: 0.1875rem auto 0.1875rem 0.1875rem;    width: 0.75rem;    background: var(--color-muted);    transition: transform 0.18s var(--ease-out), background-color 0.18s var(--ease-out);  }  [aria-pressed="true"] .bindings-knob { border-color: var(--color-accent); }  [aria-pressed="true"] .bindings-knob::after {    transform: translateX(1rem);    background: var(--color-accent);  }  .bindings-card {    display: grid;    gap: 0.375rem;    width: 100%;    padding: 1rem;    border: 1px solid var(--color-line);    background: var(--color-surface);  }  .bindings-status {    min-height: 1lh;    font-family: var(--font-mono);    font-size: 1.125rem;  }  [data-tone="down"] .bindings-status { color: var(--color-danger-300); }  [data-tone="ok"] .bindings-status { color: var(--color-accent); }  .bindings-link {    min-height: 1lh;    color: var(--color-faint);    font-size: 0.875rem;  }  .bindings-link[href] {    color: var(--color-ink);    text-decoration: underline;    text-underline-offset: 0.25em;  }  @media (prefers-reduced-motion: reduce) {    .bindings-knob,    .bindings-knob::after { transition: none; }  }</style>

Live result

One let, online, drives text, href, title, disabled, aria-pressed and data-tone through derived functions.

Class toggles: .class and .class="!v"

.line-through="$done" adds the class while the value is truthy; .is-pending="!$done" does the opposite. The class must be a known utility or a class from the project's CSS, and variants work: .md:font-semibold only bolds from 48rem up. Static classes on the same element are left alone.

There is no :class and no {} inside class: both are check errors (html/class), because a computed class name could never be generated into the CSS. Write the static classes in class and toggle each optional one; for a value with many states, bind :data-tone and style the attribute, as the bindings example does.

routes/examples/syntax/_components/classes/classes.html

<script>  let done = false  const pressed = () => (done ? 'true' : 'false')  const buttonLabel = () => (done ? 'Reopen' : 'Mark as done')  function toggle() {    done = !done  }</script><div>  <p class="classes-task" .line-through="$done" .text-faint="$done" .is-pending="!$done" .md:font-semibold="$done">Ship the release notes</p>  <button type="button" class="btn btn-small" :aria-pressed="$pressed" @click="toggle">{$buttonLabel}</button></div><style>  [data-c="classes"] {    display: grid;    justify-items: start;    gap: 1rem;  }  .classes-task {    padding: 0.75rem 1rem;    border: 1px solid var(--color-line);    background: var(--color-surface);    transition: color 0.18s var(--ease-out), border-color 0.18s var(--ease-out);  }  .classes-task.is-pending { border-color: var(--color-accent); }  @media (prefers-reduced-motion: reduce) {    .classes-task { transition: none; }  }</style>

Live result

Ship the release notes

Four toggles on one paragraph, one of them negated and one behind the md: breakpoint.

:show hides, <if> creates

:show toggles the hidden attribute, so the element, its listeners and its input state stay in the DOM. <if> inserts and removes its content. An element with autofocus inside a block that was just inserted receives focus, so opening the right pane puts the caret in its input.

routes/examples/syntax/_components/visibility/visibility.html

<script>  let open = false  const expanded = () => (open ? 'true' : 'false')  const buttonLabel = () => (open ? 'Hide both' : 'Show both')  function toggle() {    open = !open  }</script><div>  <button type="button" class="btn btn-small" :aria-expanded="$expanded" aria-controls="visibility-note" @click="toggle">{$buttonLabel}</button>  <div class="visibility-panes">    <div class="visibility-pane">      <p class="label">:show</p>      <p id="visibility-note" class="visibility-box" :show="$open">Toggled by the hidden attribute; this node never leaves the DOM.</p>      <p class="visibility-empty" :show="!$open">nothing visible</p>    </div>    <div class="visibility-pane">      <p class="label">&lt;if&gt; + autofocus</p>      <if $open>        <label class="visibility-box">          <span>Created on open, focused:</span>          <input class="visibility-input" autofocus placeholder="Type here">        </label>      </if>      <else>        <p class="visibility-empty">not in the DOM</p>      </else>    </div>  </div></div><style>  [data-c="visibility"] {    display: grid;    justify-items: start;    gap: 1.25rem;    width: 100%;  }  .visibility-panes {    display: grid;    grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr));    gap: 1rem;    width: 100%;  }  .visibility-pane {    display: grid;    align-content: start;    gap: 0.5rem;  }  .visibility-box {    display: grid;    gap: 0.5rem;    min-height: 5.5rem;    padding: 0.75rem;    border: 1px solid var(--color-line);    background: var(--color-surface);    font-size: 0.875rem;  }  .visibility-empty {    display: grid;    place-items: center;    min-height: 5.5rem;    border: 1px dashed var(--color-line);    color: var(--color-faint);    font-family: var(--font-mono);    font-size: 0.75rem;  }  .visibility-input {    width: 100%;    padding: 0.375rem 0.5rem;    border: 1px solid var(--color-line-strong);    background: var(--color-sunken);    color: var(--color-ink);  }  .visibility-input::placeholder { color: var(--color-faint); }</style>

Live result

:show

nothing visible

<if> + autofocus

not in the DOM

The same flag drives both panes; inspect the DOM to see the difference.

Two-way binding with :model

:model works on input, select and textarea, and only with a $x or shared.x path. The value keeps its type: checkboxes are booleans, radios hold the value of the checked one, number and range give a number (or null when the field is empty), everything else a string. A prop cannot be the target (js/prop-write).

routes/examples/syntax/_components/model/model.html

<script>  let name = 'Ada'  let quantity = 2  let shipping = 'standard'  let size = 'm'  let gift = false  let note = ''  function readout() {    return Object.entries({ name, quantity, shipping, size, gift, note }).map(([key, value]) => ({      key,      shown: JSON.stringify(value),      kind: value === null ? 'null' : typeof value,    }))  }</script><form aria-label="Order options" notool>  <label class="model-field">    <span class="label">text</span>    <input class="model-input" :model="$name">  </label>  <label class="model-field">    <span class="label">number</span>    <input class="model-input" type="number" min="0" max="9" :model="$quantity">  </label>  <label class="model-field">    <span class="label">range</span>    <input class="model-range" type="range" min="0" max="9" :model="$quantity">  </label>  <label class="model-field">    <span class="label">select</span>    <select class="model-input" :model="$shipping">      <option value="standard">Standard</option>      <option value="express">Express</option>    </select>  </label>  <fieldset class="model-field">    <legend class="label">radio</legend>    <div class="model-row">      <label><input type="radio" name="model-size" value="s" :model="$size"> S</label>      <label><input type="radio" name="model-size" value="m" :model="$size"> M</label>      <label><input type="radio" name="model-size" value="l" :model="$size"> L</label>    </div>  </fieldset>  <label class="model-row">    <input type="checkbox" :model="$gift">    <span>checkbox: gift wrap</span>  </label>  <label class="model-field">    <span class="label">textarea</span>    <textarea class="model-input" rows="2" :model="$note"></textarea>  </label>  <output class="model-readout">    <for field in $readout key=field.key>      <span class="model-line"><span class="model-key">{field.key}</span><span>{field.shown}</span><span class="model-type">{field.kind}</span></span>    </for>  </output></form><style>  [data-c="model"] {    display: grid;    gap: 0.875rem;    width: 100%;    max-width: 20rem;    font-size: 0.875rem;  }  .model-field {    display: grid;    gap: 0.375rem;  }  .model-row {    display: flex;    align-items: center;    gap: 1rem;  }  .model-row label {    display: inline-flex;    align-items: center;    gap: 0.375rem;  }  .model-input {    width: 100%;    padding: 0.375rem 0.5rem;    border: 1px solid var(--color-line-strong);    background: var(--color-sunken);    color: var(--color-ink);  }  :is(.model-range, input[type="radio"], input[type="checkbox"]) { accent-color: var(--color-accent); }  .model-readout {    display: grid;    gap: 0.25rem;    padding: 0.75rem;    border: 1px solid var(--color-line);    background: var(--color-sunken);    font-family: var(--font-mono);    font-size: 0.75rem;  }  .model-line {    display: grid;    grid-template-columns: 5rem minmax(0, 1fr) auto;    gap: 0.5rem;  }  .model-line > * {    overflow: hidden;    white-space: nowrap;    text-overflow: ellipsis;  }  .model-key { color: var(--color-faint); }  .model-type { color: var(--color-accent); }</style>

Live result

radio
name"Ada"stringquantity2numbershipping"standard"stringsize"m"stringgiftfalsebooleannote""string
The readout shows each let and its JavaScript type. Clear the number field to get null.

Events: event by default, el on request

@keydown="pressed" calls the script's function with the DOM event, so function pressed(event) needs no wrapper. With parentheses the function receives only what is listed: @focusout="record('@focusout', 'field lost focus')", @change="toggle(item)", @dblclick="doubled(el, event)". el is the element that has the directive.

routes/examples/syntax/_components/events/events.html

<script>  const maxEntries = 5  let draft = ''  let counter = 0  let entries = []  function record(name, detail) {    counter += 1    entries = [{ id: counter, name, detail }, ...entries].slice(0, maxEntries)  }  function typed() {    record('@input', draft.length + ' chars')  }  function pressed(event) {    if (event.key !== 'Escape') return    draft = ''    record('@keydown', 'Escape cleared the field')  }  function doubled(el, event) {    record('@dblclick', 'el <' + el.localName + '>, target <' + event.target.localName + '>')  }  function save() {    record('@submit', 'saved "' + draft + '", no reload')    draft = ''  }</script><div>  <form class="events-form" notool @submit="save">    <input class="events-input" aria-label="Task title" placeholder="Type, press Esc or Enter" :model="$draft" @input="typed" @keydown="pressed" @focusout="record('@focusout', 'field lost focus')">    <button class="btn btn-small">Save</button>  </form>  <p class="events-target" @dblclick="doubled(el, event)">Double-click this line or <strong>this word</strong></p>  <ol class="events-log" aria-label="Event log" aria-live="polite">    <for entry in $entries key=entry.id>      <li class="events-entry"><span class="events-name">{entry.name}</span><span>{entry.detail}</span></li>    </for>    <empty>      <li class="events-entry events-idle">No events yet</li>    </empty>  </ol></div><style>  [data-c="events"] {    display: grid;    gap: 1rem;    width: 100%;    max-width: 20rem;  }  .events-form {    display: flex;    gap: 0.5rem;  }  .events-input {    flex: 1;    min-width: 0;    padding: 0.375rem 0.5rem;    border: 1px solid var(--color-line-strong);    background: var(--color-sunken);    color: var(--color-ink);    font-size: 0.875rem;  }  .events-input::placeholder { color: var(--color-faint); }  .events-target {    padding: 0.625rem 0.75rem;    border: 1px dashed var(--color-line-strong);    color: var(--color-muted);    font-size: 0.875rem;    cursor: pointer;    user-select: none;  }  .events-target strong { color: var(--color-ink); font-weight: 500; }  .events-log {    display: grid;    align-content: start;    gap: 0.25rem;    min-height: 8.5rem;    padding: 0.75rem;    border: 1px solid var(--color-line);    background: var(--color-sunken);    font-family: var(--font-mono);    font-size: 0.75rem;  }  .events-entry {    display: flex;    gap: 0.75rem;    color: var(--color-muted);  }  .events-name {    flex: none;    width: 5.5rem;    color: var(--color-accent);  }  .events-idle { color: var(--color-faint); }</style>

Live result

Double-click this line or this word

  1. No events yet
Every handler appends to the log; the newest event is on top.
  • An argument is a path (item, $draft, data.x), a string in quotes, a number, true, false, null, event or el. Expressions are a check error.
  • Double-click the bold word: event.target is the <strong>, el is still the <p>. Use el instead of an id lookup; event.currentTarget is the root the runtime listens on.
  • A store function is a handler too, with no wrapper in the script: @click="shared.cart.remove(line)" (Stores).
  • @submit calls preventDefault() for you, so the form never reloads the page.
  • The same function can be an action and a helper: record runs from @focusout and from the other functions.

Overlay shortcuts: @open and bare @close

@open="id" opens the overlay with that id and @close, written without a value, closes the overlay around it. The button's value becomes the result of confirm(id); the overlays section covers modal, alert and dropdown in depth.

routes/examples/syntax/_snippets/overlay-shortcut/usage.html

<p-overlay-shortcut></p-overlay-shortcut>

routes/examples/syntax/_components/overlay-shortcut/overlay-shortcut.html

<div>  <button type="button" class="btn" @open="syntax-shortcut">Open dialog</button>  <c-modal id="syntax-shortcut" title="Opened by @open">    <p class="text-muted">No action ran: the button named this overlay by id. Esc, the backdrop and Back close it too.</p>    <button slot="actions" type="button" class="btn btn-primary" @close value="ok">Close with @close</button>  </c-modal></div>

Live result

Opened by @open

No action ran: the button named this overlay by id. Esc, the backdrop and Back close it too.

No script in this component: both directives are handled by the runtime.

Conditions: <if>, <else-if>, <else>

The path in a block tag is unquoted: <if $loading>, <else-if $noOrders>. Any number of <else-if> may follow, and each one must come right after the closing tag of the previous branch. Every block holds exactly one root element, which carries the directives; the block tag itself takes none.

routes/examples/syntax/_components/conditions/conditions.html

<script>  const sampleOrders = [    { id: '#1042', total: '$18.00' },    { id: '#1043', total: '$64.50' },  ]  let mode = 'ready'  const modes = () => ['loading', 'error', 'empty', 'ready'].map(id => ({ id, pressed: id === mode ? 'true' : 'false' }))  const loading = () => mode === 'loading'  const failed = () => mode === 'error'  const orders = () => (mode === 'ready' ? sampleOrders : [])  const noOrders = () => orders().length === 0  function pick(id) {    mode = id  }</script><div>  <div class="conditions-modes" role="group" aria-label="Simulated state">    <for option in $modes key=option.id>      <button type="button" class="conditions-mode" :aria-pressed="option.pressed" @click="pick(option.id)">{option.id}</button>    </for>  </div>  <if $loading>    <div class="conditions-panel" aria-busy="true">      <span class="skeleton conditions-bar"></span>      <span class="skeleton conditions-bar conditions-short"></span>    </div>  </if>  <else-if $failed>    <p class="conditions-panel conditions-error" role="alert">Could not load the orders. Retry in a moment.</p>  </else-if>  <else-if $noOrders>    <p class="conditions-panel conditions-muted">No orders yet.</p>  </else-if>  <else>    <ul class="conditions-panel">      <for order in $orders key=order.id>        <li class="conditions-order"><span>{order.id}</span><span>{order.total}</span></li>      </for>    </ul>  </else></div><style>  [data-c="conditions"] {    display: grid;    gap: 1rem;    width: 100%;    max-width: 20rem;  }  .conditions-modes {    display: flex;    border: 1px solid var(--color-line-strong);  }  .conditions-mode {    flex: 1;    padding: 0.5rem 0.25rem;    color: var(--color-muted);    font-family: var(--font-mono);    font-size: 0.75rem;    cursor: pointer;  }  .conditions-mode + .conditions-mode { border-left: 1px solid var(--color-line-strong); }  .conditions-mode:hover { color: var(--color-ink); }  .conditions-mode[aria-pressed="true"] {    background: var(--color-accent);    color: var(--color-accent-ink);  }  .conditions-panel {    display: grid;    align-content: center;    gap: 0.5rem;    min-height: 5.5rem;    padding: 0.875rem 1rem;    border: 1px solid var(--color-line);    background: var(--color-surface);    font-size: 0.875rem;  }  .conditions-bar { height: 0.75rem; }  .conditions-short { width: 60%; }  .conditions-error { color: var(--color-danger-300); }  .conditions-muted { color: var(--color-faint); }  .conditions-order {    display: flex;    justify-content: space-between;    font-family: var(--font-mono);    font-size: 0.8125rem;    font-variant-numeric: tabular-nums;  }</style>

Live result

  • #1042$18.00
  • #1043$64.50
Pick a state: four branches, one rendered at a time. Each button passes its own id: pick(option.id).

Lists: <for> with key, and <empty>

<for item in group.items key=item.id> repeats its root element; the key is required, starts with the loop variable and must be unique (duplicates throw in dev). Updates diff by key. <empty> right after </for> renders when the list is empty.

Pass the item to the function: @change="toggle(item)", @click="clear(group)". State is a deep proxy, so item.done = !item.done and group.items = [] render without copying anything. A loop variable cannot shadow a root such as data or page.

routes/examples/syntax/_components/lists/lists.html

<script>  const startingGroups = () => [    { id: 'today', name: 'Today', items: [{ id: 'a', label: 'Review the PR', done: false }, { id: 'b', label: 'Write the changelog', done: false }] },    { id: 'later', name: 'Later', items: [{ id: 'c', label: 'Upgrade the runtime', done: false }] },  ]  let groups = startingGroups()  function toggle(item) {    item.done = !item.done  }  function clear(group) {    group.items = []  }  function reset() {    groups = startingGroups()  }</script><div>  <for group in $groups key=group.id>    <section class="lists-group" aria-label="{group.name}">      <div class="lists-head">        <h3 class="label">{group.name}</h3>        <button type="button" class="lists-clear" :show="group.items.length" @click="clear(group)">Clear</button>      </div>      <ul class="lists-items">        <for item in group.items key=item.id>          <li>            <label class="lists-item" .line-through="item.done" .text-faint="item.done"><input type="checkbox" :checked="item.done" @change="toggle(item)"> {item.label}</label>          </li>        </for>        <empty>          <li class="lists-empty">Empty group</li>        </empty>      </ul>    </section>  </for>  <button type="button" class="btn btn-small" @click="reset">Reset lists</button></div><style>  [data-c="lists"] {    display: grid;    justify-items: start;    gap: 1rem;    width: 100%;    max-width: 20rem;  }  .lists-group {    display: grid;    gap: 0.5rem;    width: 100%;  }  .lists-head {    display: flex;    align-items: center;    justify-content: space-between;  }  .lists-clear {    color: var(--color-muted);    font-family: var(--font-mono);    font-size: 0.75rem;    text-decoration: underline;    text-underline-offset: 0.3em;    cursor: pointer;  }  .lists-items {    display: grid;    border: 1px solid var(--color-line);    background: var(--color-surface);  }  .lists-items > li + li { border-top: 1px solid var(--color-line); }  .lists-item {    display: flex;    align-items: center;    gap: 0.625rem;    padding: 0.625rem 0.75rem;    font-size: 0.875rem;    cursor: pointer;  }  .lists-item:hover { background: var(--color-raised); }  .lists-item input { accent-color: var(--color-accent); }  .lists-empty {    padding: 0.625rem 0.75rem;    color: var(--color-faint);    font-family: var(--font-mono);    font-size: 0.75rem;  }</style>

Live result

Today

Later

Check an item; clear a group to see its empty branch.

Static props decide <if> at build time

In a component without a script, <if $icon> on a static prop is resolved by the compiler. The badge with icon ships the star inline and the other ships nothing, with no template and no runtime work. A bare attribute such as icon is true; icon="", icon="false" and a missing one are false.

routes/examples/syntax/_snippets/badge/usage.html

<p-badge label="New" icon></p-badge><p-badge label="Beta"></p-badge>

routes/examples/syntax/_components/badge/badge.html

<span>  <if $icon>    <svg class="badge-icon" viewBox="0 0 16 16" aria-hidden="true"><path d="M8 1.5l1.9 4.1 4.6.5-3.4 3.1 1 4.5L8 11.4l-4.1 2.3 1-4.5-3.4-3.1 4.6-.5z" fill="currentColor"></path></svg>  </if>  <span>{$label}</span></span><style>  [data-c="badge"] {    display: inline-flex;    align-items: center;    gap: 0.375rem;    padding: 0.25rem 0.625rem;    border: 1px solid var(--color-line-strong);    font-family: var(--font-mono);    font-size: 0.75rem;  }  .badge-icon {    width: 0.75rem;    height: 0.75rem;    color: var(--color-accent);  }</style>

Live result

New Beta
No script, and both branches settled in the prebuilt HTML.

What the compiler rejects

The list above is closed, so pragma check rejects what falls outside it, and every error names the fix:

  • The old API: :text (html/text-removed), export const state and actions, ctx.$, ctx.update and export function mount(ctx) (js/legacy-api).
  • Expressions in paths and in event arguments, {{ }} and ${ }, hand-written data-*, inline style and on*, :class, quoted block paths and a <for> without key.
  • Attributes from other frameworks, with the pragma form in the message: Vue's v-if, Alpine's x-show, Svelte's on:click, Angular's *ngIf, React's className.
  • Script mistakes that would show a stale value: data at the top level, a let derived from another let, a derived function used without () and $name in JS (State: script mistakes).

routes/examples/syntax/_snippets/rejected/wrong.html

<script>  let name = 'Ada'  let items = []  let tone = 'ok'  let open = false  const total = () => items.length  function add(amount) {    items.push(amount)  }</script><title>Wrong</title><h1 :text="$name">x</h1><p>{$items.length > 0}</p><p>{$name.toUpperCase()}</p><p data-text="$name">x</p><p style="color: red">x</p><button onclick="add()">Add</button><p :class="$tone">x</p><p>{{ $name }}</p><p>Total: ${$total}</p><button @click="add($total + 1)">Add</button><if test="$open"><p>x</p></if><for item in $items><p>{item}</p></for><p v-if="$open">x</p>

routes/examples/syntax/_snippets/rejected/ticker.js

export const state = ctx => ({  count: Number(ctx.$.start),  get label() { return this.count + ' ticks' },})export const actions = {  reset(ctx) { ctx.$.count = 0 },}export function mount(ctx) {  const timer = setInterval(() => ctx.update(current => { current.count += 1 }), 1000)  return () => clearInterval(timer)}

Live result

pragma check --strict

  • ticker.js:1 js/legacy-api old API: `export const state` โ†’ declare each value as a top-level `let` (`let count = 0`); props are `export let step = 1`
  • ticker.js:2 js/legacy-api old API: `ctx.$.x` โ†’ use the top-level `let x` or the prop `x` directly
  • ticker.js:6 js/legacy-api old API: `export const actions` โ†’ write top-level functions (`function add() {โ€ฆ}`) and call them from HTML (`@click="add"`, `@change="toggle(task)"`)
  • ticker.js:10 js/legacy-api old API: `export function mount(ctx)` โ†’ `function mount() { โ€ฆ; return cleanup }` without export; services come from `import { โ€ฆ } from 'pragma'`
  • ticker.js:11 js/legacy-api old API: `ctx.update(fn)` โ†’ assign the top-level `let` directly; renders are batched
  • wrong.html:13 html/text-removed `:text` was removed: write {$name} inside the element (e.g. <p>{$name}</p>)
  • wrong.html:14 html/invalid-path invalid path "$items.length > 0": use only root.a.b (no expressions, calls or indexes); move the logic into a function in <script> (`const total = () => โ€ฆ`) and use $total
  • wrong.html:15 html/invalid-path invalid path "$name.toUpperCase()": use only root.a.b (no expressions, calls or indexes); move the logic into a function in <script> (`const total = () => โ€ฆ`) and use $total
  • wrong.html:16 html/data-attribute `data-text` is internal; write `{path} inside the element`
  • wrong.html:17 html/style-inline the style attribute is not allowed; use classes
  • wrong.html:18 html/on-inline inline onclick is not allowed; use @<event>="action"
  • wrong.html:19 html/class :class is not allowed: write static classes in class="โ€ฆ" and toggle each one with .name="path" (e.g. .text-warning-700="$warn")
  • wrong.html:20 html/interpolation {{ }} is not pragma syntax: write {path} in text and attributes (e.g. <p>Hi {$name}</p>, alt="Photo of {p.name}"); inside <code> or <pre> it is shown as text
  • wrong.html:21 html/interpolation ${ } is not pragma syntax: write {path} in text and attributes; for a literal $ before a value write &#36;{path}
  • wrong.html:22 html/invalid-path @click: "add($total + 1)": argument `$total + 1` must be a path, a simple literal ('text', 2, true) or event; no expressions
  • wrong.html:23 html/block use <if path>, with the path unquoted (e.g. <if page.loading>, <if !$open>)
  • wrong.html:24 html/for-without-key <for> requires key=x.field
  • wrong.html:25 html/unknown-directive `v-if` is Vue syntax and does nothing in pragma; wrap the element in `<if path>โ€ฆ</if>`

24 error(s), 0 warning(s)

Real output for these two files, trimmed to one line per error; the full run reports 24 errors.