jukebox
All repositories: gitoria
298.0 KB
// The framework's server half — the SERVER REALM's entrypoint, and the EDGE// MODULE for the carriers the manifest declares.// Its jobs: answer a URL with the HTML of a constructed component (SSR), ship// the browser the client, the View tree and the state to continue from, carry// the boundary in both directions (a websocket on the same port, a POST for a// peer that has none), and run the server faces an inbound emit names.import { NativeWebSocketServer, Response, randomToken } from 'hl:http1'import HlwView from './view.hl'import HlwViewServer from './viewserver.hl'import HlwRouter from './router.hl'// Reachable for explicit browser projection and native baking; never constructed on the server.import HlwOffline from './offline.hl'import HlwUploads from './uploads.hl'import HlwSessions from './sessions.hl'import HlwSession from './session.hl'// the Style walk — named Css here because `Style` is a well-known MEMBER nameimport HlwCss from './css.hl'import HlwCompile from './compile.hl'import { readFile, exists, watch } from 'hl:fs'import { file, env, setEnv, args, writeStderr } from 'hl:proc'import { now } from 'hl:time'import { sha256, base64urlDecode, base64urlEncode, p256PublicKey } from 'hl:crypto'// the statics of push.hl that server.hl (the app's import of sendPush) and the app use are named here: a package// file's statics are live only for the names the framework's own import selectsimport { configure as configurePush, sendPush as pushSender } from './push.hl'import { newline, tab } from './view.hl'// #360: document language default; null leaves <html lang> absent.String lang = nullHybrid routes = [] // bound by `new WebFrameworkServer(routes = …)`// THE PROJECT'S STYLES FILE, declared by the app as a property of the framework:// `new WebFrameworkServer(…, styles = './styles.hl')`. A file of statics and one// `Style { }` root member (COMPONENTS §4) — the design tokens and the global// rules, under every component's own Style in the one stylesheet. null: none.styles = null // the app's styles file: the class it imported, or a path// WHO AN OUTWARD EVENT IS FOR (creator, 2026-09-12): per event, a function the app// declares — `audience = { postCreated = (p, session) => … }` — called for every// connection that has a listener for the event mounted, with the event's// arguments and that connection's session; a true answer sends the frame. An// event with no entry reaches the emitting connection only. Only the app knows// who is entitled; the face stays pure; the framework applies the answer.Hybrid audience = {}// THE SESSION STORE (the archive's manifest members, mission 252/255): nothing said →// `<project>/.sessions`; a path → that path; `false` → memory only. The three clocks// are seconds; null takes the layer's defaults (14 days valid, 15 min resident, sweep// every 5 min).// THE DEV WATCHER (the archive's `watch`): every save under the project arrives as an// event; a save that changes the analysis re-reads the graph, drops every cache and tells// every open tab to reload. Off by default — a deploy never re-analyses itself.Boolean minify = false // production: one-line HTML, compact JavaScript modulesBoolean watchMode = truelastChange = 0 // epoch ms of the last save acted on (the debounce)String | Boolean sessionDir = nullNumber sessionMaxAge = nullNumber sessionIdle = nullNumber sweepInterval = null// THE SESSION COOKIE'S NAME (ticket #10). Cookies ignore the port, so two apps on one// host that both answered `hlsid` overwrote each other's sessions; an app names its own.// null: `hlsid`.String sessionCookie = null// THE COOKIE'S `Secure` FLAG (ticket #27): true when the app is reached over https —// behind a TLS proxy the server itself speaks plain http and cannot tell, so the app// says so. The browser then never sends the session over plain http. null (W124): `Secure` when THE REQUEST// came over https (X-Forwarded-Proto: https from the proxy); true: always; false: never.Boolean sessionSecure = null// THE MOST ANONYMOUS SESSIONS KEPT (W124): a visitor gets a session (and a file) only when something is stored// in it; the ones nobody logged in to are capped, the oldest evicted first.Number sessionAnonMax = 10000Number sessionAnonKeep = 86400// THE COOKIE'S `Domain` (ticket #44): 'example.org' shares one session with every// <sub>.example.org, which a host-only cookie cannot. null: host-only, no attribute.String sessionDomain = null\* THE PORT: the app's own `--port=N` argument (hybriel hands every argumentafter the entry to the program, creator ruling 2026-09-27), else theconstructor's, else HL_PORT (hybriel resolves PORT and `.env` into it),else 8080. *\Number port = null// THE OFFLINE ALLOW-LIST (COMPONENTS §10, D38): the pages this app promises with the// network down, named as the route table names them — the imported class or a path// string. null: no service worker, no cache, no IndexedDB, nothing on the device.offline = null// THE OFFLINE FALLBACK PAGE (ticket #120): a data-free page — a route component with no// parameters, the class or its path string — the service worker keeps once, fetched with// NO credentials, and shows for any page it has nothing for while the network is down.// null: the "Unavailable offline" page, as before. Needs `offline`.offlineFallback = null// THE APP'S OWN FILES KEPT OFFLINE (ticket #170): a list of urls — each a path the app's// `file` routes answer (`/md-editor.js`, or one file under a directory route) — the worker// precaches at install and serves cache-first. Only the urls listed: a directory route is// never kept as a tree. Needs `offline`. null: none beyond the files a kept page's View// loads through a literal `<script src>` or `<link href>`.offlineFiles = null// WEB PUSH (ticket #173): the app's VAPID PUBLIC key, base64url (the 65-byte uncompressed P-256// point). Setting it serves the service worker — which then shows a pushed notification and// focuses the app on a click — and lets a component call `subscribePush()` (hl:web). null: no push.pushKey = null// …and the SERVER'S half: the VAPID PRIVATE key (base64url, the 32-byte P-256 scalar of `pushKey`) and the// contact `pushSubject` ('mailto:…' or 'https://…', the push service may write to it). Both set: the app can// `import { sendPush } from 'hl:web/push'` and send. A key that is not the private half of `pushKey` is refused at boot.pushPrivateKey = nullpushSubject = null// THE DEAD-SOCKET CLOCK (COMPONENTS §10), in seconds. The browser pings every `pingEvery`,// and a socket whose pong has not come back within `pongWithin` is taken for dead: it is// closed, and the reconnect and the queue's replay start. A network that drops without a// close frame is noticed within pingEvery + pongWithin (35 s by default). null: 25 and 10.Number pingEvery = nullNumber pongWithin = null// AN UPLOAD THAT GOES SILENT — no progress, no answer — is read as dropped after this// many seconds (COMPONENTS §10, an emit's file). null: 15.Number uploadStall = null// THE LARGEST FILE AN EMIT MAY CARRY (ticket #94), in bytes: a bigger one is refused// at its first request, and the emit ends with that error. 1 GiB.Number uploadMax = 67108864// THE UPLOAD BUDGETS (W115): the bytes announced by the unfinished uploads of ONE session,// and of ALL sessions together (a part is held in memory until its emit claims it). 256 MiB, 1 GiB.Number uploadSessionMax = 268435456Number uploadHeldMax = 1073741824// THE LARGEST BODY `POST /__hl/emit` takes, in bytes (W115): a bigger one is answered 413. 16 MiB.// (hl:http1 reads a request's body whole before hl:web sees it, so this refuses the answer, not the read.)Number emitMax = 16777216// ONE PART OF AN UPLOAD, at most (the client half sends 1 MiB): 8 MiB.Number uploadPartMax = 8388608// THE HEADERS EVERY ANSWER CARRIES (W115, COMPONENTS §7): the safe defaults are nosniff,// Referrer-Policy strict-origin-when-cross-origin, X-Frame-Options SAMEORIGIN and a CSP of// `frame-ancestors 'self'`. `pageHeaders = { 'Content-Security-Policy' = "…" }` adds to or replaces// them on every answer (a header set to null is removed); a route's own header wins over both.Hybrid pageHeaders = {}// ORIGINS BESIDES THE REQUEST'S OWN HOST that may call `/__hl/emit`, `/__hl/upload` and open the// socket (W115): `['https://app.example.org']`. A request whose Origin is another is refused 403.trustedOrigins = []// THE PUSH LOG (ticket #143). A push is addressed to the TAB, not to its socket: each tab// keeps the last `pushKept` pushes it was sent (and no more than `pushKeptBytes` of them),// numbered, and a tab whose socket comes back gets what it missed again, in order. A tab// whose socket left is kept `tabKept` seconds, and pushed to and logged meanwhile; a gap// longer than the log (or a server restart) resyncs the tab's server-derived state instead.// THE BYTES BOUND IS THE ONE THAT GOVERNS (ticket #160): a push is small (a streamed delta is some// 150 bytes), and a count of 500 ran out within a 15-second gap on a server streaming several// chats to the tab while 1 MiB was far off. The count is the guard for the degenerate case only.Number pushKept = 10000Number pushKeptBytes = 1048576Number tabKept = 600// THE PUSHES SINCE A RENDER (W181): a page's tab does not exist until its first hello, so every fan-out push is also// kept here, numbered, for `recentKept` seconds (and within `pushKeptBytes`). The seed names the number the render stood at// (`pushed`), and the first hello is replayed what was sent since, exactly like a reconnect. Older than that, it is not.Number recentKept = 30recent = []recentBytes = 0pushCount = 0String host = null // the interface to bind; null → HL_HOST/HOST, the manifest's `host`, 0.0.0.0// THE ONE RUNTIME URL, and the reason it is a member and not a literal in two// places: a module's `import … from "./hl-runtime.js"` resolves against the// MODULE's own url, so a server answering modules at two directory depths hands// the browser two runtime urls — two ES-module instances, two `globalEvents`// buses, two `__hlRealm` variables, and a crossing emit announced on a bus the// edge module never taps. Every module this server compiles is handed this one// specifier (hlJs's third argument).// THE DIRECTORY THE FRAMEWORK ANSWERS FROM, and the reason it is its own member:// a package's browser half is served BESIDE THE RUNTIME, and the compiler derives// that url from the runtime's own (`js_module.zig browserHalfUrl`:// `<dirname(runtime)>/<pkg>/client.js`). Two sides deriving one url from one// directory is what keeps the module's `import` and this server's route table// from drifting apart.static halfDir = '/__hl'// Browser keys are module paths without the leading slash. Outside graph keys are// absolute disk paths: only their opaque module key crosses the boundary. This ONE// mapping also supplies imports, live routes and the native bake.static graphModuleKey = (moduleKey) => {if (moduleKey.startsWith('/')) { return halfDir.slice(1) + '/modules/' + sha256(moduleKey) + '.hl' }return moduleKey}static graphModulePath = (moduleKey) => { return '/' + graphModuleKey(moduleKey) }// The inverse is a lookup in this generation's graph, never a path decoded from a// browser's input. Internal absolute keys are not accepted on the wire.browserKeys = nullgraphKeyOf(key) {if (key == null || key.startsWith('/')) { return null }if (graph.files[key] != null) { return key }if (browserKeys == null) {out = {}for (k of graph.files.keys()) { if (k.startsWith('/')) { out[graphModuleKey(k)] = k } }browserKeys = out}return browserKeys[key]}graphKeysOf(keys) {if (keys == null) { return null }out = []for (key of keys) {internal = graphKeyOf(key)if (internal != null) { out.push(internal) }}return out}graphParamsOf(params) {if (params == null) { return null }out = {}for (key of params.keys()) {internal = graphKeyOf(key)if (internal != null) { out[internal] = params[key] }}return out}static runtimeUrl = halfDir + '/hl-runtime.js'clientUrl = halfUrl('web')styleUrl = halfDir + '/app.css'// THE BUILD'S VERSION IS IN EVERY URL THE BROWSER CACHES (after ticket #82): the// runtime, the package halves, the component modules and the stylesheet were served// at fixed urls, and a browser or Cloudflare kept the old client against a new// deploy's pages. Each is now asked for as `<url>?v=<hash>`, the hash of everything// this build serves, and answered with a year's `immutable` caching — a new build is// a new url. The modules are COMPILED against this mark and it is replaced with the// hash when they are served: the hash is of the compiled texts, so it cannot be in// them while they are compiled, and a binary's baked modules carry the mark too (the// one form both paths share). The route patterns stay the bare paths.static buildMark = '?v=__hlbuild__'static runtimeSpec = runtimeUrl + buildMark// the web app manifest and the service worker's entry script (COMPONENTS §10)static manifestUrl = halfDir + '/manifest.webmanifest'static workerUrl = halfDir + '/sw.js'// THE FRAMEWORK'S OWN DEFAULT LOOK for the two waiting marks (#434, #435), first in the sheet and all inside `:where()` (specificity 0),// so any rule of the app's Style wins whatever its order. Nothing shows for the first 300 ms (a transition delay, no timer).// `<html data-hl-busy>` a navigation or an emit answer is open: a thin indeterminate bar (html::after) after 300 ms// `aria-busy="true"` + `data-hl-waiting` on a button whose handler's emit has no answer yet: dimmed, cursor progress after 300 ms// An app restyles `html[data-hl-busy]::after` / `button[aria-busy="true"]`, hides the bar with `html::after { display = 'none' }`,// and keeps one button quiet with the attribute `data-hl-quiet`.static busyCss = ':where(html)::after{content:"";position:fixed;z-index:2147483647;top:0;left:0;width:100%;height:3px;pointer-events:none;opacity:0;background:currentColor;transform-origin:0 50%;transform:scaleX(0)}' +':where(html[data-hl-busy])::after{opacity:.7;transition:opacity .1s 300ms;animation:hl-busy 1.4s ease-in-out infinite}' +'@keyframes hl-busy{0%{transform:translateX(-100%) scaleX(.3)}50%{transform:translateX(30%) scaleX(.6)}100%{transform:translateX(100%) scaleX(.3)}}' +':where(button[aria-busy="true"],input[aria-busy="true"],[role=button][aria-busy="true"]){opacity:.6;cursor:progress;transition:opacity .15s 300ms,cursor 0s 300ms;transition-behavior:allow-discrete}' +'@media (prefers-reduced-motion:reduce){:where(html[data-hl-busy])::after{animation:none;transform:none;opacity:.35}}'// TEST-ONLY CONSTRUCTION COUNTER (mission 343, W133). Only with HL_WEB_COUNT=1: `construct` counts every server// construction by component file, and GET /__hl/constructs answers the counts. Without the flag nothing is// counted and the route does not exist.countConstructs = env('HL_WEB_COUNT') == '1'constructTotal = { n = 0 }constructByFile = {}// W159: the same switch also counts page builds (`mounts`), level renders (`renderOf`), documents and resyncs, as `calls`countCalls = {}tally(name) {if (countConstructs) { countCalls[name] = (countCalls[name] == null ? 0 : countCalls[name]) + 1 }return null}// THE FRAMEWORK'S OWN URLS ARE ROUTES (creator: "just use routes"), appended to// the app's table with `routes[] = …` — the append that takes on a caller's// pinned argument during construction, where `routes = routes + […]` is dropped.// Three of them here — the runtime, the REST carrier and the app's one// stylesheet — and then one per PACKAGE BROWSER HALF the app's graph holds,// appended below where the graph is known. There is no catch-all that compiles// any graph file a url names.routes[] = { pattern = runtimeUrl framework = true function = (route, req) => {return new Response(runtime, { headers = cached(req, 'text/javascript; charset=utf-8') })} }// THE REST CARRIER, the same emit/ack pair for a peer that cannot hold a socket// (SPEC: `POST /__hl/emit`).// ITS SESSION IS THE COOKIE'S (creator, 2026-09-14): this is an HTTP request like// the page request, so it resolves the SAME session the page route would for that// cookie — a `session.user` a face writes here is what the next document reads.// Before this the face was handed null and a login over the fallback was lost.// AN OUTWARD EMIT RAISED UNDER IT RIDES BACK IN THE ANSWER: there is no// connection to push to, so the frames a face raised for the CALLER are// collected while it runs and shipped in the ack as `emits`, which the client// half delivers before it resolves the emit. The audience fan-out to the other// connections of that user is the same walk it always was.routes[] = { pattern = '/__hl/emit' framework = true function = (route, req) => {if (req.method != 'POST') { return notFound(req.path) }if (crossSite(req.headers)) { return refused(403, 'cross-site request refused') }if (req.body != null && req.body.length > emitMax) { return refused(413, 'the emit is longer than ' + emitMax + ' bytes (`emitMax`)') }// NO COOKIE, NO SESSION (W124): a face that stores something in the session it was handed makes one,// `inbound` leaves it in `postAdopted`, and the answer sets the cookielet s = sessions.resolve(req.headers['cookie'] != null ? req.headers['cookie'] : req.headers['Cookie'])let idBefore = s != null ? s.id : null// the session travels in a MEMBER, not an argument: a call argument is a copy,// an instance inside it included, and a copied session loses the face's writepostSession = spostHost = hostOf(req.headers['host'])postHeaders = requestHeaders(req.headers)postReq = requestInfo(req.headers, req.remoteAddress, req.secure)postAdopted = nulllet res = new Response(inbound(null, JSON.parse(req.body)), { headers = { 'Content-Type' = 'application/json; charset=utf-8' } })// the session a face made (W124), or the one a face's `session.rotate()` moved to a new id (W120): this answer carries the cookieif (postAdopted != null) { res.headers['Set-Cookie'] = sessions.cookieHeader(postAdopted.id, isHttps(req.headers, req.secure)) } else if (s != null && s.id != idBefore) { res.headers['Set-Cookie'] = sessions.cookieHeader(s.id, isHttps(req.headers, req.secure)) }// W137: several cookies of the session's name: the answer re-issues the chosen one and expires the host-only straylet fx = sessions.repair(req.headers['cookie'] != null ? req.headers['cookie'] : req.headers['Cookie'], s, isHttps(req.headers, req.secure))for (k of fx.keys()) { if (res.headers[k] == null) { res.headers[k] = fx[k] } }postAdopted = nullpostReq = nullreturn res} }// THE SOCKET CARRIER'S HALF OF `session.rotate()` (W120): a frame cannot set a cookie, so the server pushed the// tab `{ t: 'rotate', token }` and the client half POSTs it here. Origin-checked, authenticated twice — by the// token only that socket was given (one-shot) and by the cookie it still holds (the OLD id the rotation// recorded) — and the answer carries the Set-Cookie of the new id. A planted id has no token: nothing to claim.routes[] = { pattern = '/__hl/rotate' framework = true function = (route, req) => {if (req.method != 'POST') { return notFound(req.path) }if (crossSite(req.headers)) { return refused(403, 'cross-site request refused') }let sent = req.body != null && req.body != '' ? JSON.parse(req.body) : nulllet token = sent != null ? sent.token : nulllet rec = token != null ? pendingRotate['r' + token] : nulllet cks = sessions.cookieValues(req.headers['cookie'] != null ? req.headers['cookie'] : req.headers['Cookie'])if (rec == null || !cks.includes(rec.old) || now() - rec.at > 300000) { return refused(403, 'no rotation to claim') }pendingRotate['r' + token] = nulllet res = new Response('', { status = 204 headers = { 'Cache-Control' = 'no-store' } })res.headers['Set-Cookie'] = sessions.cookieHeader(rec.id, isHttps(req.headers, req.secure))return res} }// A FILE IN AN EMIT TRAVELS OVER HTTP (ticket #94, creator 2026-09-25): the client half// sends each file of an `emit server …` here, in parts, before the emit itself; the emit's// frame then names the upload, and `inbound` hands the face the file in its place.// POST /__hl/upload { name, type, size, q, n } → { id, have } (an upload; see uploadRequest)// POST /__hl/upload?id=&at= one part, raw → { have } (appended when `at` is what arrived so far)// GET /__hl/upload?id= → { have } (after a dropped connection)// An upload belongs to the session of the cookie that started it, and only an emit// of that session can claim it. A part cut short by a dropped connection keeps what// arrived; the client asks for `have` and goes on from there.routes[] = { pattern = '/__hl/upload' framework = true function = (route, req) => {if (crossSite(req.headers)) { return refused(403, 'cross-site request refused') }// W124: sessions are lazy (a page mints none), so the START of an upload is what makes one for a// visitor with no cookie; the answer sets it. A part or a question about `id` needs the session// that started it. The caps (uploadMax, uploadSessionMax, uploadHeldMax) still hold the memory.let s = sessions.resolve(req.headers['cookie'] != null ? req.headers['cookie'] : req.headers['Cookie'])if (s == null && req.query != null && req.query.id != null) { return uploadAnswer(404, { error = 'no upload ' + req.query.id + ' in this session' }) }let made = s == nullif (made) {if (req.method != 'POST') { return notFound(req.path) }s = sessions.fresh()}postAdopted = nulllet out = uploadRequest(&s, req)// a visitor whose start was refused (too big, bad body) keeps no session: `uploadRequest` adopts it// only when the upload is acceptedif (postAdopted != null) { out.headers['Set-Cookie'] = sessions.cookieHeader(postAdopted.id, isHttps(req.headers, req.secure)) }// W137: several cookies of the session's name: re-issue the chosen session's id, expire the host-only straylet fx = made ? sessions.strays(req.headers['cookie'] != null ? req.headers['cookie'] : req.headers['Cookie'], isHttps(req.headers, req.secure)) : sessions.repair(req.headers['cookie'] != null ? req.headers['cookie'] : req.headers['Cookie'], s, isHttps(req.headers, req.secure))for (k of fx.keys()) { if (out.headers[k] == null) { out.headers[k] = fx[k] } }postAdopted = nullreturn out} }// A SESSION MADE OVER THE SOCKET GETS ITS COOKIE HERE (W124): a socket cannot set one, so the ack of the// face that made the session carries a one-time token and the page POSTs it here; the answer sets the cookie.routes[] = { pattern = '/__hl/adopt' framework = true function = (route, req) => {if (req.method != 'POST') { return notFound(req.path) }if (crossSite(req.headers)) { return refused(403, 'cross-site request refused') }let t = req.query != null ? req.query.t : nulllet a = t != null ? adoptTokens[t] : nullif (a == null || now() - a.at > 60000) { return refused(404, 'no such token') }adoptTokens[t] = nulllet res = new Response('', { status = 204 headers = { 'Cache-Control' = 'no-store' 'Set-Cookie' = sessions.cookieHeader(a.sid, isHttps(req.headers, req.secure)) } })// W137: the new cookie must be the only one of its name: a host-only stray is expiredlet fx = sessions.strays(req.headers['cookie'] != null ? req.headers['cookie'] : req.headers['Cookie'], isHttps(req.headers, req.secure))for (k of fx.keys()) { res.headers[k] = fx[k] }return res} }if (countConstructs) {routes[] = { pattern = '/__hl/constructs' framework = true function = (route, req) => {return new Response(JSON.stringify({ total = constructTotal.n; byFile = constructByFile; calls = countCalls; }), { headers = { 'Content-Type' = 'application/json; charset=utf-8' 'Cache-Control' = 'no-store' } })} }}// THE SERVER IS UP (ticket #153): an empty answer the client half asks for while its socket// waits to reconnect, so a tab is back within about a second of a restarted server listeningroutes[] = { pattern = '/__hl/up' framework = true function = (route, req) => {return new Response('', { status = 204 headers = { 'Cache-Control' = 'no-store' } })} }// THE APP'S ONE STYLESHEET — the `styles` file's rules and every mounted// component's `Style { }`, walked in style.hl and cached after the first ask.routes[] = { pattern = styleUrl framework = true function = (route, req) => {return new Response(stylesheet(), { headers = cached(req, 'text/css; charset=utf-8') })} }// THE COMPONENT MODULES ARE ROUTES TOO — the framework's, not the app's: one per// file a page route mounts and per wrapper above it (the graph's `parent`// chain), served at the file's own `.hl` url as the browser's projection. A// browser executes a module by its MIME type, so `text/javascript` at// `/components/home.hl` is a module, and the url is the path the author wrote.// Nothing else is served as a module: a file no page route reaches has no url.// THE LANGUAGE GRAPH, AND THE REALMS ARE THIS PACKAGE'S (creator, 2026-09-12: "the project.hl// defines no realms so the framework just fills them itself"). This file is the server// realm's entrypoint, client.hl beside it the browser's; the app reaches both by// importing hl:web, and the graph follows that reference into the package.graph = hlProject(realms = {server = { entrypoint = './WebFramework.hl' }client = { entrypoint = './client.hl' }}transports = [['websocket' 'client' 'server']['websocket' 'server' 'client']['rest' 'client' 'server']])gen = graph.analysisGen // the syntax reflection's handle: the routes below read Views// TWO WEB FRAMEWORKS IN ONE APP IS NOT AN APP (creator, 15 Sep: project.hl switched// to the other framework the repo had then while styles.hl still said 'hl:web/css').// Both packages load, both `on server page` faces answer the same navigation, and// the second answers on a blank instance — a NotCallable deep inside the other framework's dispatch, which// says nothing about the two import rows that caused it. So it is refused HERE,// before anything is served, naming both rows.oneFrameworkOnly()// A VALUE-FORM EMIT HAS ONE ANSWERER (SPEC "An emit ANSWERS", ticket #20): checked here,// before anything is served, because the wire does not say which form an emit wasoneAnswererEach()// THE APP'S SETTINGS come from the file that constructed this one when they were not// passed (the archive's `configure()`): `styles`, `audience`, `sessionDir`, the clocks,// `watchMode`, `minify`, `port`cfg = hlConstructor()if (cfg != null) {if (lang == null && cfg.lang != null) { lang = cfg.lang }if (styles == null && cfg.styles != null) { styles = cfg.styles }if (cfg.audience != null && audience.keys().length == 0) { audience = cfg.audience }if (sessionDir == null && cfg.sessionDir != null) { sessionDir = cfg.sessionDir }if (sessionMaxAge == null && cfg.sessionMaxAge != null) { sessionMaxAge = cfg.sessionMaxAge }if (sessionIdle == null && cfg.sessionIdle != null) { sessionIdle = cfg.sessionIdle }if (sweepInterval == null && cfg.sweepInterval != null) { sweepInterval = cfg.sweepInterval }if (sessionCookie == null && cfg.sessionCookie != null) { sessionCookie = cfg.sessionCookie }if (sessionSecure == null && cfg.sessionSecure != null) { sessionSecure = cfg.sessionSecure }if (cfg.sessionAnonMax != null) { sessionAnonMax = cfg.sessionAnonMax }if (cfg.sessionAnonKeep != null) { sessionAnonKeep = cfg.sessionAnonKeep }if (sessionDomain == null && cfg.sessionDomain != null) { sessionDomain = cfg.sessionDomain }if (cfg.watchMode != null) { watchMode = cfg.watchMode }if (cfg.minify != null) { minify = cfg.minify }if (cfg.port != null) { port = cfg.port }if (offline == null && cfg.offline != null) { offline = cfg.offline }if (offlineFallback == null && cfg.offlineFallback != null) { offlineFallback = cfg.offlineFallback }if (offlineFiles == null && cfg.offlineFiles != null) { offlineFiles = cfg.offlineFiles }if (pushKey == null && cfg.pushKey != null) { pushKey = cfg.pushKey }if (pushPrivateKey == null && cfg.pushPrivateKey != null) { pushPrivateKey = cfg.pushPrivateKey }if (pushSubject == null && cfg.pushSubject != null) { pushSubject = cfg.pushSubject }if (pingEvery == null && cfg.pingEvery != null) { pingEvery = cfg.pingEvery }if (pongWithin == null && cfg.pongWithin != null) { pongWithin = cfg.pongWithin }if (uploadStall == null && cfg.uploadStall != null) { uploadStall = cfg.uploadStall }if (cfg.uploadMax != null) { uploadMax = cfg.uploadMax }if (cfg.uploadSessionMax != null) { uploadSessionMax = cfg.uploadSessionMax }if (cfg.uploadHeldMax != null) { uploadHeldMax = cfg.uploadHeldMax }if (cfg.emitMax != null) { emitMax = cfg.emitMax }if (cfg.pageHeaders != null && pageHeaders.keys().length == 0) { pageHeaders = cfg.pageHeaders }if (cfg.trustedOrigins != null && trustedOrigins.length == 0) { trustedOrigins = cfg.trustedOrigins }if (cfg.pushKept != null) { pushKept = cfg.pushKept }if (cfg.pushKeptBytes != null) { pushKeptBytes = cfg.pushKeptBytes }if (cfg.tabKept != null) { tabKept = cfg.tabKept }if (cfg.recentKept != null) { recentKept = cfg.recentKept }}// MISSION 511: `import { a, b } from './counter.hl'` of an app file (not a package's): the statics it takes live ONCE, in that// file's own module, which every importing module imports. A static function so the build and the boot agree.// The app's own entry (the manifest, which builds the server) is never one: it is no browser module.// MISSION 516: and not one the browser module leaves out: the graph says `unreadIn` for the realms whose module reads none of the// names (they are used only in a `Style {}` or in handlers of another realm), and that file is no module of the page then.static isBracedFileImport = (imp, entryKey, realm) => {if (imp.unreadIn != null && imp.unreadIn.includes(realm)) { return false }return imp.key != entryKey && imp.default == null && imp.key != null && !imp.key.startsWith('hl:') && imp.key.endsWith('.hl') && imp.names != null && imp.names.length > 0}// does the file at `key` declare a View? (a component, as opposed to a plain class)static hasViewMember = (gen, key) => {for (m of hlMembers(gen, key)) {if (m.name == 'View') { return true }}return false}// Every statically imported component can be rendered by a function route's server.page call.static componentImports = (&graph) => {out = []for (key of graph.files.keys()) {for (imp of graph.files[key].imports) {if (imp.default != null && imp.key != null && graph.files[imp.key] != null && hasViewMember(graph.analysisGen, imp.key) && !out.includes(imp.key)) { out.push(imp.key) }}}return out}served = {}mounted = []for (r of routes) { if (r.component != null) { mounted[] = keyOf(r.component) } }// Function routes may import their pages through helpers (#358), not just the manifest (#249).// Use the same project import closure for CSS, live modules and the static module map.for (ck of componentImports(&graph)) {if (!mounted.includes(ck)) { mounted[] = ck }}for (k of mounted) {let key = k// a file the graph does not hold is refused at its route row, below (servedKeys// → routeComponentKey: this walk reads the evaluated table, which has no lines)if (graph.files[key] == null) { key = null }while (key != null) {serveComponent(key)let child = keykey = graph.files[key].parent// A PARENT IS A COMPONENT (COMPONENTS §5): one without a View wraps nothing, and// every page under it answered a 500 while the boot said nothing (322 row 13)if (key != null && viewHandle(key) == 0) {hlError("hl:web: the `parent` clause of " + child + " names " + key + ", which declares no View: a parent is a component whose View places `slot` where the page renders")}}}// EVERY PACKAGE'S BROWSER HALF IS SERVED, BY ONE RULE. A package whose browser// side is written in this language ships it as `client.hl` beside its// plugin.json; the compiler compiles it like any other file and writes the// importing module `import { … } from "<halfDir>/<pkg>/client.js"`// (js_module.zig browserHalf / browserHalfUrl). Something has to answer that url,// and this is it — for EVERY such package the graph holds, because the rule// belongs to the language and not to one package. hl:web's own half is the first// case of it and no longer a hard-coded route of its own; hl:dnd is the second.//// The graph is the whole guard: a key is here only because the entry's closure// REACHED that package's half through an import, which is the same reason a// component has a module url. A package nothing imports is served nothing.for (gk of graph.files.keys()) {if (gk.startsWith('hl:') && gk.endsWith('/client.hl')) { serveHalf(gk) }}// ---- INSTALLABLE, AND OFFLINE (COMPONENTS §10, tickets #95–#97) ------------------// Two declarations in the app's manifest, and nothing written by hand in the app:// · `appIcons` (with `appTitle`, and optionally `appShortName`, `appThemeColor`,// `appBackgroundColor`, `appManifest`) makes the app INSTALLABLE — the web app// manifest below, linked from every page's head with its apple-touch-icon;// · `offline = [ … ]` makes the pages it names work OFFLINE — the service worker// (worker.hl) that keeps the shell and those pages, and in the client half the// IndexedDB copy of their state and the queue of the emits they make.// An app that declares neither is served nothing of either.routes[] = { pattern = '/__hl/uploads.js' framework = true function = (route, req) => { return serveHl('hl:web/uploads.hl', req) } }offlineKeys = offlinePages()if (offlineKeys != null) {routes[] = { pattern = '/__hl/offline.js' framework = true function = (route, req) => { return serveHl('hl:web/offline.hl', req) } }}fallbackPattern = offlineFallbackPattern()dataFreeKeys = dataFreePages()queueEvents = offlineKeys != null ? queueable() : []if (installable()) {routes[] = { pattern = manifestUrl framework = true function = (route, req) => {return new Response(JSON.stringify(webManifest()), { headers = { 'Content-Type' = 'application/manifest+json; charset=utf-8' 'Cache-Control' = 'no-cache' } })} }}if (pushKey != null && hlTypeName(pushKey) != 'String') { refuseAtSetting('pushKey', 'hl:web: pushKey is the VAPID public key as a base64url string, and this one is a ' + hlTypeName(pushKey)) }if (pushPrivateKey != null || pushSubject != null) {if (pushKey == null || pushPrivateKey == null || pushSubject == null) { refuseAtSetting('pushPrivateKey', 'hl:web: sending a push needs pushKey, pushPrivateKey and pushSubject together') }if (hlTypeName(pushPrivateKey) != 'String' || hlTypeName(pushSubject) != 'String') { refuseAtSetting('pushPrivateKey', 'hl:web: pushPrivateKey is a base64url string and pushSubject a string (mailto:… or https://…)') }if (!pushSubject.startsWith('mailto:') && !pushSubject.startsWith('https://')) { refuseAtSetting('pushSubject', 'hl:web: pushSubject is a mailto: or https:// contact, and this one is ' + pushSubject) }let vapidPriv = base64urlDecode(pushPrivateKey)let vapidPub = vapidPriv != null && vapidPriv.length == 32 ? p256PublicKey(vapidPriv) : nullif (vapidPub == null || base64urlEncode(vapidPub) != pushKey) { refuseAtSetting('pushPrivateKey', 'hl:web: pushPrivateKey is not the private half of pushKey (32 bytes, base64url)') }configurePush(pushKey, vapidPriv, pushSubject)}if (offlineKeys != null || pushKey != null) {// the ENTRY SCRIPT is served at the framework's directory, and its scope is the// whole app: `Service-Worker-Allowed` is what lets a script under /__hl/ say soroutes[] = { pattern = workerUrl framework = true function = (route, req) => {return new Response(workerEntry(), { headers = { 'Content-Type' = 'text/javascript; charset=utf-8' 'Cache-Control' = 'no-cache' 'Service-Worker-Allowed' = '/' } })} }routes[] = { pattern = halfDir + '/web/worker.js' framework = true function = (route, req) => {return new Response(workerModule(), { headers = cached(req, 'text/javascript; charset=utf-8') })} }}// ---- WHAT THIS APP SERVES, OFF THE ANALYSIS ALONE (mission 315) ----------------// These four are STATIC, so they answer with no instance and without constructing// anything: the compiler evaluates `servedModulesOf(&graph)` at BUILD time to bake// each module's text, and this file's own root uses the very same functions at// boot. One definition, two callers — a second derivation would drift, and a// compiled binary would then serve text generated against different urls.//// The seed is the entry's route table AS WRITTEN, read through `hlSyntax`, not// the evaluated `routes` member: evaluating it means constructing the app, and// constructing this class binds a socket. The graph carries the entry's record// since 2026-09-16, which is what makes that readable at all.// A ROUTE'S COMPONENT IS A PAGE: a file without a View answered every request with a 500// ("declares no View", raised without a span) while the boot said nothing (mission 322// row 13). Refused at the row instead.static routePage = (gen, entryKey, valueNode, key) => {if (!hasViewMember(gen, key)) { hlSourceError(gen, entryKey, valueNode, key + " declares no View, so it is no page: a route's component is a file whose View renders") }return key}// The key a route row's `component` names: an imported class, or a path string.// Anything else is a located refusal AT THE ROW — never silently unserved.static routeComponentKey = (&graph, gen, entryKey, imports, valueNode) => {let v = hlSyntax(gen, entryKey, valueNode)if (v == null) { return null }if (v.tag == 'literal' && v.kind == 'string') {let t = v.textlet k = t.startsWith('./') ? t.slice(2) : t// A PATH NO FILE OF THE APP IMPORTS IS NOT IN THE GRAPH: the analysis never read// it, so nothing can be served for it — refused here, at the row, instead of a// null deep in the framework once the server is already up (STATUS §2 item 0)if (graph.files[k] == null) { hlSourceError(gen, entryKey, valueNode, "the app never imports " + t + ", so the analysis never read it and the app would serve no module for it: import it in this file (`import Page from '" + t + "'`) and write `component = Page`") }return routePage(gen, entryKey, valueNode, k)}if (v.tag == 'identifier') {for (imp of imports) {if (imp.default == v.name && imp.key != null) { return routePage(gen, entryKey, valueNode, imp.key) }}}hlSourceError(gen, entryKey, valueNode, "a route's component must be an imported component class or a path string — this one the analysis cannot resolve to a file, so the app would serve no module for it")return null}// `key` and every component it composes, once each — the same walk// `serveComponent` performs, as a function of the graph.static collectServed = (&graph, gen, &out, key) => {if (key == null || graph.files[key] == null) { return null }for (k of out) { if (k == key) { return null } }out[] = keyfor (imp of graph.files[key].imports) {if (imp.default != null && imp.key != null && hasViewMember(gen, imp.key)) {collectServed(&graph, gen, &out, imp.key)}// MISSION 511: the same for a file imported by braces (its statics are shared through its module)if (isBracedFileImport(imp, graph.manifest.file, clientRealmOf(&graph)) && graph.files[imp.key] != null) {collectServed(&graph, gen, &out, imp.key)}}return null}// Every key this app answers a module for: each route's component and the wrapper// chain above it, the components those compose, and every package's browser half.static servedKeys = (&graph) => {let gen = graph.analysisGenlet entryKey = graph.manifest.filelet out = []if (entryKey != null && graph.files[entryKey] != null) {let imports = graph.files[entryKey].importslet routesNode = 0for (m of hlMembers(gen, entryKey)) {if (m.name == 'routes') { routesNode = m.node }}// Function-route pages anywhere in the import closure, with their wrappers.for (key of componentImports(&graph)) {let k = keywhile (k != null) {collectServed(&graph, gen, &out, k)k = graph.files[k] != null ? graph.files[k].parent : null}}if (routesNode != 0) {let arr = hlSyntax(gen, entryKey, routesNode)if (arr != null && arr.tag == 'array_expression') {for (e of arr.elements) {let row = hlSyntax(gen, entryKey, e)if (row != null && row.tag == 'object_expression') {let hasSocket = falselet hasOther = falsefor (entry of row.entries) {property = hlSyntax(gen, entryKey, entry)if (property != null && property.tag == 'object_property') {if (property.key == 'socket') { hasSocket = true }if (property.key == 'component' || property.key == 'function') { hasOther = true }}}if (hasSocket && hasOther) { hlSourceError(gen, entryKey, e, 'a socket route cannot also have component or function') }for (pe of row.entries) {let prop = hlSyntax(gen, entryKey, pe)if (prop != null && prop.tag == 'object_property' && prop.key == 'component') {let key = routeComponentKey(&graph, gen, entryKey, imports, prop.value)// the wrapper chain above it, deepest last — a page is// served inside whatever wraps itlet k = keywhile (k != null) {collectServed(&graph, gen, &out, k)k = graph.files[k] != null ? graph.files[k].parent : null}}}}}}}}return out}// EVERY PACKAGE'S BROWSER HALF, BY ONE RULE — a package whose browser side is// written in this language ships it as `client.hl`, the compiler writes// `<halfDir>/<pkg>/client.js` into every importing module, and something has to// answer that url. The graph is the whole guard: a key is here only because the// entry's closure reached that package.//// SEPARATE FROM `servedKeys` ON PURPOSE: a half gets a ROUTE but is not a module// url of this app, so it is not in the map `hlJs` is handed. That asymmetry is// the existing `serveHalf`/`serveComponent` split, stated rather than inherited// by accident — measured 2026-09-16, when folding the two together made the// analysis set one key wider than the route walk's.static packageHalfKeys = (&graph) => {let out = []for (gk of graph.files.keys()) {if (gk.startsWith('hl:') && gk.endsWith('/client.hl')) { out[] = gk }}return out}// The browser realm's NAME, off the graph — the declared realm whose entrypoint// is this framework's client half. Static, so the compiler can ask it too.static clientRealmOf = (&graph) => {for (name of graph.realms.keys()) {if (graph.realms[name].entrypoint == 'hl:web/client.hl') { return name }}return null}// EVERY MODULE THIS APP SERVES, COMPILED — what a native binary answers `hlJs`// with (mission 315). The emitter needs the runtime specifier, the browser// realm and the served-url map; all three are functions of the analysis, so the// whole map is, and the COMPILER can build it without an instance.//// `minify` is NOT: it is an app setting bound at construction, and the analysis// cannot evaluate a construction. The value used is recorded beside each// module so a binary asked for a different one refuses at the call instead of// answering text generated the other way.// HOW THE APP ASKED FOR ITS MODULES. A build bakes ONE form of every module and// a binary answering the other form would be different bytes, so the build must// read the app's own answer — and the app writes it where it configures the// framework: `new WebFramework(… minify = true …)` in the manifest. The analysis// carries a construction's named arguments, so this is a READ of the same syntax// `servedKeys` reads for the routes, not a second declaration.//// A COMPUTED `minify` IS NOT READ HERE, and nothing is guessed from it: a build// cannot evaluate an expression the running app has not reached yet. Such an app// bakes the unminified form, exactly as every app did before this, and if it// then asks for the other form at run time the binary says so at the request —// "this binary carries the module compiled the other way", located, which is// the refusal that already exists and the one measured on the creator's social// app (2026-09-17). Writing the literal in the manifest is what removes it.static manifestMinify = (&graph) => {let gen = graph.analysisGenlet key = graph.manifest.fileif (key == null || graph.files[key] == null) { return false }for (m of hlMembers(gen, key)) {let s = hlSyntax(gen, key, m.node)if (s != null && s.tag == 'new_expression' && s.named != null) {for (h of s.named) {let p = hlSyntax(gen, key, h)if (p != null && p.tag == 'object_property' && p.key == 'minify') {let v = hlSyntax(gen, key, p.value)if (v != null && v.tag == 'literal' && v.kind == 'boolean') { return v.text == 'true' }}}}}return false}// THE PACKAGES WHOSE BROWSER HALF MAY BE ONE PLAIN `client.js`: each `hl:<pkg>` a served module (or a package's own// browser half) imports, that has no `client.hl` in the graph. Whether the package really has a `client.js` is// the compiler's to say (`hlJs('hl:<pkg>/client.js')` answers the empty text when it has none).static plainHalfPackages = (&graph) => {let out = []let keys = servedKeys(&graph)for (hk of packageHalfKeys(&graph)) { keys[] = hk }// the files those import, and theirs: a module reaches `hl:time` through a plain `.hl` file it imports (a static helper)let at = 0while (at < keys.length) {let k = keys[at]at = at + 1if (graph.files[k] != null) {for (imp of graph.files[k].imports) {if (imp.key != null && graph.files[imp.key] != null && !keys.includes(imp.key)) { keys[] = imp.key }if (imp.source.startsWith('hl:') && !imp.source.includes('/')) {let pkg = imp.source.slice(3, imp.source.length)if (graph.files['hl:' + pkg + '/client.hl'] == null && !out.includes(pkg)) { out[] = pkg }}}}}return out}// AND A PACKAGE WHOSE BROWSER HALF IS ONE PLAIN `client.js` (hl:time) THE SAME WAY (mission 509): the compiler// writes the same `import … from "<halfDir>/<pkg>/client.js"` for it, so the browser fetches it once and every// page module shares that one instance, instead of each module carrying a private copy of the half's text.plainHalves = {} // package name → the half's text, for the packages the served modules importfor (pkg of plainHalfPackages(&graph)) { servePlainHalf(pkg) }static bakeModules = (graph) => {let realm = clientRealmOf(&graph)let served = servedModulesOf(&graph)let min = manifestMinify(&graph)let out = {}for (k of servedKeys(&graph)) {if (graph.files[k] != null) {let p = graph.files[k].pathout[p] = {text = hlJs(p, k == 'hl:web/client.hl' && env('HL_TK_COVERAGE') != null ? false : min, runtimeSpec, realm, served)minify = k == 'hl:web/client.hl' && env('HL_TK_COVERAGE') != null ? false : minruntime = runtimeSpecrealm = realm}}}// EVERY PACKAGE HALF TOO. The root walk above serves `<halfDir>/<pkg>/client.js`// for every `hl:<pkg>/client.hl` the graph holds, and a compiled binary answers// from BAKED text alone — so a bake that skipped them served the page and then// 404'd on the module the page imports, leaving the client half of the app// dead with nothing reported (measured on projects/framework, 2026-09-16).// Same rule, same list, one loop later: what the server routes, the build bakes.// AN OFFLINE APP'S SERVICE WORKER MODULE (COMPONENTS §10), under its own pathif (manifestOffline(graph)) {let wp = workerPathOf(graph)out[wp] = {text = hlJs(wp, min, runtimeSpec, realm, served)minify = minruntime = runtimeSpecrealm = realm}}if (graph.files['hl:web/uploads.hl'] != null) {p = graph.files['hl:web/uploads.hl'].pathout[p] = { text = hlJs(p, min, runtimeSpec, realm, served); minify = min; runtime = runtimeSpec; realm = realm; }}if (manifestFeature(&graph, 'offline')) {p = graph.files['hl:web/offline.hl'].pathout[p] = { text = hlJs(p, min, runtimeSpec, realm, served); minify = min; runtime = runtimeSpec; realm = realm; }}// AND EACH PLAIN PACKAGE HALF (mission 509), under its pseudo path `hl:<pkg>/client.js`for (pkg of plainHalfPackages(&graph)) {let pp = 'hl:' + pkg + '/client.js'out[pp] = {text = hlJs(pp, min, runtimeSpec, realm, served)minify = minruntime = runtimeSpecrealm = realm}}for (gk of graph.files.keys()) {if (gk.startsWith('hl:') && gk.endsWith('/client.hl') && graph.files[gk] != null) {let hp = graph.files[gk].pathif (out[hp] == null) {out[hp] = {text = hlJs(hp, gk == 'hl:web/client.hl' && env('HL_TK_COVERAGE') != null ? false : min, runtimeSpec, realm, served)minify = gk == 'hl:web/client.hl' && env('HL_TK_COVERAGE') != null ? false : minruntime = runtimeSpecrealm = realm}}}}return out}// file path → the url this server answers its module at. What `hlJs` is handed,// and what the compiler bakes against.static servedModulesOf = (&graph) => {let out = {}// An extension's Client reference must reuse the package half's own module.if (graph.files['hl:web/client.hl'] != null) { out[graph.files['hl:web/client.hl'].path] = halfDir + '/web/client.js' + buildMark }if (graph.files['hl:web/offline.hl'] != null) { out[graph.files['hl:web/offline.hl'].path] = '/__hl/offline.js' + buildMark }if (graph.files['hl:web/uploads.hl'] != null) { out[graph.files['hl:web/uploads.hl'].path] = '/__hl/uploads.js' + buildMark }for (k of servedKeys(&graph)) {if (graph.files[k] != null) { out[graph.files[k].path] = graphModulePath(k) + buildMark }}return out}// ONE PACKAGE HALF'S ROUTE. It is a FUNCTION and not the body of the loop above// because the url's route closure must hold THIS key: a `let` in a loop body is// one binding the closures share, so every route built that way would serve the// last package's half (measured 2026-09-14 — both /__hl/web/client.js and// /__hl/dnd/client.js answered with hl:web's module). A parameter is a fresh// binding per call, which is the same reason serveComponent below is a function.serveHalf(key) {routes[] = { pattern = halfUrl(key.slice(3, key.length - 10)) framework = true function = (route, req) => { return serveHl(key, req) } }return null}// ONE PLAIN PACKAGE HALF'S ROUTE (mission 509): the text comes from `hlJs` as `hl:<pkg>/client.js` (the compiler// reads it beside the package, a binary carries it baked); a package that has no such half answers the empty text// and gets no route. Cached by the build version exactly like the other halves (`cached`).servePlainHalf(pkg) {let text = hlJs('hl:' + pkg + '/client.js', minify, runtimeSpec, clientRealm(), servedModules())if (text == null || text == '') { return null }plainHalves[pkg] = textroutes[] = { pattern = halfUrl(pkg) framework = true function = (route, req) => {return new Response(plainHalves[pkg], { headers = cached(req, 'text/javascript; charset=utf-8') })} }return null}// a mounted file's module route, and the routes of the components it composes// (an import with a View), recursively — off the graph, once eachserveComponent(key) {if (served[key] != null) { return null }served[key] = trueroutes[] = { pattern = modulePath(key) framework = true function = (route, req) => { return serveHl(key, req) } }for (imp of graph.files[key].imports) {if (imp.default != null && imp.key != null && viewHandle(imp.key) != 0) { serveComponent(imp.key) }// MISSION 511: a file a served module imports statics from by braces is a module of its own too, so its statics exist once;// a braced import of a file outside the graph is skipped, as collectServed skips it, so it cannot crash the bootif (isBracedFileImport(imp, graph.manifest.file, clientRealm()) && graph.files[imp.key] != null) { serveComponent(imp.key) }}return null}// THE PROJECT DIRECTORY: this file lives in a package, so the app's directory is read// off a file that is the app's — the first route component's key against its pathroot = projectRoot()view = new HlwViewServerviewRead = new HlwViewcss = new HlwCss(minify = minify, view = view)compiler = new HlwCompile(browserKeyOf = graphModuleKey)sessions = new HlwSessions(dir = sessionDirPath(), maxAge = sessionMaxAge != null ? sessionMaxAge : 1209600, idle = sessionIdle != null ? sessionIdle : 900, sweepEvery = sweepInterval != null ? sweepInterval : 300, cookie = cookieName(), secure = sessionSecure, anonMax = sessionAnonMax, anonKeep = sessionAnonKeep, domain = sessionDomain != null ? sessionDomain : '')sessions.open()// THE STYLES FILE IS NAMED AT BOOT, not at the first request for the stylesheet: a value// that names no file, or a file the graph does not hold, is the app's mistake and the// app does not start with it (ticket #12)if (styles != null) {if (hlTypeName(styles) != 'String' && hlTypeName(styles) != 'Class') { refuseAtSetting('styles', "hl:web: styles is the styles file — the class the app imported (`styles = Styles`) or a path string ('./styles.hl') — and this one is a " + hlTypeName(styles)) }if (graph.files[keyOf(styles)] == null) { refuseAtSetting('styles', "hl:web: styles names " + keyOf(styles) + ", which is not in the project graph — import it from the app's entry (`import Styles from './styles.hl'`) and write `styles = Styles`") }}// the whole tree, nothing excluded: dot directories (the session store) are skipped by// the walker's own rule, and a custom store inside the tree is the app's choice to pay forif (watchMode) { __native("eventloop.register", watch(root), "hlFileChanged") }sheetText = null // the stylesheet, walked once at the first request for it// hl:web's OWN urls (/__hl/*, /components/*.hl) win over the app's routes whatever the// app's table ends in (ticket #129: a last `/:slug/:n` answered /__hl/app.css with HTML):// the framework's routes first, the app's after them in their own orderlet ownFirst = []for (r of routes) { if (r.framework == true) { ownFirst[] = r } }for (r of routes) { if (r.framework != true) { ownFirst[] = r } }let oi = 0for (r of ownFirst) {routes[oi] = roi = oi + 1}router = new HlwRouter(routes = routes)trees = {} // key → the View tree, built oncepreloaded = {} // key → true: the closure of the Views it reaches is loaded (preload)declared = {} // key → { member name → true } of its non-static members (declares)setters = {} // key → { member name → true } of its setters (setterOf)reach = {} // key → the component keys its View reaches, in the order preload walks themless = {} // key → { skipped, kids }: the server-only members the first load's seed leaves out (lessFor)needed = {} // key → { sites, names, reads }: the members only the server computes (serverNeeds)kidWants = {} // key → the host members the View's references, conditions and lists read (kidWanted); cleared with `needed`srvBelow = {} // key → 'yes' / 'no': does a component below (or this one) have server-realm members (srvBelow)kidless = {} // key → 'yes' / 'no': does its View reference a component (holdsKids)fillsOf = {} // key → the named-region fills its View root writes (`side { … }`), lifted out of the treeslotAt = {} // key → where its View places its one `slot`styleNames = {} // key → the rule names of the file's Style, off the syntaxstyleRefs = {} // key → [{ tag rule }] the View wrotefillTags = {} // key → the element names (DOM tags) callers write into this component's slot (hybriel#270)styleTags = {} // key → the element names this file's View rendersstyleIds = {} // key → the literal `id` values this file's View writes (R3)staticHolders = {} // key → an instance of a file whose statics another file importsmodules = {} // key → the browser module (JavaScript text), compiled once at bootbuildHash = null // the hash of everything this build serves, in every cached url (build())workerCompiled = null // the service worker's module as compiled (offline apps only, workerText())shipped = {} // key → the module as served: its build marks replaced with the hashsitesOf = {} // key → the position tables cut out of a deploy build's module, as the JSON `?sites=1` answersservedUrls = null // file path → the url this server answers its module at, for hlJs// MISSION 505: the paint helpers every component module used to carry (compile.hl `paintHelpers`, 699 bytes in each of the 25// modules of the reference app's start page) ride once, at the end of the runtime text every module imports firstruntime = hlJsRuntime() + newline + compiler.paintHelpers() // the runtime library every module imports as "./hl-runtime.js"peers = {} // connection key → the WsClient, while it is openpeerSession = {} // connection key → its session, from the tab's `hello` (null = anonymous)peerHost = {} // connection key → the host its upgrade request named (null = none sent)peerHeaders = {} // connection key → its upgrade request's headers (requestHeaders)peerMounts = {} // connection key → the component keys the tab has mounted// A TAB OUTLIVES ITS SOCKET (ticket #143): 't' + the tab's id → { id, n, log, bytes, conn,// session, mounts, params, host, headers, left }. `n` counts the pushes sent to it, `log`// keeps the last of them as sent ([{ n, text }], bounded by pushKept/pushKeptBytes),// `conn` is its open socket's key or null, `left` when that socket went (tabKept)tabs = {}peerTab = {} // connection key → the id of the tab its `hello` named// SESSIONS (web/sessions.hl): named by the cookie, at the page request and at the// socket's handshake alike. Nothing about a session ever reaches page script.sending = null // the WsClient whose inbound emit is being handled — the peer// an outward emit reaches, and null under the POST fallback// THE POST FALLBACK'S PEER IS ITS OWN ANSWER. While a face dispatched over// `POST /__hl/emit` runs, or a socket face has a transient session (W214), `posting` is true. Every outward emit meant for the// CALLER is appended here instead of pushed; `inbound` ships the list in the ack.Boolean posting = falsepostEmits = []// …AND ITS TAB (#143): the tab a POST named (`tab` in its frame, of the same session) has// what is raised for it numbered and logged like a push, so the replay on its next socket// does not run it a second timepostTab = null// A PAGE ANSWER'S OWN PUSHES (hybriel#410): what building a navigation answer (the `page` face) raises for the NAVIGATING tab is// numbered and logged like any push (#143) but rides in the page ack as `late`, in order, not sent ahead of it: the browser// places the new page first and then applies them, so the page it is leaving never shows the effect of the page's build.lateOn = falselateTab = nulllateEmits = []postSession = null // the cookie's session of the POST being dispatchedpendingRotate = {} // 'r' + token → { old, id, at }: a socket-carrier rotation waiting for its browser's POST /__hl/rotate (W120)postAdopted = null // the session a POST's face (or an upload start) just made: its answer sets the cookie (W124)postReq = null // the request context of the POST being dispatched (requestInfo)faceReq = null // the request context of the carrier whose inbound emit is being dispatchedpeerReq = {} // connection key → its upgrade request's context (requestInfo)adoptTokens = {} // one-time token → { sid, at }: a socket cannot set a cookie, so the page asks for it (/__hl/adopt)postHost = null // the host of the POST being dispatchedfaceInst = null // the BLANK instance the running face writes on (step 2 of #201): read back as the tab's deltafaceKey = nullfaceSent = {} // name -> JSON of what the delta already carried, so a later flush sends only the changefaceHost = null // the host of the carrier whose inbound emit is being dispatchedpostHeaders = null // the headers of the POST being dispatched (requestHeaders)faceHeaders = null // the headers of the carrier whose inbound emit is being dispatched// EXACTLY ONCE (COMPONENTS §10): a queued emit carries a stable id `q`, and the ids handled// are kept per session, the last `handledKept` of them (Session.handled). A connection// with no session keeps its ids here, in one list under the same bound.Number handledKept = 200anonHandled = []// WHAT A KEPT ID WAS ANSWERED (ticket #107). An emit in flight when its socket closed// is sent again with its id, and its caller is still waiting — for a page, say. The// first delivery's ack went out on the dead socket, so the repeat is answered from// here: `answers[session id + ' ' + q]` is that ack as sent (its `i` replaced), or// `running` while the first delivery has not finished, which answers the repeat// `later` and the client asks again. In memory, the last `handledKept` of them: a// repeat comes seconds after the first try, and a restart loses nothing a live peer// still waits for but the ack, which is then plain `ok`, as before.answers = {}answerKeys = []uploads = {} // 'u' + upload id → { sid, name, type, size, have, parts, at, key }: a file on its way in (ticket #94)uploadKeys = {} // 'k' + session id + ' ' + q + ' ' + n → the upload id the n-th file of emit q went up underuploadParts = {} // 'u' + id + ':' + n → the n-th part as it arrived, a Bytes// ONE PORT, TWO CARRIERS. hl:http1's WebSocket engine answers the Upgrade// inline on the port this server already bound, so `websocket` and `rest` are// the same listener — which is why the manifest can declare both for the same// direction and this file needs no second server.// EVERY VIEW IS BUILT AT BOOT, not at the first request for its route: a View that// reads a name its file declares nowhere (checkRead) is the app's mistake, and the// app does not start with it — the port is bound on the line below this pass.// THE TWO DERIVATIONS MUST AGREE (mission 315). `served` is built above from the// EVALUATED route table; `servedKeys(&graph)` derives the same set from the// analysis alone, and the compiler bakes each module's text against the second.// If they ever disagree the binary would serve modules generated against urls// this server does not answer, so the disagreement is a refusal, here, at boot.analysedKeys = servedKeys(&graph)for (k of analysedKeys) {if (served[k] == null) {hlError('hl:web: the analysis says this app serves ' + k + ', the route walk did not — the two derivations of the served set disagree')}}for (k of served.keys()) {let seen = falsefor (a of analysedKeys) { if (a == k) { seen = true } }if (seen == false) {let why = ''for (imp of graph.files[k] != null ? [] : []) { why = why }hlError('hl:web: the route walk serves ' + k + ', the analysis did not — the two derivations of the served set disagree')}}routeNow = nullanon = nullfor (k of served.keys()) { if (viewHandle(k) != 0) { tree(k) } }// the compiler reads a kid mount's View through this (a mount no longer carries a copy of it)compiler.treeOf = (key) => { return tree(key) }// A COMPONENT-REFERENCE CYCLE IS REFUSED HERE (COMPONENTS §12): a View that renders// itself, directly or through another, is a mount that never ends — it overflowed the// stack at the first request and the server died of a segfault with nothing said// (mission 322 row 1).acyclic = {}for (k of served.keys()) { if (viewHandle(k) != 0) { referenceCycle(k, [], []) } }// …and a page a shell wraps is placed at the shell's slot, inside its body: a page whose// root is `body` there emitted a second, nested <body> (mission 322 row 5)for (k of mounted) {if (graph.files[k] != null && graph.files[k].parent != null && viewHandle(k) != 0 && bodyRooted(k)) {hlError("hl:web: " + k + " is wrapped by " + graph.files[k].parent + " (its `parent` clause), but its View's root is `body { … }`, the page's body: the shell owns the body, so write the page's root as an element (`main { … }`, `section { … }`)")}}// THE SHEET IS WALKED AT BOOT, so the rules it drops are listed at boot (COMPONENTS §4,// css.hl's own header): walked at the first request for it, a dead rule was listed only// once some browser had asked, and a boot log said nothing (mission 322 row 11)stylesheet()// EVERY SERVED MODULE IS COMPILED AT BOOT: a free name in a View handler is a located// compile error (COMPONENTS §6b), and compiled at the first request for the module it// was a 500 behind a page that had already answered 200 (mission 322 row 14)for (k of served.keys()) { module(k) }// THE INTERFACE IS THE OPERATOR'S (ticket #24), on the ladder graph.zig's OperatorBind// states: the constructor's `host` > HL_HOST (the binary fills it from HOST) > the// manifest's > 0.0.0.0. Binding the default regardless put an app meant to sit behind// a proxy on every interface of the machine.if (host == null) { host = env('HL_HOST') }if (host == null && cfg != null && cfg.host != null) { host = cfg.host }if (host == null) { host = '0.0.0.0' }// A --PORT AFTER THE ENTRY OUTRANKS THE APP'S OWN PORT (creator ruling// 2026-09-27), but `port` ITSELF CANNOT SAY SO: the reference app passes an// explicit `port = …` to `new WebFramework(…)` (server.hl, computed from// HL_FW_PORT so a test run can sit beside a developer's own instance), which// PINS the member for the whole construction (SPEC.md "The file root is the// constructor" — "a root assignment to [a pinned] property… is a no-op").// `port = port_arg` below was exactly that no-op: `hybriel server.hl// --port=11499` still bound 44333, server.hl's own default, because this// line's write never landed. `boundPort`, a plain local nothing ever pins,// carries the actual ladder instead — CLI argument, else the (possibly// pinned) member, else HL_PORT, else 8080 — and IS what binds and what the// boot line names.warnRemovedCaches()let port_arg = portArgument()let boundPort = port_argif (boundPort == null) { boundPort = port }if (boundPort == null && env('HL_PORT') != null) { boundPort = toNumber(env('HL_PORT')) }if (boundPort == null) { boundPort = 8080 }http = new NativeWebSocketServer(port = boundPort, host = host)echo 'framework listening on ' + boundPortmodule('web/client.hl')// ---- the browser's modules: compiled IN PROCESS, served from memory --------------// The JavaScript target is this binary's own function (hlJs), the same one `--js`// runs from the command line. No child process, no build directory.//// THE CLIENT is compiled at boot — every page needs it, and it carries the View// and the Router with it (one module, three classes). A COMPONENT is compiled ON// DEMAND, at the request for its own `.hl` url, and kept: a route nobody visits// costs nothing, and the browser asks for a component's module the first time it// mounts one.//// THE TABLE THE EMITTER WRITES IS DROPPED. `hlJs` puts each file's members,// handlers and methods — every node of every initializer, with the names it reads —// into the module, because the old hl:web's browser half reduces that table on every boot.// This framework asked the same questions at COMPILE time and wrote the answers into// the component's own statements, so the table is dead weight in the page: 58 KB of// syntax on the reference app's home page alone. What the framework SERVES is its own// text, so it leaves that statement out; the language is not asked to change, and// The old hl:web kept its table untouched.// THE TABLE STATEMENT'S NAME in this module: `hlTablesDef`, or in a compact module the// alias its import clause gives it (`hlTablesDef as _51`). Each statement stands at the// start of its own line, which is how it is found — an alias alone is a suffix of other// names (`$_51(` is a compiler temporary).tablesCall(text) {let alias = text.indexOf('hlTablesDef as ')if (alias < 0) { return newline + 'hlTablesDef(' }let first = alias + 15let stop = firstwhile (stop < text.length && text[stop] != ',' && text[stop] != '}') { stop = stop + 1 }return newline + text.slice(first, stop) + '('}// the `fns` of the file's own table — the first table statement the module carries is// the file's; the ones after it are the classes it bundlestableFns(text) {let at = text.indexOf(tablesCall(text))if (at < 0) { return [] }let open = text.indexOf('{', at)let end = text.indexOf(');', at)if (open < 0 || end < 0) { return [] }let t = JSON.parse(text.slice(open, end))return t.fns == null ? [] : t.fns}withoutTables(text) {// one per FILE the module carries — the client half bundles three classes. A compact// module calls it by its alias, and was served with every table until ticket #98's// follow-up: 50 KB and more of syntax on a minified app's pagelet call = tablesCall(text)let out = textlet at = out.indexOf(call)while (at >= 0) {let end = out.indexOf(');', at)if (end < 0) { return out }// the newline before it stays: it ends the statement aboveout = out.slice(0, at + 1) + out.slice(end + 2)at = out.indexOf(call)}return out}// THE APP RUNS ON ONE WEB FRAMEWORK. Which packages are frameworks is READ OFF THE// GRAPH and not off a list this file keeps: a package the app's entry reached that// holds a `WebFramework.hl` is one. hl:dnd, hl:http1 and every other package an app// imports hold none and are untouched by this.//// The refusal names the ROW of each import, because the mistake IS an import line —// a sub-file import (`'hl:web/css'`) counts as much as the package itself, which is// exactly the case that made it: a lone braced import of a stylesheet helper puts the// whole package into the graph, and with it a second navigation face.oneFrameworkOnly() {let frameworks = {}for (gk of graph.files.keys()) {if (gk.startsWith('hl:') && gk.endsWith('/WebFramework.hl')) { frameworks[gk.slice(0, gk.length - 16)] = true }}if (frameworks.keys().length < 2) { return null }// the first row of the app's OWN files that reached each packagelet sites = {}for (k of graph.files.keys()) {if (!k.startsWith('hl:')) {for (imp of graph.files[k].imports) {for (pkg of frameworks.keys()) {if (sites[pkg] == null && (imp.source == pkg || imp.source.startsWith(pkg + '/'))) {sites[pkg] = { key = k; node = imp.node; where = k + ':' + imp.line + ':' + imp.col + " imports '" + imp.source + "'" }}}}}}let said = ''for (pkg of frameworks.keys()) {if (said != '') { said = said + ', and ' }if (sites[pkg] == null) { said = said + "'" + pkg + "' (reached through a package, not from a file of the app)" }else { said = said + sites[pkg].where }}let msg = 'this app imports TWO web frameworks: ' + said + '. Both packages load, both answer a page navigation, and the second one answers on a blank instance. An app runs on ONE of them — switch EVERY hl: import in EVERY file of the app to the same package, a sub-file import like \'/css\' included. Switching one line is not switching the app.'// THE CARET GOES ON ONE OF THE ROWS, and the sentence names them all: two// import lines are equally the mistake, and a diagnostic can only underline one.for (pkg of frameworks.keys()) {if (sites[pkg] != null) { hlSourceError(gen, sites[pkg].key, sites[pkg].node, msg) }}hlError(msg)return null}// ONE ANSWERER PER VALUE-FORM EMIT. SPEC: "if more than one class in the destination// realm declares a non-tap handler for the event, the VALUE form is refused at the emit// site naming both. As a statement it stays a broadcast and every handler still fires."// The statement form is what `inbound` does — every face runs. The value form cannot be// told apart on the wire, so every `x = emit server ev()` the app's files hold is read// off the analysis here, and one whose event two files answer is refused at its site,// naming both, before anything is served. Until ticket #20 both faces ran and the first// answer was taken in silence.oneAnswererEach() {let realm = serverRealm()for (k of graph.files.keys()) {if (!k.startsWith('hl:')) {for (e of hlEvents(gen, k).emits) {if (e.value == true && e.realm == realm) {let owners = facesOf(e.event)if (owners.length > 1) {let named = ''for (o of owners) { named = named == '' ? o : named + ' and ' + o }let msg = "hl:web: " + k + ':' + e.line + ':' + e.col + " — this emit waits for the answer of '" + e.event + "', and " + owners.length + " files answer it in the '" + realm + "' realm: " + named + ". A value-form emit has ONE answerer — rename the event in one of them, or emit it as a statement (a broadcast every handler receives)"hlSourceError(gen, k, e.node, msg)hlError(msg)}}}}}return null}// WHAT THIS SERVER SERVES AS A MODULE OF ITS OWN, by the file's path (mission 314// rule 0). Handed to `hlJs`, it is what turns `import PostCard from './post_card.hl'`// into an ES import of `/components/post_card.hl` instead of PostCard's whole class// text copied into the importing module — EditHistory's class shipped three times on// the social demo's home page before this. The urls are THIS file's (`moduleUrl`);// the compiler invents none, and a file this server does not answer for is inlined// exactly as it always was.servedModules() {if (servedUrls == null) {out = servedModulesOf(&graph)for (k of served.keys()) { out[pathOf(k)] = modulePath(k) + buildMark }servedUrls = out}return servedUrls}// A key the graph holds no file for is answered `null`, and the caller makes// that a 404: a file the entry's closure never referenced is not part of this// app, which is what keeps this from being a read of any path a url asks for.module(key) {if (modules[key] == null) {let f = graph.files[key]if (f == null) { return null }// THE BROWSER GETS THE BROWSER'S PROJECTION, and nothing else. hlJs's// fourth argument is the realm the module is produced for: a handler// written `on server …` is not emitted at all, and a member whose// initializer reaches a name the browser does not have is declared// without one, for this server to lay over the instance with the state// it already ships. The realm NAME comes off the manifest (clientRealm()// above), never a literal — a project names its own realms.// Coverage uses one unminified browser half; other modules retain app settings.clientMin = key == 'hl:web/client.hl' && env('HL_TK_COVERAGE') != null ? false : minifylet text = hlJs(f.path, clientMin, runtimeSpec, clientRealm(), servedModules())// AND THE COMPILE STEP'S OWN OUTPUT BESIDE IT (mission 313): a component with a// View carries, after its class, the paint statements this framework compiled// from that View — one per bound spot, with its read written in (compile.hl).// The browser calls them instead of walking the tree at paint time. Text// produced here and served from memory like the module itself; nothing is// written to disk and no JavaScript file lives under plugins/.// THE FUNCTION VALUES' SITES are the one part of that table the browser still// needs (tickets #98, #99): the compile step turns them into write setslet fns = tableFns(text)text = withoutTables(text)// Run registration only when this ES module is evaluated in the browser.// A static initializer would also run while the server loads its graph.if (key == 'hl:web/offline.hl') { text = text + newline + 'await Offline.register();' + newline }if (key == 'hl:web/uploads.hl') { text = text + newline + 'await Uploads.register();' + newline }if (viewHandle(key) != 0) {let nodes = tree(key)text = text + newline + compiler.module(gen, key, nodes, fns, fillsOf[key])// THE COMPONENT'S BLUEPRINT COMES WITH ITS MODULE (W195): the structure the browser reads (`skeleton`), whether the// component takes the route and which members the server computes. Not in the seed, so a page carries only the plans of// components it uses. The elements, texts and attributes are not in it: the paint code above already holds them (W199).let need = serverNeeds(key)plan = { view = skeleton(&nodes); route = declares(key, 'route'); srv = need.sites.length > 0 ? need.reads : null; setters = setterNames(key); }// Offline construction follows the same parent chain; it belongs to the module, not every seed.if (offlineKeys != null && graph.files[key].parent != null) { plan.parent = graphModuleKey(graph.files[key].parent) }text = text + ';(globalThis.__hlB=globalThis.__hlB||{})[' + JSON.stringify(graphModuleKey(key)) + ']=' + JSON.stringify(plan) + ';' + newline}modules[key] = text}return modules[key]}// WHAT THE BROWSER READS OF A VIEW TREE besides the paint code (W199): the composed children with their bindings and fill (it// mints and re-binds them), the `for`s (their site and the list they iterate, which decides whether a child is repainted or// composed anew) and the `if`s that hold one of those. An element stands for nothing but the place of its children, so the// elements go and their children move up; texts, attributes, handlers and styles are in the compiled paint code and not here.skeleton(&nodes) {let out = []for (n of nodes) {if (n.k == 'el') { for (c of skeleton(&n.children)) { out.push(c) } }else if (n.k == 'component') { out.push({ k = 'component'; path = n.path; bindings = n.bindings; fill = skeleton(&n.fill); }) }else if (n.k == 'for') { out.push({ k = 'for'; site = n.site; list = n.list; body = skeleton(&n.body); }) }else if (n.k == 'if') {let t = skeleton(&n.then)let o = skeleton(&n.other)if (t.length > 0 || o.length > 0) { out.push({ k = 'if'; site = n.site; then = t; other = o; }) }}}return out}// the file the graph knows under this key — the graph carries every file's own pathpathOf(key) {let f = graph.files[key]if (f == null) { hlError('the graph holds no file ' + key + ' — nothing referenced it from the entry') }return f.path}// THE BROWSER'S REALM, off the manifest: the realm whose declared entrypoint is// this framework's client half. The framework's own two files ARE the two// realms' entrypoints, so this is a lookup and never a guess.clientRealm() {for (name of graph.realms.keys()) {if (graph.realms[name].entrypoint == 'hl:web/client.hl') { return name }}hlError('the manifest declares no realm whose entrypoint is ./client.hl — the browser half of this framework IS a realm, and a page cannot say which realm it is running in until the manifest names it')}// THIS realm, off the graph: the declared realm whose entrypoint REACHES this// file (the app's entry imports it). A face names it, and so does the refusal// when nothing answers.serverRealm() {let mine = graph.files['hl:web/WebFramework.hl'].realmsif (mine.length == 1) { return mine[0] }hlError('the manifest declares no realm whose entrypoint reaches hl:web/WebFramework.hl — this file cannot dispatch a face without knowing which realm it is')}// the app's directory: a route component is the app's file, its key project-relativeprojectRoot() {for (r of routes) {if (r.component != null) { return rootOf(keyOf(r.component)) }}// AN APP OF FUNCTION ROUTES ONLY (ticket #19) has no component to read it off, and// needs no other: the manifest is the app's file too, and the graph knows its keyif (graph.manifest.file != null && graph.files[graph.manifest.file] != null) { return rootOf(graph.manifest.file) }hlError('hl:web: the route table names no component and the graph names no manifest file, so the app\'s directory cannot be read off either')}// a project-relative key against its absolute path: what is left is the project's directoryrootOf(key) {let path = pathOf(key)// A COMPILED BINARY'S PATH IS ITS KEY (mission 318): it carries no// build directory, so the file's path and its key are the same// string and the root is the process's own directory. The// interpreter's path is the script's absolute one, and the key is// its tail — the root is what stands before it.if (path == key) { return '.' }return path.slice(0, path.length - key.length - 1)}// THE KEY OF A FILE THE APP NAMED — as the class it imported (`component = SortList`,// `styles = Styles`: the import is the guarantee the graph reached it) or as a path// ('./components/home.hl'). A class knows its file (`file(cls)`), and the graph knows// the file's key.keyOf(named) {if (hlTypeName(named) == 'Class') {let path = file(named)for (k of graph.files.keys()) {if (graph.files[k].path == path) { return k }}hlError('hl:web: the class at ' + path + ' is not in the project graph — import it from the app\'s entry')}// ANYTHING ELSE NAMES NO FILE (ticket #12): `styles = {}` booted and every request// for the stylesheet was then a NotCallable on this line, with no line of the app'sif (hlTypeName(named) != 'String') { hlError("hl:web: a file the app names — a route's component, or `styles` — is the class it imported or a path string ('./styles.hl'), and this one is a " + hlTypeName(named)) }if (named.startsWith('./')) { return named.slice(2) }return named}// ---- the View tree: the member's syntax, reflected into plain hybrids ----------viewHandle(key) {for (m of hlMembers(gen, key)) {if (m.name == 'View') { return m.node }}return 0}tree(key) {treeLoad(key)return trees[key]}// THE TREE IS BUILT ONCE PER KEY and read in place afterwards (`&trees[key]`): `tree(key)` hands out a COPY of the whole// View tree on each call, and a mount, a render and a seed each asked for one (W116)treeLoad(key) {if (trees[key] != null) { return null }let handle = viewHandle(key)if (handle == 0) { hlError('component ' + key + ' declares no View') }let v = hlSyntax(gen, key, handle)let nodes = []let fills = []for (h of v.entries) {let n = node(key, h, [], false, [])// A NAMED REGION'S FILL (D-CHAIN addendum): `side { … }` at this View's root, where a level// above declares `slot { name = 'side' … }`, is the content of THAT region and not of this// page's own column: the region renders it, in this page's frame (compile.hl skips it here)if (n != null && n.k == 'if' && n.regionfill != null) { fills.push({ name = n.regionfill; site = n.site; children = n.then; cond = null; }) }// A CONDITIONAL FILL: `if (x) { side { … } }` at the View root fills while x holds (the default// stands otherwise); the `if` itself stays in the page's tree (its branch holds the fill's// components for the mounts, and the browser's `if` site is what hears x change)else if (n != null && n.k == 'if' && n.region == null) {for (c of n.then) {if (c.k == 'if' && c.regionfill != null) { fills.push({ name = c.regionfill; site = c.site; children = c.then; cond = n.cond; }) }}}if (n != null) { nodes.push(n) }}for (n of nodes) {if (n.k == 'if' && n.regionfill == null && n.region == null) {strayFill(key, n.then, true)strayFill(key, n.other, false)} else if (n.regionfill == null) { strayFill(key, [n], false) }}fillsOf[key] = fillstrees[key] = nodesreturn null}// a fill standing anywhere but a View's root (or the root-level `if` that makes it conditional) is// refused where it stands, rather than left to render nothingstrayFill(key, nodes, direct) {for (n of nodes) {if (n.k == 'if' && n.regionfill != null) {if (!direct) { hlError('hl:web: ' + n.site + " — a region's fill (`" + n.regionfill + " { … }`) stands at a View's root or directly inside a root-level `if`; this one stands deeper (inside a nested `if`, an `else` or an element)") }}else if (n.k == 'if') { strayFill(key, n.then, false) strayFill(key, n.other, false) }else if (n.k == 'el') { strayFill(key, n.children, false) }else if (n.k == 'for') { strayFill(key, n.body, false) }else if (n.k == 'component' && n.fill != null) { strayFill(key, n.fill, false) }}return null}// whether a node list holds a component anywhere (a region default that does is mounted late)holdsComponent(nodes) {for (n of nodes) {if (n.k == 'component') { return true }if (n.k == 'el' && holdsComponent(n.children)) { return true }if (n.k == 'if' && (holdsComponent(n.then) || holdsComponent(n.other))) { return true }if (n.k == 'for' && holdsComponent(n.body)) { return true }}return false}// the named regions the levels ABOVE this file declare (`slot { name = 'side' … }`)regionsAbove(key) {let out = []let w = hlFile(gen, key).wrapperlet guard = 0while (w != null && guard < 64) {regionNamesIn(&out, tree(w))w = hlFile(gen, w).wrapperguard = guard + 1}return out}regionNamesIn(&out, nodes) {for (n of nodes) {if (n.k == 'if') {if (n.region != null) { out.push(n.region) }regionNamesIn(&out, n.then)regionNamesIn(&out, n.other)}else if (n.k == 'el') { regionNamesIn(&out, n.children) }else if (n.k == 'for') { regionNamesIn(&out, n.body) }else if (n.k == 'component' && n.fill != null) { regionNamesIn(&out, n.fill) }}return null}// one entry of a hybrid literal → a tree node (null for an attribute: the// element that owns it reads it)node(key, handle, path, inFor, rows) {let n = hlSyntax(gen, key, handle)if (n == null) { return null }if (n.tag == 'object_property') {let v = hlSyntax(gen, key, n.value)if (v.tag == 'object_expression') {// A NAMED REGION: `slot { name = 'side' <default> }` is a region a lower level may fill// (an `if` that always stands, carrying its name: the walkers already know the shape);// `side { … }` at a View's root where a level above declares it is that region's fillif (n.key == 'slot') {let rname = regionName(key, v)if (rname != null) {let el = element(key, 'slot', v, path, inFor, rows)let kids = []for (c of el.children) { kids.push(c) }return { k = 'if'; region = rname; deferred = holdsComponent(kids); cond = { k = 'text'; text = 'true'; kind = 'boolean'; }; then = kids; other = []; site = el.site; }}}if (inFor && path.length == 0 && componentKeyOf(key, n.key) == null && regionsAbove(key).includes(n.key)) {hlError('hl:web: ' + baseName(pathOf(key)) + ':' + n.line + ':' + n.col + " — a region's fill (`" + n.key + " { … }`) cannot stand inside a `for`: a fill stands at a View's root, or directly inside a root-level `if`")}if (path.length == 0 && !inFor && componentKeyOf(key, n.key) == null && regionsAbove(key).includes(n.key)) {let el = element(key, n.key, v, path, inFor, rows)// (an `if` that never renders in this column, so every walk of the tree that finds the// components standing in it — mounts, seed, browser — sees them as it does an `if`'s)return { k = 'if'; regionfill = n.key; cond = { k = 'text'; text = 'true'; kind = 'boolean'; }; then = el.children; other = []; site = el.site; }}let childKey = componentKeyOf(key, n.key)if (childKey != null) { return component(key, n.key, childKey, v, v, path, inFor, rows) }return element(key, n.key, v, path, inFor, rows)}return null}if (n.tag == 'literal') { return { k = 'text'; text = n.text; kind = n.kind; } }if (n.tag == 'identifier') {// A BARE CAPITALISED REFERENCE IS A COMPOSITION WITH AN EMPTY FILL (§12:// "`Name { }` is the same reference as bare `Name`"). It is not a read, so it// is answered before the read rules below refuse the name.let bareKey = componentKeyOf(key, n.name)if (bareKey != null) { return component(key, n.name, bareKey, null, n, path, inFor, rows) }if (n.name == 'slot') { oneSlot(key, n) }// AN IMPORTED STATIC IN A VIEW IS FOLDED (the archive did the same at build):// `h1 { siteTitle }` with `import { siteTitle } from '../store.hl'` is not a// member of this class, it is a constant of another file — read off that// file's class once, here, and written into the tree as textreturn nameRead(key, n.name, rows, n)}if (n.tag == 'view_for') {// `for (row of list) { … }` — the list is a member (or a row field), the// body's entries are rendered once per entry with `row` bound to itlet body = hlSyntax(gen, key, n.body)let children = []// THE ROW VARIABLE IS IN SCOPE INSIDE THE BODY, and nowhere else: the list is// read in the scope that stands around the `for`let list = ref(key, n.list, rows)let inner = rows.slice(0)inner.push(n.varName)for (h of body.entries) {let c = node(key, h, path, true, inner)if (c != null) { children.push(c) }}// THE SITE, as every element node carries one: the id the module's tables// file this `for`'s row under, so the browser reads what the list depends// on from the compiler instead of guessing it off `list.name`.return { k = 'for'; row = n.varName; list = list; body = children; site = baseName(pathOf(key)) + ':' + n.line + ':' + n.col; }}if (n.tag == 'view_if') {let then = []let cons = hlSyntax(gen, key, n.consequent)for (h of cons.entries) {let c = node(key, h, path, inFor, rows)if (c != null) { then.push(c) }}let other = []let alt = hlSyntax(gen, key, n.alternate) // null when there is no elseif (alt != null) {if (alt.tag == 'view_if') {other.push(node(key, n.alternate, path, inFor, rows))} else {for (h of alt.entries) {let c = node(key, h, path, inFor, rows)if (c != null) { other.push(c) }}}}// A BRANCH CONDITION IS A READ (COMPONENTS: a member or a loop path).// Anything else came back null here and the branch rendered nothing, on the// server and after hydration, with no word said (ticket #17: `if (!flag)`).let cond = ref(key, n.condition, rows)// …or a COMPARISON of such a read with a literal (`x != ''`, `row.state == 'open'`,// `count > 3`), or a `!` of a read or of one (hybriel#287): the same expression// tree a View text holds, so the server and the browser evaluate one thingif (cond == null && simpleCondition(key, n.condition, rows)) {let names = []cond = { k = 'expr'; x = exprTree(key, n.condition, rows, &names); names = names; }}if (cond == null) {let c = hlSyntax(gen, key, n.condition)hlError("hl:web: " + baseName(pathOf(key)) + ':' + c.line + ':' + c.col + " — a View `if` takes a member, a field path or a `for` row variable as its condition, and this one is an expression: declare it at the root of " + baseName(pathOf(key)) + " (`showIt = !flag`) and write `if (showIt)`")}return { k = 'if'; cond = cond; then = then; other = other; site = baseName(pathOf(key)) + ':' + n.line + ':' + n.col; }}if (n.tag == 'member_expression') {// `p.title` — a field path off a member or a row variablelet r = ref(key, handle, rows)if (r != null) { return r }}if (n.tag == 'binary_expression' || n.tag == 'unary_expression' || n.tag == 'conditional_expression') {// AN EXPRESSION IN A VIEW: its tree, and the names it reads (what repaints it)let names = []let x = exprTree(key, handle, rows, &names)return { k = 'expr'; x = x; names = names; }}if (n.tag == 'on_statement') {// a DOM event handled by the literal that carries it: the browser finds the// literal in the instance's View by the path of keys and fires the event at it// THE SITE IS THE HANDLER'S ID: the tables file this handler's write set// under it, and the browser repaints exactly those members when it runs.return { k = 'on'; event = n.event; site = baseName(pathOf(key)) + ':' + n.line + ':' + n.col; }}return { k = 'other'; tag = n.tag; }}// the literal name of a `slot { name = 'side' … }` region, null for anything elseregionName(key, v) {for (h of v.entries) {let e = hlSyntax(gen, key, h)if (e.tag == 'object_property' && e.key == 'name') {let val = hlSyntax(gen, key, e.value)if (val.tag == 'literal' && val.kind == 'string') { return val.text }}}return null}// A COMPONENT HAS EXACTLY ONE SLOT (COMPONENTS §2 table, §12): a second one rendered the// child a second time, with no word said (mission 322 row 4)oneSlot(key, n) {let here = baseName(pathOf(key)) + ':' + n.line + ':' + n.colif (slotAt[key] != null) {hlError("hl:web: " + here + " — a second `slot` in this View (the first is at " + slotAt[key] + "): a component has exactly one slot, where the page it wraps or the fill it is given renders")}slotAt[key] = herereturn null}isMember(key, name) {for (m of hlMembers(gen, key)) { if (m.name == name) { return true } }return false}// THE READ OF A BARE NAME IN A VIEW — wherever the name stands. A text child, an// attribute's value and a reference-site binding are ONE lookup with ONE refusal://// a `for` row variable standing around the read → read at render, from the row// a member of this file → read at render, from the instance// a name this file imports by BRACE → a STATIC of another file:// constant-folded here, at build// anything else → the located refusal (checkRead)//// An ATTRIBUTE used to skip the middle two and record every name as a member read,// so `a { href = brandHref }` on a braced import asked the instance for a member it// does not have and the renderer raised error.UndefinedProperty with view.hl's line// and nothing of the app's — while the same name as a TEXT CHILD rendered fine// (creator, routger migration W8). A read is a read; where it stands decides// nothing about what it names.nameRead(key, name, rows, at) {if (rows != null && rows.includes(name)) { return { k = 'member'; name = name; } }if (isMember(key, name)) { return { k = 'member'; name = name; } }// A BRACED IMPORT FOLDS EVEN WHEN ITS VALUE IS NULL: the name resolved, so the// read is answered here and never reaches the instance (a null static used to// fall through to a member read and raise the same UndefinedProperty).if (importsName(key, name)) {let folded = importedStatic(key, name)// THE VALUE AS WELL AS THE TEXT: an attribute and a text child want the text,// and a reference binding wants the value the author's file declared (§12)return { k = 'text'; text = folded == null ? '' : '' + folded; kind = 'folded'; value = folded; }}checkRead(key, name, rows, at)return { k = 'member'; name = name; }}// A VIEW READS ONLY WHAT ITS FILE DECLARES. A name that is neither a member of// this class, nor a static it imports by brace, nor a `for` row variable standing// around this read, is a typo or a missing declaration — refused HERE, at the// build of the tree (boot), naming the file and the line, instead of a 500 out of// the renderer with the language's UndefinedProperty and no line of the app's.checkRead(key, name, rows, n) {if (rows != null && rows.includes(name)) { return null }if (isMember(key, name)) { return null }if (importsName(key, name)) { return null }let hint = name == 'session' ? "`session = null` to receive the connection's session" : name == 'host' ? "`host = null` to receive the request's host" : name == 'headers' ? "`headers = null` to receive the request's headers" : name == 'route' ? "`route = null` to receive the matched route" : "`" + name + " = null`"hlError("hl:web: " + baseName(pathOf(key)) + ':' + n.line + ':' + n.col + " — the View reads '" + name + "', which this file declares nowhere: declare it at the file's root (" + hint + "), or write the name it was meant to be")}// does this file import that name by brace from another file?\* `--port=N` or `--port N` among the program's arguments, or null. *\portArgument() {let given = args()let i = 0while (i < given.length) {let a = given[i]let text = nullif (a.startsWith('--port=')) {text = a.slice(7)} else if (a == '--port' && i + 1 < given.length) {text = given[i + 1]}if (text != null) {let digits = text.length > 0 && text.length <= 5let b = toBytes(text)let k = 0while (k < b.length) {if (b[k] < 48 || b[k] > 57) { digits = false }k = k + 1}if (!digits || toNumber(text) > 65535) {hlError("hl:web: invalid --port value '" + text + "' — a port is a number 0-65535")}return toNumber(text)}i = i + 1}return null}importsName(key, name) {for (imp of graph.files[key].imports) {if (imp.key != null && memberOfImport(imp, name) != null) { return true }}return false}// the member of the imported file that the name `name` is bound to here, or null:// the name itself, or what `import { a as name }` selected (#142)memberOfImport(imp, name) {if (imp.locals == null) { return imp.names.includes(name) ? name : null }let i = 0while (i < imp.locals.length) {if (imp.locals[i] == name) { return imp.names[i] }i = i + 1}return null}// the value of a static this file imports by brace from another .hl file, or null —// read off an instance of that file (a class value takes no computed index, an// instance does; the file is constructed once, its statics were evaluated at load)importedStatic(key, name) {for (imp of graph.files[key].imports) {let member = imp.key != null ? memberOfImport(imp, name) : nullif (member != null) {if (staticHolders[imp.key] == null) { staticHolders[imp.key] = construct(imp.key, constructionArgs(imp.key, {}, anonSession(), null, null)) }return staticHolders[imp.key][member]}}return null}// THE TREE OF A VIEW EXPRESSION: operators, literals and reads — evaluated by view.hl's// `evalExpr`, with the language's own operators. `names` collects the members it reads.exprTree(key, handle, rows, &names) {let n = hlSyntax(gen, key, handle)if (n.tag == 'literal') { return { k = 'text'; text = n.text; kind = n.kind; } }if (n.tag == 'identifier') {let r = nameRead(key, n.name, rows, n)if (r.k == 'member' && !names.includes(r.name)) { names.push(r.name) }return r}if (n.tag == 'member_expression' && !n.computed) {let r = ref(key, handle, rows)if (r != null) {if (!names.includes(r.name)) { names.push(r.name) }return r}}if (n.tag == 'binary_expression') {return { k = 'bin'; op = n.operator; l = exprTree(key, n.left, rows, &names); r = exprTree(key, n.right, rows, &names); }}if (n.tag == 'unary_expression') {return { k = 'un'; op = n.operator; x = exprTree(key, n.operand, rows, &names); }}if (n.tag == 'conditional_expression') {return { k = 'cond'; c = exprTree(key, n.condition, rows, &names); a = exprTree(key, n.consequent, rows, &names); b = exprTree(key, n.alternate, rows, &names); }}hlError("hl:web: " + baseName(pathOf(key)) + ':' + n.line + ':' + n.col + " — a View expression holds names, literals, member paths and operators; a " + n.tag + " is none of those — declare it at the root of " + baseName(pathOf(key)) + " and write its name")}// is this a View `if` condition beyond a plain read that is still allowed (hybriel#287): a// comparison of a read (member, field path, row variable) with a literal, either side, or// a `!` of a read or of such a comparisonsimpleCondition(key, handle, rows) {let n = hlSyntax(gen, key, handle)if (n == null) { return false }if (n.tag == 'unary_expression') {if (n.operator != 'logical_not') { return false }return ref(key, n.operand, rows) != null || simpleCondition(key, n.operand, rows)}if (n.tag != 'binary_expression') { return false }if (!['equal', 'not_equal', 'less_than', 'less_equal', 'greater_than', 'greater_equal'].includes(n.operator)) { return false }let l = hlSyntax(gen, key, n.left)let r = hlSyntax(gen, key, n.right)if (l == null || r == null) { return false }if (l.tag == 'literal') { return r.tag != 'literal' && ref(key, n.right, rows) != null }if (r.tag == 'literal') { return ref(key, n.left, rows) != null }return false}// a READ in the View: a member (`title`), or a field path (`p.title`) whose root// is a member or a `for` row variable — the client decides which at render timeref(key, handle, rows) {let n = hlSyntax(gen, key, handle)if (n.tag == 'identifier') { checkRead(key, n.name, rows, n) return { k = 'member'; name = n.name; } }// A LIST WRITTEN IN PLACE (`for (n of [1, 2])`) is a literal, read as its value: the// same folded 'text' node a folded static is, so every reader takes it the way it takes// that one. Its entries are literals — anything else has no value before a read.if (n.tag == 'array_expression') {let items = []for (e of n.elements) {let el = hlSyntax(gen, key, e)if (el == null || el.tag != 'literal') {hlError("hl:web: " + baseName(pathOf(key)) + ':' + n.line + ':' + n.col + " — a list written in a View can hold literals only; declare it as a member to loop over anything else")}items.push(viewRead.literalValue(el.kind, el.text))}return { k = 'text'; text = ''; kind = 'folded'; value = items; }}if (n.tag == 'member_expression' && !n.computed) {let obj = hlSyntax(gen, key, n.object)let prop = hlSyntax(gen, key, n.property)if (obj.tag == 'identifier') { checkRead(key, obj.name, rows, obj) return { k = 'field'; name = obj.name; path = [prop.name]; } }let inner = ref(key, n.object, rows)if (inner != null && inner.k == 'field') {let path = inner.path.slice(0)path.push(prop.name)return { k = 'field'; name = inner.name; path = path; }}}return null}// THE COMPOSED CHILD: an entry named after a class the file imports, whose file// has a View. `Child { count = count on done(v) { … } }` — the entries are the// BINDINGS (host values handed to the child's construction as named arguments)// and the reference-site handlers. The graph says which name is which file.componentKeyOf(key, name) {for (imp of graph.files[key].imports) {if (imp.default == name && imp.key != null && viewHandle(imp.key) != 0) { return imp.key }}return null}// THE REFERENCE'S SITE IS IN ITS PATH. A path of class names alone made two// references of one class under one parent (`body/Card` twice) the SAME node key,// so both collapsed onto one mount and one of the two fills was lost. A reference// is a construction: each one is its own mount, so each one is its own path.componentStep(cls, at) {return cls + '@' + at.line + ':' + at.col}// is this entry a `Style.rule` reference? (the `Style` of THIS file, by name)styleRef(key, e) {let obj = hlSyntax(gen, key, e.object)return obj.tag == 'identifier' && obj.name == 'Style'}// THE REFERENCE'S POSITIONAL SIGNATURE (§12: "a reference is a construction, so its// POSITIONAL entries bind to the class's declared properties in declaration order —// the same rule `new X(a, b)` follows").//// MEASURED, not guessed (2026-09-13, this worker): `new X(a, b, …)` fills the class's// root PROPERTY DECLARATIONS in SOURCE ORDER, one slot each — `on` handlers and// methods take no slot, and `hlMembers` returns exactly that list in exactly that// order, so the tree builder reads the signature straight off it. Three of those// declarations are not properties of the COMPOSITION and are left out here://// `View` and `Style` — what the component renders and paints WITH, not what it is// constructed from. The language does give them a slot (a// bare `new` binds them), but §12 says `Card { "text" }` with// no declared property takes its text as FILL, and a// component always declares a View: counting it would make// the positional-literal fill unreachable in every component// there is.// `slot` — the late-bound child, not state (§12); and with the fill// rendered where the child places it the two readings emit// the same HTML anyway.// every `static` — a static belongs to the CLASS (§12 build-time constants), so// a reference cannot seed one for every other reference.//// A NAMED assignment does NOT free its slot — measured: `new Q('n1', beta = 'B', 'n2')`// puts 'n2' in the SECOND declaration and 'B' in beta. It is applied AFTER the// positional ones and wins, which is why the positional bindings are emitted first// below. (COMPONENTS.md:711 reads "a property the reference also assigns by name is// not in the signature"; the interpreter says otherwise and the parenthetical in the// same line — "named is applied after positional; the name wins, as in `new`" — is// what this follows.)positionalSignature(key) {let out = []for (m of hlMembers(gen, key)) {if (!m.isStatic && m.name != 'View' && m.name != 'Style' && m.name != 'slot') { out.push(m.name) }}return out}component(key, cls, childKey, v, at, path, inFor, rows) {let bindings = []let positional = []let ons = []let fill = []let here = path.slice(0)here.push(componentStep(cls, at))let sig = positionalSignature(childKey)let taken = 0if (v != null) {for (h of v.entries) {let e = hlSyntax(gen, key, h)if (e.tag == 'object_property') {let val = hlSyntax(gen, key, e.value)// A BINDING NAMES A DECLARED MEMBER OF THE CHILD (COMPONENTS §12): the value// otherwise went into the construction and nowhere, with no word said// (mission 322 row 12). An element entry is the fill, not a binding.if (val.tag != 'object_expression' && !isMember(childKey, e.key)) {hlError("hl:web: " + baseName(pathOf(key)) + ':' + e.line + ':' + e.col + " — " + cls + " has no member '" + e.key + "' to bind: " + baseName(pathOf(childKey)) + " declares " + positionalSignature(childKey).join(', '))}// A LITERAL ON A REFERENCE KEEPS ITS TYPE (§12 "typed, not stringified"):// the binding carries the literal's KIND, and `view.refValue` turns the// pair into the value the child's member is given. Written as text alone,// `Level2 { n = 1 }` handed the child the String "1" and `n * 97` refused// (measured 2026-09-14, demo-nested wall 3).if (val.tag == 'literal') { bindings.push({ name = e.key; text = val.text; kind = val.kind; }) }else if (val.tag == 'identifier') {// a binding is a read at the reference site, so it is the same lookuplet r = nameRead(key, val.name, rows, val)// …and a folded static crosses as its VALUE, for the same reasonif (r.k == 'text') { bindings.push({ name = e.key; text = r.text; kind = 'folded'; value = r.value; }) }else { bindings.push({ name = e.key; member = val.name; }) }}else if (val.tag == 'member_expression') { bindings.push({ name = e.key; ref = ref(key, e.value, rows); }) }else {// `Card { span { … } }` — an element entry is not a binding, it is the FILLlet c = node(key, h, here, inFor, rows)// …and an EXPRESSION is neither, so it is refused rather than dropped:// the same rule an attribute follows (mission 312 wall 4).if (c == null) {hlError("hl:web: " + baseName(pathOf(key)) + ':' + val.line + ':' + val.col + " — '" + e.key + "' is bound to an expression on the reference " + cls + ", and a binding is a literal, a member or a field path: declare the expression at the root of " + baseName(pathOf(key)) + " (`" + e.key + "Value = …`) and write `" + e.key + " = " + e.key + "Value`")}fill.push(c)}} else if (e.tag == 'on_statement') {// A HANDLER WRITTEN ON A REFERENCE IS THE HOST'S, bound on the child's ROOT// element. The reference is a literal of THIS file's View, so its behaviour// is minted from THIS file's site and its body reaches this file through the// owner rule — the same path an element's own handler takes. The child's own// handler on that element is not replaced: both are listeners on one element// and both run, the child's first, because it was bound when the child's tree// was claimed. (Until 2026-09-13 the event was collected here and dropped: a// reference with `on submit` never bound, and a form submitted natively.)// …AND ITS SITE, because the tables file this handler's write set// under it: the browser repaints exactly what it wrote (mission 309).ons.push({ event = e.event; site = baseName(pathOf(key)) + ':' + e.line + ':' + e.col; })} else if (e.tag == 'member_expression' && !e.computed && styleRef(key, e)) {// a `Style.rule` written on a reference: the reference renders no element// of its own, so there is nothing for the class to land on (§12)hlError("hl:web: " + baseName(pathOf(key)) + ':' + at.line + ':' + at.col + " — a Style rule cannot be written on the component reference '" + cls + "': a reference renders no element of its own. Write the rule on an element inside " + baseName(pathOf(childKey)) + ", or name a '#" + cls + "' local rule in this file")} else {// AN ORDERED ENTRY. A literal or a read is the next declared property's// value while the signature has room — `Button { "SD" }` is `Button// { label = "SD" }` — and everything else, plus everything that EXCEEDS// the signature, is the FILL: a fragment of THIS file's View, with its// reads, its handlers and its `for` rows (§12 "host content").let c = node(key, h, here, inFor, rows)if (c != null) {if (taken < sig.length && (c.k == 'text' || c.k == 'member' || c.k == 'field')) {// the same rule as the named form above: a literal keeps its kind and a// folded static crosses as its valueif (c.k == 'text') { positional.push({ name = sig[taken]; text = c.text; kind = c.kind; value = c.value; }) }else if (c.k == 'member') { positional.push({ name = sig[taken]; member = c.name; }) }else { positional.push({ name = sig[taken]; ref = c; }) }taken = taken + 1} else { fill.push(c) }}}}}// THE NAMED ASSIGNMENTS COME LAST, so the name wins over the positional entry that// landed on the same property (measured: that is what `new` does)let allBindings = []for (b of positional) { allBindings.push(b) }for (b of bindings) { allBindings.push(b) }bindings = allBindings// FILLING WHAT PLACES NO SLOT IS A LOCATED ERROR (§12): the child would drop the// content silently, which is exactly the bug this rule was written for.if (fill.length > 0 && !isMember(childKey, 'slot')) {hlError("hl:web: " + baseName(pathOf(key)) + ':' + at.line + ':' + at.col + " — " + cls + " is filled here, but " + baseName(pathOf(childKey)) + " declares no 'slot' to fill: declare `slot = null` there and place `slot` in its View, or write the content outside the reference")}if (fill.length > 0) {if (fillTags[childKey] == null) { fillTags[childKey] = [] }noteFillTags(childKey, fill)}let classes = []if (styleRules(key).includes('#' + cls) && !viewIds(key).includes(view.kebab(cls))) {classes.push(view.localClass(key))for (t of rootTags(childKey)) { noteRef(key, t, '#' + cls) }}// THE NODE NAMES ITS CHILD, it does not carry it. What the browser needs to build// a child the server never mounted — the module url and the View tree — stands// ONCE in the component's own module (its blueprint, W195), keyed by this `key`.// The node used to carry that pair itself, and only when it stood inside a `for`:
Only the first lines are shown.
Branches
Latest commits
- 10f8a8c8Merge branch 'code-order' into mainJukebox
- 204fc828Merge branch 'day72' into mainJukebox
- 95f5faae|||PR jukebox#7 Drop needless let declarationsmre
- 33072bb5|||PR Record day72 gates and Chrome proofmre
- 95f2cd73|||PR Use typed parent methods for screen playback and local server facesmre
- 6422a020Sync media-player at 51c3818mre
- b582ba1cVendor complete Hybriel day72 plugin setmre
- 02dccbc9Merge branch 'records-1119' into mainJukebox
- a39e1c23|||PR Records: missions 013-015, reconnect fix livemre
- fc7db075Merge branch 'reconnect-retry' into mainJukebox
- ac6f4c6fL2: plain declaration for a in pickedNextmre
- 2f335086Review round 2: only an explicit queue pick drops pend (not the automatic advance); jb23 records every source changemre
- 3eb6695fReview fixes: action generation, queue pick clears pend, Previous/Next retry the decided request, typed handlersmre
- 7a53c0c2|||PR A tap lost to a dead socket plays after reconnect (mission 015)mre
- 1f0cd77bMerge branch 'records-day41' into mainJukebox
- 67be229f|||PR Records: day41 live (PR #4), mission 012, statusmre
- 0bb027daconductor: caramboleyo is the user, not owner/creatorApollo
- 04f5d9d5Merge branch 'day41' into mainJukebox
- 8ed6da45|||PR README: media-player pin df9e7dfmre
- d5d45fc3|||PR media-player df9e7df (repeat-one fix), sync pin and SOURCEmre