Locus now performs a lightweight lexical pass for UI blocks before structural transformation. This enables:
line:column
+ offset metadata on UI element nodes and attributes.The UI parser (parseUi
) pre-processes directive sugar ({#if}
, {#each}
, etc.) into temporary element tags, then performs a single pass building a raw tree. During this pass we record:
start
and end
byte offsets (UTF-16 indices) for elements and expression segments.loc
objects: { line, column, endLine, endColumn }
on element nodes plus loc
on attributes.A helper buildUiCodeFrame(filePath, loc)
(in src/cli/uiDiagnostics.ts
) produces a simple code frame highlighting the element or attribute span. This is intended for use by future validation passes and error reporters.
import { buildUiCodeFrame } from '../cli/uiDiagnostics';
// given a node with .loc
console.log(buildUiCodeFrame('MyPage.locus', node.loc));
Validation now issues warnings for:
onX
events (passes through but flagged).onclick
with a suggested canonical onClick
.bind:value
becomes internal bind$value
).You can experiment quickly:
echo '<Button onClick="{doThing}">Hi</Button>' | locus ui:ast
This prints the structured UI AST including location metadata.
Last updated: 2025-09-04