From 55c658aef5d863a1bcb2e8a9822bce603a7292ee Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 6 Dec 2026 10:00:41 +0000 Subject: [PATCH 01/30] compile.ts: put misplaced doc comments on their declarations Comment-only: nine doc comments sat above the wrong declaration (hasBase's above stateReaders, makeCode's above bodyOf, frozenPlain's above cloneArg, ...). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AjKzdxQfw4ecAQCBmwDk7t --- src/compiler/compile.ts | 54 ++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/src/compiler/compile.ts b/src/compiler/compile.ts index a8b631c7..a1e11290 100644 --- a/src/compiler/compile.ts +++ b/src/compiler/compile.ts @@ -14401,7 +14401,6 @@ class Compiler { // ---- helpers -/** Whether the document has a `` (links then resolve against it). */ /** * For each state object (`$s3`) and field (`$s3.k`) the functions read, the distinct function sources * that read it; the object itself only where it is not followed by `.`, `$` or a word character, a @@ -14424,6 +14423,7 @@ export function stateReaders(fns: readonly string[]): Map> { return out; } +/** Whether the document has a `` (links then resolve against it). */ function hasBase(n: P5Parent): boolean { return n.childNodes.some((c) => isElement(c) && ((c.tagName === 'base' && attr(c, 'href') != null) || hasBase(c.tagName === 'template' ? (c as any).content : c))); } @@ -14556,7 +14556,6 @@ function samePage(p: HrefPrefix, patterns: string[]): boolean { }); } -/** Flags for the runtime: `e` when the expression reads `$el`, `i` when it reads a loop index. */ /** The AST of an object-literal entry's value (by its offset), for the selection pattern. */ const entryValue = (r: ExprResult, e: { offset: number }): Node | undefined => { const props = (r.ast as import('acorn').ObjectExpression | null)?.properties; @@ -14614,6 +14613,7 @@ function mentions(n: unknown, names: Set): boolean { for (const key in node) if (key !== 'type' && key !== 'start' && key !== 'end' && key !== 'loc' && typeof node[key] === 'object' && mentions(node[key], names)) return true; return false; } +/** Flags for the runtime: `e` when the expression reads `$el`, `i` when it reads a loop index. */ const usesEl = (r: ExprResult): Pick => ({ ...(r.usesEl ? { e: 1 as const } : {}), ...(r.usesIndex ? { i: 1 as const } : {}) }); function binding(b: Binding): Binding { @@ -14876,6 +14876,11 @@ function lookup(nodes: NodeDef[]): { decls: string[]; els: string[] } { const SIMPLE_KINDS = new Set(['text', 'attr', 'class', 'style', 'show', 'prop', 'on']); const WRITER: Record = { text: 't', attr: 'a', class: 'c', style: 's', show: 'h', prop: 'p' }; +/** A value function's expression, as `makeCode` inlines it (`($) => (x)` → `x`). */ +function bodyOf(code: string): string { + return code.startsWith('($) => (') && code.endsWith(')') ? code.slice('($) => ('.length, -1) : code; +} + /** * The creation function of a simple row template (see `TemplateDef.make`): the lookup of the elements * with value bindings (handlers bind on an element's first event), then every @@ -14884,11 +14889,6 @@ const WRITER: Record = { text: 't', attr: 'a', class: 'c', style * attribute, so a false first value has nothing to remove otherwise). Null when the template is not * simple, a binding reads `$el`, or an expression is not of the value form. */ -/** A value function's expression, as `makeCode` inlines it (`($) => (x)` → `x`). */ -function bodyOf(code: string): string { - return code.startsWith('($) => (') && code.endsWith(')') ? code.slice('($) => ('.length, -1) : code; -} - export function makeCode(nodes: NodeDef[], fns: string[]): string | null { if (!nodes.every((nd) => !nd.dl && nd.state == null && nd.b.every((b) => SIMPLE_KINDS.has(b.k) && !b.e))) return null; // only elements with value bindings: a handler binds on its element's first event @@ -15125,6 +15125,12 @@ const UNMEASURED = -2; /** the height of children: one more than the highest object among them, `UNMEASURED` if one is */ const above = (h: number, ch: number) => (h === UNMEASURED || ch === UNMEASURED ? UNMEASURED : Math.max(h, ch + 1)); +/** + * A folded call's argument as the build keeps it for its cross check (`foldLog`): an object copied, a string or another + * primitive as it is (a copy of one is the same value, and the post a call reads would be kept twice until the end) + */ +export const cloneArg = (x: unknown): unknown => (x !== null && typeof x === 'object' ? structuredClone(x) : x); + /** * Whether `v` is what `deepFreeze(structuredClone(v))` would make of it, as it is: frozen at every depth, every object a * plain object or a dense array of its realm's (`Object.prototype`, `Array.prototype`), every own property a string @@ -15132,12 +15138,6 @@ const above = (h: number, ch: number) => (h === UNMEASURED || ch === UNMEASURED * keeps one, but the purity check's `JSON.stringify` throws on it). What it walks is marked frozen at every depth * (`DEEP_FROZEN`), as `deepFreeze` marks its copy, once the whole of it is known to be. */ -/** - * A folded call's argument as the build keeps it for its cross check (`foldLog`): an object copied, a string or another - * primitive as it is (a copy of one is the same value, and the post a call reads would be kept twice until the end) - */ -export const cloneArg = (x: unknown): unknown => (x !== null && typeof x === 'object' ? structuredClone(x) : x); - export function frozenPlain(v: object): boolean { // (with each object's height, `DEEP_FROZEN`: -1 is not plain) const done = new Map(), path = new Set(), all: object[] = []; @@ -15452,7 +15452,6 @@ function unitCands(u: BuildUnit, tplEls: Map, fns: string[]) return c; } -/** a binding `prerender` evaluates: `tpl`, in a template's content, written there only when it can never change; `if`, a condition decided for a second pass; `for`, a loop unrolled in it */ /** * The state fields (`$s.`) a compiled expression (`($) => (…)`) reads, when it is made of nothing but whole * fields of states, literals and operators. Null for anything else: a member of what a field holds, a call, a function, @@ -15484,6 +15483,7 @@ export function fieldsOnly(code: string): string[] | null { }; return ok(ast.body) ? [...fields] : null; } +/** a binding `prerender` evaluates: `tpl`, in a template's content, written there only when it can never change; `if`, a condition decided for a second pass; `for`, a loop unrolled in it */ type EvalCand = { el: P5Element; b: Binding; f: number; tpl?: true; if?: true; for?: true }; /** what the worklist reads of the program, by node, binding and case (`worklist`): asked once per evaluation, or per kept template */ @@ -15528,10 +15528,10 @@ export function renderOn(): boolean { return renderForced ?? proc?.env.SN_RENDER /** the render audit's compile without rendering (`compileParts`) */ let renderForced: boolean | null = null; -/** what `rowRenderer` did in this process, by reason, printed at exit with `SN_RENDER_LOG=1` */ /** (measurement, stage5-b1.md: what a second pass applies, by kind and place; null when nothing records) */ let APPLIED: Set | null = null; function applied(kind: string) { APPLIED?.add(kind); } +/** what `rowRenderer` did in this process, by reason, printed at exit with `SN_RENDER_LOG=1` */ export const RENDER_STATS = { rendered: 0, rows: 0, spliced: 0, fallback: new Map() }; let renderLogged = false; function renderStat(why: string | null, rows: number) { @@ -15582,12 +15582,12 @@ function paintable(el: P5Element, b: Binding): boolean { return !(b.k === 'text' && el.childNodes.some(isElement)); } +export type Kind = 'text' | 'attr' | 'class' | 'style' | 'show' | 'checked' | 'value'; + /** * What the runtime would write for value `v` of binding `b` on `el`, as `[kind, value]`, or FAIL * when it cannot be written ahead (an object, a refused URL or style, a select). */ -export type Kind = 'text' | 'attr' | 'class' | 'style' | 'show' | 'checked' | 'value'; - function firstPaintValue(el: P5Element, b: Binding, v: unknown, schemes: Set): [Kind, unknown] | typeof FAIL { switch (b.k) { case 'text': return isPrimitive(v) ? ['text', '' + (v ?? '')] : FAIL; @@ -15655,16 +15655,6 @@ export function writeFirstPaint(el: P5Element, kind: Kind, name: string | null, } } -/** - * The style bindings of one element a rendered row made (`fresh`, its attribute list its own), written one after another - * as `writeFirstPaint(el, 'style', name, v, true)` writes each, without the element's whole style split and joined again - * at every one: sinter-mail's components write 55 an element, most of them `null`. The declarations are kept as a list - * with each one's property, which the next write filters as `writeFirstPaint` filters the split value: the split of a - * join of declarations that have no `;` and no space at either end is the list itself, so only a declaration that has is - * split again. The attribute is added and removed where `writeFirstPaint` adds and removes it (its place among the - * element's attributes), and its value written at the end (`done`): nothing reads it in between, as nothing else writes - * it (an element with a `data-sn-attr` of `style` is written one write at a time). `SN_STYLE_BATCH=0`: one at a time. - */ /** * a `