@llui/compiler 0.4.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/collect-deps.d.ts.map +1 -1
- package/dist/collect-deps.js +14 -3
- package/dist/collect-deps.js.map +1 -1
- package/dist/lint-modules.d.ts.map +1 -1
- package/dist/lint-modules.js +4 -0
- package/dist/lint-modules.js.map +1 -1
- package/dist/modules/no-repeated-item-current.d.ts +3 -0
- package/dist/modules/no-repeated-item-current.d.ts.map +1 -0
- package/dist/modules/no-repeated-item-current.js +164 -0
- package/dist/modules/no-repeated-item-current.js.map +1 -0
- package/dist/modules/no-sample-in-event-handler.d.ts +3 -0
- package/dist/modules/no-sample-in-event-handler.d.ts.map +1 -0
- package/dist/modules/no-sample-in-event-handler.js +101 -0
- package/dist/modules/no-sample-in-event-handler.js.map +1 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"collect-deps.d.ts","sourceRoot":"","sources":["../src/collect-deps.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAA;AAyG3B;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,2BAA2B,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,GAAG,GAAG,CAAC,MAAM,CAAC,CAuBlF;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,CAwBhF;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,MAAM,EACd,UAAU,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,GAC/B;IACD,EAAE,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACvB,EAAE,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CACxB,CAsCA;AAeD;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,OAAO,
|
|
1
|
+
{"version":3,"file":"collect-deps.d.ts","sourceRoot":"","sources":["../src/collect-deps.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAA;AAyG3B;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,2BAA2B,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,GAAG,GAAG,CAAC,MAAM,CAAC,CAuBlF;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,CAwBhF;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,MAAM,EACd,UAAU,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,GAC/B;IACD,EAAE,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACvB,EAAE,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CACxB,CAsCA;AAeD;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,OAAO,CA6DzD"}
|
package/dist/collect-deps.js
CHANGED
|
@@ -279,9 +279,20 @@ export function isReactiveAccessor(node) {
|
|
|
279
279
|
if (!ancestor)
|
|
280
280
|
return false;
|
|
281
281
|
const callExpr = ancestor;
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
282
|
+
// Bare identifier: `scope({on: …})`, `div({title: …})`, etc.
|
|
283
|
+
if (ts.isIdentifier(callExpr.expression)) {
|
|
284
|
+
return REACTIVE_API_NAMES.has(callExpr.expression.text);
|
|
285
|
+
}
|
|
286
|
+
// Method-call form: `h.scope({on: …})`, `h.show({when: …})`, etc.
|
|
287
|
+
// The docs and View bag promote this shape; without recognizing it
|
|
288
|
+
// here, paths read ONLY through a structural primitive's
|
|
289
|
+
// `on`/`when`/`items` accessor never enter `__prefixes`, so the
|
|
290
|
+
// runtime dirty mask can't see changes to those fields and the
|
|
291
|
+
// structural block silently fails to reconcile.
|
|
292
|
+
if (ts.isPropertyAccessExpression(callExpr.expression)) {
|
|
293
|
+
return REACTIVE_API_NAMES.has(callExpr.expression.name.text);
|
|
294
|
+
}
|
|
295
|
+
return false;
|
|
285
296
|
}
|
|
286
297
|
}
|
|
287
298
|
return false;
|
package/dist/collect-deps.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"collect-deps.js","sourceRoot":"","sources":["../src/collect-deps.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAA;AAC3B,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAA;AAE5D;;;;;;;GAOG;AACH,MAAM,sBAAsB,GAAG,IAAI,GAAG,CAAC,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,CAAC,CAAC,CAAA;AAExF;;;;;;;;;;;;;;;GAeG;AACH,SAAS,wBAAwB,CAC/B,IAAa,EACb,cAAsB,EACtB,MAA6F;IAE7F,SAAS,KAAK,CAAC,IAAa;QAC1B,IAAI,EAAE,CAAC,gBAAgB,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;YAClE,MAAM,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,CAAA;YACjC,IAAI,CAAC,sBAAsB,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;gBACtC,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAA;gBAC9B,IAAI,IAAI,IAAI,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,KAAK,cAAc,EAAE,CAAC;oBAClE,MAAM,QAAQ,GAAG,mBAAmB,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CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IACpC,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AACxB,CAAC;AAED;;GAEG;AACH,SAAS,oBAAoB,CAAC,IAAgC,EAAE,SAAiB;IAC/E,IAAI,CAAC,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QAC5E,OAAO,IAAI,CAAA;IACb,CAAC;IAED,IAAI,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,kBAAkB,CAAC,EAAE,CAAC;QAChD,OAAO,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAA;IACrC,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC","sourcesContent":["import ts from 'typescript'\nimport { resolveAccessorBody } from './accessor-resolver.js'\n\n/**\n * Names whose first arg is itself a reactive accessor (the existing\n * arrow walker handles them) or which are explicitly excluded\n * (sample/item read state imperatively / per-row, not as state\n * accessors). When a delegating accessor's body contains a call to one\n * of these, we don't follow it — recursion is reserved for \"this is\n * just a thin wrapper that hands the state to another local helper.\"\n */\nconst NON_DELEGATION_HELPERS = new Set(['sample', 'item', 'memo', 'text', 'unsafeHtml'])\n\n/**\n * Walk a delegating accessor's body looking for calls to OTHER local\n * functions that take the state param verbatim — `helper(s)` where\n * `s` matches the outer accessor's param name. For each, hand the\n * resolved declaration back so the caller can recurse into its body.\n *\n * Skips:\n * - Framework helpers (`memo`, `text`, etc.) — their arrow args are\n * visited by the top-level arrow walker; we'd double-count.\n * - Method calls (`s.items.filter(...)`) — the callee is a builtin,\n * not a local function we can resolve.\n * - Nested function bodies — params inside a `(item) => …` shadow\n * ours, so a `helper(s)` deep in there isn't (necessarily)\n * handing OUR state in. Conservative: don't recurse through\n * lambda boundaries.\n */\nfunction visitTopLevelDelegations(\n body: ts.Node,\n stateParamName: string,\n follow: (resolved: ts.ArrowFunction | ts.FunctionExpression | ts.FunctionDeclaration) => void,\n): void {\n function visit(node: ts.Node): void {\n if (ts.isCallExpression(node) && ts.isIdentifier(node.expression)) {\n const name = node.expression.text\n if (!NON_DELEGATION_HELPERS.has(name)) {\n const arg0 = node.arguments[0]\n if (arg0 && ts.isIdentifier(arg0) && arg0.text === stateParamName) {\n const resolved = resolveAccessorBody(node.expression)\n if (resolved) follow(resolved)\n }\n }\n }\n // Don't descend into nested function bodies — their params shadow\n // ours, and any call inside them isn't unambiguously delegating\n // our state.\n if (\n ts.isArrowFunction(node) ||\n ts.isFunctionExpression(node) ||\n ts.isFunctionDeclaration(node)\n ) {\n return\n }\n ts.forEachChild(node, visit)\n }\n // If the body itself is a function, there's nothing at the top\n // level to inspect — its own body is a separate scope.\n if (ts.isArrowFunction(body) || ts.isFunctionExpression(body) || ts.isFunctionDeclaration(body)) {\n return\n }\n visit(body)\n}\n\n/**\n * Extract paths from a callable accessor (arrow / fn-expr / fn-decl)\n * into the given set. Recurses through call-delegations to other local\n * helpers so that `(s) => filtered(s)` / `(s) => { void s.x; return\n * inner(s) }` correctly contribute the helper's state-path reads.\n * Without recursion the precise mask under-counts — fields read only\n * via the helper drop off the bitmask, and any sibling reactive\n * accessor that reads them produces a non-zero `dirty` that AND'd with\n * the narrow each.__mask is zero, silently skipping the reconcile.\n *\n * `visited` breaks cycles on mutually-recursive helpers — terminates\n * the walk; doesn't try to be precise about what such helpers read.\n */\nfunction extractAccessorPaths(\n accessor: ts.ArrowFunction | ts.FunctionExpression | ts.FunctionDeclaration,\n paths: Set<string>,\n visited: Set<ts.Node> = new Set(),\n): boolean {\n if (visited.has(accessor)) return false\n visited.add(accessor)\n\n const params = accessor.parameters\n if (params.length !== 1) return false\n const paramName = params[0]!.name\n if (!ts.isIdentifier(paramName)) return false\n if (!accessor.body) return false\n const before = paths.size\n\n extractPaths(accessor.body, paramName.text, '', paths)\n\n // Follow delegations: `(s) => helper(s)` — extract `helper`'s body's\n // state paths too. Reuses the `visited` set across the recursion\n // chain so cycles terminate.\n visitTopLevelDelegations(accessor.body, paramName.text, (resolved) => {\n extractAccessorPaths(resolved, paths, visited)\n })\n\n return paths.size > before\n}\n\n/**\n * Walk the AST and collect every unique state access path referenced by\n * a reactive accessor. A reactive accessor is one of:\n *\n * - An inline arrow / function expression at a reactive position\n * (`text(s => s.count)`, `div({ title: s => s.title })`,\n * `show({ when: s => s.gated })`, etc.).\n * - An Identifier at a reactive position that resolves to a callable\n * in this file — a const-bound arrow / function expression,\n * a hoisted function declaration, or `const x = memo(arrow)`.\n *\n * The second case lets authors refactor a literal arrow into a named\n * helper without losing the reactive-mask optimization (a precise mask\n * for `__dirty` and structural-primitive `__mask`). Without it, the\n * runtime falls back to FULL_MASK — correct, but every binding fires\n * on every state change.\n *\n * Shared by the bit-assignment path (`collectDeps`, below) and the\n * `diagnostics.ts` bitmask-overflow warning.\n */\nexport function collectStatePathsFromSource(sourceFile: ts.SourceFile): Set<string> {\n const paths = new Set<string>()\n\n function visit(node: ts.Node): void {\n // Inline arrow / function expression at a reactive position.\n if (ts.isArrowFunction(node) || ts.isFunctionExpression(node)) {\n if (isReactiveAccessor(node)) extractAccessorPaths(node, paths)\n }\n\n // Identifier at a reactive position — resolve to its declaration\n // and extract paths from the resolved body. Skip identifiers\n // imported from elsewhere (resolver returns null) — there's no\n // body to scan, runtime falls back to FULL_MASK.\n if (ts.isIdentifier(node) && isReactiveAccessor(node)) {\n const resolved = resolveAccessorBody(node)\n if (resolved) extractAccessorPaths(resolved, paths)\n }\n\n ts.forEachChild(node, visit)\n }\n\n visit(sourceFile)\n return paths\n}\n\n/**\n * Per-accessor path sets — one entry per reactive arrow/function. Used\n * by the bitmask-overflow diagnostic to find clusters of paths that\n * always fire together (co-occurrence analysis).\n */\nexport function collectAccessorPathSets(sourceFile: ts.SourceFile): Set<string>[] {\n const sets: Set<string>[] = []\n\n function visit(node: ts.Node): void {\n if (ts.isArrowFunction(node) || ts.isFunctionExpression(node)) {\n if (isReactiveAccessor(node)) {\n const set = new Set<string>()\n if (extractAccessorPaths(node, set)) sets.push(set)\n }\n }\n\n if (ts.isIdentifier(node) && isReactiveAccessor(node)) {\n const resolved = resolveAccessorBody(node)\n if (resolved) {\n const set = new Set<string>()\n if (extractAccessorPaths(resolved, set)) sets.push(set)\n }\n }\n\n ts.forEachChild(node, visit)\n }\n\n visit(sourceFile)\n return sets\n}\n\n/**\n * Pre-scan a source file to collect all unique state access paths\n * referenced by reactive accessors (arrow functions in props and text() calls).\n *\n * Returns a pair of maps:\n * - `lo`: paths at bit positions 0..30, with value `1 << position`\n * - `hi`: paths at bit positions 31..61, with value `1 << (position - 31)`\n *\n * Bit positions past 61 collapse to `-1` (FULL_MASK) in the `lo` map and\n * cause every binding reading them to re-evaluate on every cycle. The\n * `bitmask-overflow` lint rule warns the user to restructure state.\n *\n * Components with ≤31 paths see an empty `hi` map; the compiler skips\n * all high-word emit so the generated code is byte-identical to the\n * pre-multi-word baseline.\n */\nexport function collectDeps(\n source: string,\n extraPaths?: ReadonlySet<string>,\n): {\n lo: Map<string, number>\n hi: Map<string, number>\n} {\n const sourceFile = ts.createSourceFile('input.ts', source, ts.ScriptTarget.Latest, true)\n\n // Check if file imports from @llui/dom\n if (!hasLluiImport(sourceFile)) {\n return { lo: new Map(), hi: new Map() }\n }\n\n const paths = collectStatePathsFromSource(sourceFile)\n // Cross-file extension (v2c pipeline integration): the host adapter may\n // pass paths discovered by `crossFileAccessorPaths()` — paths read\n // through in-repo view-helpers in *other* files. Union them with the\n // file-local set before bit assignment. Without this merge the\n // sentinel-`show()` workaround from v2b §1 remains necessary; with\n // it, helpers in other files contribute to the consumer's __prefixes\n // table automatically.\n if (extraPaths) {\n for (const p of extraPaths) paths.add(p)\n }\n\n const lo = new Map<string, number>()\n const hi = new Map<string, number>()\n let index = 0\n for (const path of paths) {\n if (index < 31) {\n lo.set(path, 1 << index)\n } else if (index < 62) {\n hi.set(path, 1 << (index - 31))\n } else {\n // Past 61 paths — graceful FULL_MASK fallback in the low word.\n // Realistic LLui components shouldn't hit this; the lint rule\n // fires well before.\n lo.set(path, -1)\n }\n index++\n }\n\n return { lo, hi }\n}\n\nfunction hasLluiImport(sourceFile: ts.SourceFile): boolean {\n for (const stmt of sourceFile.statements) {\n if (\n ts.isImportDeclaration(stmt) &&\n ts.isStringLiteral(stmt.moduleSpecifier) &&\n stmt.moduleSpecifier.text === '@llui/dom'\n ) {\n return true\n }\n }\n return false\n}\n\n/**\n * Determines if a node is at a reactive-accessor position — either an\n * inline arrow / function expression OR an identifier that's about to\n * be resolved to one. The check is identity-based on `parent.arguments[0]`\n * etc., so the same logic works for both shapes.\n *\n * Exported so the cross-file walker can use the same gate. Without this\n * gate the walker descends into every 1-param arrow in the file —\n * including `onEffect: (bag) => bag.send(...)` — and pollutes\n * `__prefixes` with non-state property names (issue #5, bug 3).\n */\nexport function isReactiveAccessor(node: ts.Node): boolean {\n const parent = node.parent\n\n // text(s => s.count) — first arg to a call\n if (ts.isCallExpression(parent) && parent.arguments[0] === node) {\n // Skip item(t => t.id) — per-item selectors inside each() render.\n // Skip sample(s => s.x) — imperative one-shot read, no binding created\n // (both the top-level import and the destructured-from-h form).\n if (ts.isIdentifier(parent.expression)) {\n if (parent.expression.text === 'item' || parent.expression.text === 'sample') {\n return false\n }\n }\n // Skip array method callbacks: .filter(t => ...), .map(t => ...), .some(t => ...), etc.\n // Allow view-helper primitive calls: h.text(s => ...), h.memo(s => ...)\n if (ts.isPropertyAccessExpression(parent.expression)) {\n const methodName = parent.expression.name.text\n if (methodName === 'text' || methodName === 'memo') {\n return true\n }\n return false\n }\n return true\n }\n\n // div({ title: s => s.title }) — value in a property assignment inside an object literal.\n // Only treat as reactive if the containing call is a known framework API whose\n // properties are reactive accessors. Otherwise user-land helpers like\n // sliceHandler({ narrow: (m) => m.type === ... }) would pollute the path set.\n if (ts.isPropertyAssignment(parent)) {\n const key = parent.name\n if (ts.isIdentifier(key)) {\n // Skip event handlers (onClick, onInput, etc.)\n if (/^on[A-Z]/.test(key.text)) return false\n // Skip each() key function and other non-reactive props\n if (key.text === 'key' || key.text === 'name') return false\n // Walk up to find the enclosing call expression\n let ancestor: ts.Node | undefined = parent.parent // ObjectLiteralExpression\n while (ancestor && !ts.isCallExpression(ancestor)) {\n ancestor = ancestor.parent\n }\n if (!ancestor) return false\n const callExpr = ancestor as ts.CallExpression\n if (!ts.isIdentifier(callExpr.expression)) return false\n return REACTIVE_API_NAMES.has(callExpr.expression.text)\n }\n }\n\n return false\n}\n\n// Framework APIs whose object-literal arguments contain reactive accessors.\n// Arrow functions in property values of these calls are state-tracked.\nconst REACTIVE_API_NAMES = new Set([\n // Element helpers (see ELEMENT_HELPERS in transform.ts — we keep a superset here)\n ...[\n 'a',\n 'abbr',\n 'article',\n 'aside',\n 'b',\n 'blockquote',\n 'br',\n 'button',\n 'canvas',\n 'code',\n 'dd',\n 'details',\n 'dialog',\n 'div',\n 'dl',\n 'dt',\n 'em',\n 'fieldset',\n 'figcaption',\n 'figure',\n 'footer',\n 'form',\n 'h1',\n 'h2',\n 'h3',\n 'h4',\n 'h5',\n 'h6',\n 'header',\n 'hr',\n 'i',\n 'iframe',\n 'img',\n 'input',\n 'label',\n 'legend',\n 'li',\n 'main',\n 'mark',\n 'nav',\n 'ol',\n 'optgroup',\n 'option',\n 'output',\n 'p',\n 'pre',\n 'progress',\n 'section',\n 'select',\n 'small',\n 'span',\n 'strong',\n 'sub',\n 'summary',\n 'sup',\n 'table',\n 'tbody',\n 'td',\n 'textarea',\n 'tfoot',\n 'th',\n 'thead',\n 'time',\n 'tr',\n 'ul',\n 'video',\n ],\n // Structural primitives\n 'each',\n 'branch',\n 'scope',\n 'show',\n 'memo',\n 'portal',\n 'foreign',\n 'child',\n 'errorBoundary',\n // track({ deps: (s) => [...] }) — explicit reactivity declaration for\n // paths static analysis can't infer. The compiler treats `deps` as a\n // reactive accessor so its paths fold into the host component's\n // __prefixes; the call expression is then stripped from emission\n // (see transform.ts). v2b §3.\n 'track',\n])\n\n/**\n * Extract state access paths from an expression body.\n * Handles:\n * - Direct property access: param.field, param.field.subfield\n * - Bracket notation with string literal: param['field']\n */\nfunction extractPaths(node: ts.Node, paramName: string, _prefix: string, paths: Set<string>): void {\n if (ts.isPropertyAccessExpression(node)) {\n // Skip if this is an intermediate in a deeper chain\n if (ts.isPropertyAccessExpression(node.parent)) {\n // handled when the leaf is visited\n }\n // Skip if this is the callee of a method call: s.todos.filter(...)\n else if (ts.isCallExpression(node.parent) && node.parent.expression === node) {\n // It's a method call — record the object, not the method\n // e.g. s.todos.filter(...) → record 'todos', not 'todos.filter'\n if (ts.isPropertyAccessExpression(node.expression)) {\n const chain = resolvePropertyChain(node.expression, paramName)\n if (chain) paths.add(chain)\n }\n } else {\n const chain = resolvePropertyChain(node, paramName)\n if (chain) {\n paths.add(chain)\n }\n }\n }\n\n if (ts.isElementAccessExpression(node)) {\n const chain = resolveElementAccess(node, paramName)\n if (chain) {\n paths.add(chain)\n }\n }\n\n ts.forEachChild(node, (child) => extractPaths(child, paramName, _prefix, paths))\n}\n\n/**\n * Resolve a property access chain like s.user.name to \"user.name\".\n * Returns null if the chain doesn't start with the state parameter.\n * Stops at depth 2.\n */\nfunction resolvePropertyChain(node: ts.PropertyAccessExpression, paramName: string): string | null {\n const parts: string[] = []\n let current: ts.Expression = node\n\n while (ts.isPropertyAccessExpression(current)) {\n parts.unshift(current.name.text)\n current = current.expression\n }\n\n // The root must be the state parameter\n if (!ts.isIdentifier(current) || current.text !== paramName) {\n return null\n }\n\n // Limit to depth 2\n if (parts.length > 2) {\n return parts.slice(0, 2).join('.')\n }\n\n return parts.join('.')\n}\n\n/**\n * Resolve bracket access with string literal: s['count'] → \"count\"\n */\nfunction resolveElementAccess(node: ts.ElementAccessExpression, paramName: string): string | null {\n if (!ts.isIdentifier(node.expression) || node.expression.text !== paramName) {\n return null\n }\n\n if (ts.isStringLiteral(node.argumentExpression)) {\n return node.argumentEx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AC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IACpC,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AACxB,CAAC;AAED;;GAEG;AACH,SAAS,oBAAoB,CAAC,IAAgC,EAAE,SAAiB;IAC/E,IAAI,CAAC,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QAC5E,OAAO,IAAI,CAAA;IACb,CAAC;IAED,IAAI,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,kBAAkB,CAAC,EAAE,CAAC;QAChD,OAAO,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAA;IACrC,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC","sourcesContent":["import ts from 'typescript'\nimport { resolveAccessorBody } from './accessor-resolver.js'\n\n/**\n * Names whose first arg is itself a reactive accessor (the existing\n * arrow walker handles them) or which are explicitly excluded\n * (sample/item read state imperatively / per-row, not as state\n * accessors). When a delegating accessor's body contains a call to one\n * of these, we don't follow it — recursion is reserved for \"this is\n * just a thin wrapper that hands the state to another local helper.\"\n */\nconst NON_DELEGATION_HELPERS = new Set(['sample', 'item', 'memo', 'text', 'unsafeHtml'])\n\n/**\n * Walk a delegating accessor's body looking for calls to OTHER local\n * functions that take the state param verbatim — `helper(s)` where\n * `s` matches the outer accessor's param name. For each, hand the\n * resolved declaration back so the caller can recurse into its body.\n *\n * Skips:\n * - Framework helpers (`memo`, `text`, etc.) — their arrow args are\n * visited by the top-level arrow walker; we'd double-count.\n * - Method calls (`s.items.filter(...)`) — the callee is a builtin,\n * not a local function we can resolve.\n * - Nested function bodies — params inside a `(item) => …` shadow\n * ours, so a `helper(s)` deep in there isn't (necessarily)\n * handing OUR state in. Conservative: don't recurse through\n * lambda boundaries.\n */\nfunction visitTopLevelDelegations(\n body: ts.Node,\n stateParamName: string,\n follow: (resolved: ts.ArrowFunction | ts.FunctionExpression | ts.FunctionDeclaration) => void,\n): void {\n function visit(node: ts.Node): void {\n if (ts.isCallExpression(node) && ts.isIdentifier(node.expression)) {\n const name = node.expression.text\n if (!NON_DELEGATION_HELPERS.has(name)) {\n const arg0 = node.arguments[0]\n if (arg0 && ts.isIdentifier(arg0) && arg0.text === stateParamName) {\n const resolved = resolveAccessorBody(node.expression)\n if (resolved) follow(resolved)\n }\n }\n }\n // Don't descend into nested function bodies — their params shadow\n // ours, and any call inside them isn't unambiguously delegating\n // our state.\n if (\n ts.isArrowFunction(node) ||\n ts.isFunctionExpression(node) ||\n ts.isFunctionDeclaration(node)\n ) {\n return\n }\n ts.forEachChild(node, visit)\n }\n // If the body itself is a function, there's nothing at the top\n // level to inspect — its own body is a separate scope.\n if (ts.isArrowFunction(body) || ts.isFunctionExpression(body) || ts.isFunctionDeclaration(body)) {\n return\n }\n visit(body)\n}\n\n/**\n * Extract paths from a callable accessor (arrow / fn-expr / fn-decl)\n * into the given set. Recurses through call-delegations to other local\n * helpers so that `(s) => filtered(s)` / `(s) => { void s.x; return\n * inner(s) }` correctly contribute the helper's state-path reads.\n * Without recursion the precise mask under-counts — fields read only\n * via the helper drop off the bitmask, and any sibling reactive\n * accessor that reads them produces a non-zero `dirty` that AND'd with\n * the narrow each.__mask is zero, silently skipping the reconcile.\n *\n * `visited` breaks cycles on mutually-recursive helpers — terminates\n * the walk; doesn't try to be precise about what such helpers read.\n */\nfunction extractAccessorPaths(\n accessor: ts.ArrowFunction | ts.FunctionExpression | ts.FunctionDeclaration,\n paths: Set<string>,\n visited: Set<ts.Node> = new Set(),\n): boolean {\n if (visited.has(accessor)) return false\n visited.add(accessor)\n\n const params = accessor.parameters\n if (params.length !== 1) return false\n const paramName = params[0]!.name\n if (!ts.isIdentifier(paramName)) return false\n if (!accessor.body) return false\n const before = paths.size\n\n extractPaths(accessor.body, paramName.text, '', paths)\n\n // Follow delegations: `(s) => helper(s)` — extract `helper`'s body's\n // state paths too. Reuses the `visited` set across the recursion\n // chain so cycles terminate.\n visitTopLevelDelegations(accessor.body, paramName.text, (resolved) => {\n extractAccessorPaths(resolved, paths, visited)\n })\n\n return paths.size > before\n}\n\n/**\n * Walk the AST and collect every unique state access path referenced by\n * a reactive accessor. A reactive accessor is one of:\n *\n * - An inline arrow / function expression at a reactive position\n * (`text(s => s.count)`, `div({ title: s => s.title })`,\n * `show({ when: s => s.gated })`, etc.).\n * - An Identifier at a reactive position that resolves to a callable\n * in this file — a const-bound arrow / function expression,\n * a hoisted function declaration, or `const x = memo(arrow)`.\n *\n * The second case lets authors refactor a literal arrow into a named\n * helper without losing the reactive-mask optimization (a precise mask\n * for `__dirty` and structural-primitive `__mask`). Without it, the\n * runtime falls back to FULL_MASK — correct, but every binding fires\n * on every state change.\n *\n * Shared by the bit-assignment path (`collectDeps`, below) and the\n * `diagnostics.ts` bitmask-overflow warning.\n */\nexport function collectStatePathsFromSource(sourceFile: ts.SourceFile): Set<string> {\n const paths = new Set<string>()\n\n function visit(node: ts.Node): void {\n // Inline arrow / function expression at a reactive position.\n if (ts.isArrowFunction(node) || ts.isFunctionExpression(node)) {\n if (isReactiveAccessor(node)) extractAccessorPaths(node, paths)\n }\n\n // Identifier at a reactive position — resolve to its declaration\n // and extract paths from the resolved body. Skip identifiers\n // imported from elsewhere (resolver returns null) — there's no\n // body to scan, runtime falls back to FULL_MASK.\n if (ts.isIdentifier(node) && isReactiveAccessor(node)) {\n const resolved = resolveAccessorBody(node)\n if (resolved) extractAccessorPaths(resolved, paths)\n }\n\n ts.forEachChild(node, visit)\n }\n\n visit(sourceFile)\n return paths\n}\n\n/**\n * Per-accessor path sets — one entry per reactive arrow/function. Used\n * by the bitmask-overflow diagnostic to find clusters of paths that\n * always fire together (co-occurrence analysis).\n */\nexport function collectAccessorPathSets(sourceFile: ts.SourceFile): Set<string>[] {\n const sets: Set<string>[] = []\n\n function visit(node: ts.Node): void {\n if (ts.isArrowFunction(node) || ts.isFunctionExpression(node)) {\n if (isReactiveAccessor(node)) {\n const set = new Set<string>()\n if (extractAccessorPaths(node, set)) sets.push(set)\n }\n }\n\n if (ts.isIdentifier(node) && isReactiveAccessor(node)) {\n const resolved = resolveAccessorBody(node)\n if (resolved) {\n const set = new Set<string>()\n if (extractAccessorPaths(resolved, set)) sets.push(set)\n }\n }\n\n ts.forEachChild(node, visit)\n }\n\n visit(sourceFile)\n return sets\n}\n\n/**\n * Pre-scan a source file to collect all unique state access paths\n * referenced by reactive accessors (arrow functions in props and text() calls).\n *\n * Returns a pair of maps:\n * - `lo`: paths at bit positions 0..30, with value `1 << position`\n * - `hi`: paths at bit positions 31..61, with value `1 << (position - 31)`\n *\n * Bit positions past 61 collapse to `-1` (FULL_MASK) in the `lo` map and\n * cause every binding reading them to re-evaluate on every cycle. The\n * `bitmask-overflow` lint rule warns the user to restructure state.\n *\n * Components with ≤31 paths see an empty `hi` map; the compiler skips\n * all high-word emit so the generated code is byte-identical to the\n * pre-multi-word baseline.\n */\nexport function collectDeps(\n source: string,\n extraPaths?: ReadonlySet<string>,\n): {\n lo: Map<string, number>\n hi: Map<string, number>\n} {\n const sourceFile = ts.createSourceFile('input.ts', source, ts.ScriptTarget.Latest, true)\n\n // Check if file imports from @llui/dom\n if (!hasLluiImport(sourceFile)) {\n return { lo: new Map(), hi: new Map() }\n }\n\n const paths = collectStatePathsFromSource(sourceFile)\n // Cross-file extension (v2c pipeline integration): the host adapter may\n // pass paths discovered by `crossFileAccessorPaths()` — paths read\n // through in-repo view-helpers in *other* files. Union them with the\n // file-local set before bit assignment. Without this merge the\n // sentinel-`show()` workaround from v2b §1 remains necessary; with\n // it, helpers in other files contribute to the consumer's __prefixes\n // table automatically.\n if (extraPaths) {\n for (const p of extraPaths) paths.add(p)\n }\n\n const lo = new Map<string, number>()\n const hi = new Map<string, number>()\n let index = 0\n for (const path of paths) {\n if (index < 31) {\n lo.set(path, 1 << index)\n } else if (index < 62) {\n hi.set(path, 1 << (index - 31))\n } else {\n // Past 61 paths — graceful FULL_MASK fallback in the low word.\n // Realistic LLui components shouldn't hit this; the lint rule\n // fires well before.\n lo.set(path, -1)\n }\n index++\n }\n\n return { lo, hi }\n}\n\nfunction hasLluiImport(sourceFile: ts.SourceFile): boolean {\n for (const stmt of sourceFile.statements) {\n if (\n ts.isImportDeclaration(stmt) &&\n ts.isStringLiteral(stmt.moduleSpecifier) &&\n stmt.moduleSpecifier.text === '@llui/dom'\n ) {\n return true\n }\n }\n return false\n}\n\n/**\n * Determines if a node is at a reactive-accessor position — either an\n * inline arrow / function expression OR an identifier that's about to\n * be resolved to one. The check is identity-based on `parent.arguments[0]`\n * etc., so the same logic works for both shapes.\n *\n * Exported so the cross-file walker can use the same gate. Without this\n * gate the walker descends into every 1-param arrow in the file —\n * including `onEffect: (bag) => bag.send(...)` — and pollutes\n * `__prefixes` with non-state property names (issue #5, bug 3).\n */\nexport function isReactiveAccessor(node: ts.Node): boolean {\n const parent = node.parent\n\n // text(s => s.count) — first arg to a call\n if (ts.isCallExpression(parent) && parent.arguments[0] === node) {\n // Skip item(t => t.id) — per-item selectors inside each() render.\n // Skip sample(s => s.x) — imperative one-shot read, no binding created\n // (both the top-level import and the destructured-from-h form).\n if (ts.isIdentifier(parent.expression)) {\n if (parent.expression.text === 'item' || parent.expression.text === 'sample') {\n return false\n }\n }\n // Skip array method callbacks: .filter(t => ...), .map(t => ...), .some(t => ...), etc.\n // Allow view-helper primitive calls: h.text(s => ...), h.memo(s => ...)\n if (ts.isPropertyAccessExpression(parent.expression)) {\n const methodName = parent.expression.name.text\n if (methodName === 'text' || methodName === 'memo') {\n return true\n }\n return false\n }\n return true\n }\n\n // div({ title: s => s.title }) — value in a property assignment inside an object literal.\n // Only treat as reactive if the containing call is a known framework API whose\n // properties are reactive accessors. Otherwise user-land helpers like\n // sliceHandler({ narrow: (m) => m.type === ... }) would pollute the path set.\n if (ts.isPropertyAssignment(parent)) {\n const key = parent.name\n if (ts.isIdentifier(key)) {\n // Skip event handlers (onClick, onInput, etc.)\n if (/^on[A-Z]/.test(key.text)) return false\n // Skip each() key function and other non-reactive props\n if (key.text === 'key' || key.text === 'name') return false\n // Walk up to find the enclosing call expression\n let ancestor: ts.Node | undefined = parent.parent // ObjectLiteralExpression\n while (ancestor && !ts.isCallExpression(ancestor)) {\n ancestor = ancestor.parent\n }\n if (!ancestor) return false\n const callExpr = ancestor as ts.CallExpression\n // Bare identifier: `scope({on: …})`, `div({title: …})`, etc.\n if (ts.isIdentifier(callExpr.expression)) {\n return REACTIVE_API_NAMES.has(callExpr.expression.text)\n }\n // Method-call form: `h.scope({on: …})`, `h.show({when: …})`, etc.\n // The docs and View bag promote this shape; without recognizing it\n // here, paths read ONLY through a structural primitive's\n // `on`/`when`/`items` accessor never enter `__prefixes`, so the\n // runtime dirty mask can't see changes to those fields and the\n // structural block silently fails to reconcile.\n if (ts.isPropertyAccessExpression(callExpr.expression)) {\n return REACTIVE_API_NAMES.has(callExpr.expression.name.text)\n }\n return false\n }\n }\n\n return false\n}\n\n// Framework APIs whose object-literal arguments contain reactive accessors.\n// Arrow functions in property values of these calls are state-tracked.\nconst REACTIVE_API_NAMES = new Set([\n // Element helpers (see ELEMENT_HELPERS in transform.ts — we keep a superset here)\n ...[\n 'a',\n 'abbr',\n 'article',\n 'aside',\n 'b',\n 'blockquote',\n 'br',\n 'button',\n 'canvas',\n 'code',\n 'dd',\n 'details',\n 'dialog',\n 'div',\n 'dl',\n 'dt',\n 'em',\n 'fieldset',\n 'figcaption',\n 'figure',\n 'footer',\n 'form',\n 'h1',\n 'h2',\n 'h3',\n 'h4',\n 'h5',\n 'h6',\n 'header',\n 'hr',\n 'i',\n 'iframe',\n 'img',\n 'input',\n 'label',\n 'legend',\n 'li',\n 'main',\n 'mark',\n 'nav',\n 'ol',\n 'optgroup',\n 'option',\n 'output',\n 'p',\n 'pre',\n 'progress',\n 'section',\n 'select',\n 'small',\n 'span',\n 'strong',\n 'sub',\n 'summary',\n 'sup',\n 'table',\n 'tbody',\n 'td',\n 'textarea',\n 'tfoot',\n 'th',\n 'thead',\n 'time',\n 'tr',\n 'ul',\n 'video',\n ],\n // Structural primitives\n 'each',\n 'branch',\n 'scope',\n 'show',\n 'memo',\n 'portal',\n 'foreign',\n 'child',\n 'errorBoundary',\n // track({ deps: (s) => [...] }) — explicit reactivity declaration for\n // paths static analysis can't infer. The compiler treats `deps` as a\n // reactive accessor so its paths fold into the host component's\n // __prefixes; the call expression is then stripped from emission\n // (see transform.ts). v2b §3.\n 'track',\n])\n\n/**\n * Extract state access paths from an expression body.\n * Handles:\n * - Direct property access: param.field, param.field.subfield\n * - Bracket notation with string literal: param['field']\n */\nfunction extractPaths(node: ts.Node, paramName: string, _prefix: string, paths: Set<string>): void {\n if (ts.isPropertyAccessExpression(node)) {\n // Skip if this is an intermediate in a deeper chain\n if (ts.isPropertyAccessExpression(node.parent)) {\n // handled when the leaf is visited\n }\n // Skip if this is the callee of a method call: s.todos.filter(...)\n else if (ts.isCallExpression(node.parent) && node.parent.expression === node) {\n // It's a method call — record the object, not the method\n // e.g. s.todos.filter(...) → record 'todos', not 'todos.filter'\n if (ts.isPropertyAccessExpression(node.expression)) {\n const chain = resolvePropertyChain(node.expression, paramName)\n if (chain) paths.add(chain)\n }\n } else {\n const chain = resolvePropertyChain(node, paramName)\n if (chain) {\n paths.add(chain)\n }\n }\n }\n\n if (ts.isElementAccessExpression(node)) {\n const chain = resolveElementAccess(node, paramName)\n if (chain) {\n paths.add(chain)\n }\n }\n\n ts.forEachChild(node, (child) => extractPaths(child, paramName, _prefix, paths))\n}\n\n/**\n * Resolve a property access chain like s.user.name to \"user.name\".\n * Returns null if the chain doesn't start with the state parameter.\n * Stops at depth 2.\n */\nfunction resolvePropertyChain(node: ts.PropertyAccessExpression, paramName: string): string | null {\n const parts: string[] = []\n let current: ts.Expression = node\n\n while (ts.isPropertyAccessExpression(current)) {\n parts.unshift(current.name.text)\n current = current.expression\n }\n\n // The root must be the state parameter\n if (!ts.isIdentifier(current) || current.text !== paramName) {\n return null\n }\n\n // Limit to depth 2\n if (parts.length > 2) {\n return parts.slice(0, 2).join('.')\n }\n\n return parts.join('.')\n}\n\n/**\n * Resolve bracket access with string literal: s['count'] → \"count\"\n */\nfunction resolveElementAccess(node: ts.ElementAccessExpression, paramName: string): string | null {\n if (!ts.isIdentifier(node.expression) || node.expression.text !== paramName) {\n return null\n }\n\n if (ts.isStringLiteral(node.argumentExpression)) {\n return node.argumentExpression.text\n }\n\n return null\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lint-modules.d.ts","sourceRoot":"","sources":["../src/lint-modules.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"lint-modules.d.ts","sourceRoot":"","sources":["../src/lint-modules.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AA6CjD;;;;;;GAMG;AACH,wBAAgB,iBAAiB,IAAI,cAAc,EAAE,CA8CpD"}
|
package/dist/lint-modules.js
CHANGED
|
@@ -51,6 +51,8 @@ import { staticOnModule } from './modules/static-on.js';
|
|
|
51
51
|
import { noListRenderInSampleModule } from './modules/no-list-render-in-sample.js';
|
|
52
52
|
import { noSampleInAccessorModule } from './modules/no-sample-in-accessor.js';
|
|
53
53
|
import { noSampleInReactivePositionModule } from './modules/no-sample-in-reactive-position.js';
|
|
54
|
+
import { noSampleInEventHandlerModule } from './modules/no-sample-in-event-handler.js';
|
|
55
|
+
import { noRepeatedItemCurrentModule } from './modules/no-repeated-item-current.js';
|
|
54
56
|
import { agentEmitsDriftModule } from './modules/agent-emits-drift.js';
|
|
55
57
|
import { agentMsgResolvableModule } from './modules/agent-msg-resolvable.js';
|
|
56
58
|
/**
|
|
@@ -101,6 +103,8 @@ export function createLintModules() {
|
|
|
101
103
|
noListRenderInSampleModule(),
|
|
102
104
|
noSampleInAccessorModule(),
|
|
103
105
|
noSampleInReactivePositionModule(),
|
|
106
|
+
noSampleInEventHandlerModule(),
|
|
107
|
+
noRepeatedItemCurrentModule(),
|
|
104
108
|
agentEmitsDriftModule(),
|
|
105
109
|
agentMsgResolvableModule(),
|
|
106
110
|
];
|
package/dist/lint-modules.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lint-modules.js","sourceRoot":"","sources":["../src/lint-modules.ts"],"names":[],"mappings":"AAAA,0BAA0B;AAC1B,EAAE;AACF,uEAAuE;AACvE,qEAAqE;AACrE,wEAAwE;AACxE,uEAAuE;AACvE,yEAAyE;AACzE,6CAA6C;AAC7C,EAAE;AACF,kEAAkE;AAClE,yEAAyE;AACzE,uEAAuE;AACvE,wEAAwE;AACxE,gEAAgE;AAGhE,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAA;AACrE,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAA;AAC7D,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAA;AACvE,OAAO,EAAE,wBAAwB,EAAE,MAAM,oCAAoC,CAAA;AAC7E,OAAO,EAAE,uBAAuB,EAAE,MAAM,mCAAmC,CAAA;AAC3E,OAAO,EAAE,yBAAyB,EAAE,MAAM,qCAAqC,CAAA;AAC/E,OAAO,EAAE,wBAAwB,EAAE,MAAM,mCAAmC,CAAA;AAC5E,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAA;AACjE,OAAO,EAAE,0BAA0B,EAAE,MAAM,qCAAqC,CAAA;AAChF,OAAO,EAAE,8BAA8B,EAAE,MAAM,yCAAyC,CAAA;AACxF,OAAO,EAAE,yBAAyB,EAAE,MAAM,qCAAqC,CAAA;AAC/E,OAAO,EAAE,wBAAwB,EAAE,MAAM,mCAAmC,CAAA;AAC5E,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAA;AACvE,OAAO,EAAE,2BAA2B,EAAE,MAAM,uCAAuC,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F,OAAO,EAAE,wBAAwB,EAAE,MAAM,oCAAoC,CAAA;AAC7E,OAAO,EAAE,gCAAgC,EAAE,MAAM,6CAA6C,CAAA;AAC9F,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAA;AACtE,OAAO,EAAE,wBAAwB,EAAE,MAAM,mCAAmC,CAAA;AAE5E;;;;;;GAMG;AACH,MAAM,UAAU,iBAAiB;IAC/B,OAAO;QACL,qBAAqB,EAAE;QACvB,iBAAiB,EAAE;QACnB,qBAAqB,EAAE;QACvB,wBAAwB,EAAE;QAC1B,uBAAuB,EAAE;QACzB,yBAAyB,EAAE;QAC3B,wBAAwB,EAAE;QAC1B,mBAAmB,EAAE;QACrB,0BAA0B,EAAE;QAC5B,8BAA8B,EAAE;QAChC,yBAAyB,EAAE;QAC3B,wBAAwB,EAAE;QAC1B,sBAAsB,EAAE;QACxB,2BAA2B,EAAE;QAC7B,0BAA0B,EAAE;QAC5B,0BAA0B,EAAE;QAC5B,wBAAwB,EAAE;QAC1B,2BAA2B,EAAE;QAC7B,2BAA2B,EAAE;QAC7B,+BAA+B,EAAE;QACjC,oCAAoC,EAAE;QACtC,mCAAmC,EAAE;QACrC,gCAAgC,EAAE;QAClC,0BAA0B,EAAE;QAC5B,gBAAgB,EAAE;QAClB,qBAAqB,EAAE;QACvB,mBAAmB,EAAE;QACrB,mBAAmB,EAAE;QACrB,qBAAqB,EAAE;QACvB,iBAAiB,EAAE;QACnB,qBAAqB,EAAE;QACvB,qCAAqC,EAAE;QACvC,qBAAqB,EAAE;QACvB,sBAAsB,EAAE;QACxB,iBAAiB,EAAE;QACnB,cAAc,EAAE;QAChB,0BAA0B,EAAE;QAC5B,wBAAwB,EAAE;QAC1B,gCAAgC,EAAE;QAClC,qBAAqB,EAAE;QACvB,wBAAwB,EAAE;KAC3B,CAAA;AACH,CAAC","sourcesContent":["// Always-on lint modules.\n//\n// Every entry here is a zero-arg `CompilerModule` factory whose output\n// is registered unconditionally on every `transformLlui` invocation.\n// The function is the single source of truth — `transform.ts`'s active-\n// module list spreads it, and `scripts/generate-rule-docs.ts` calls it\n// to enumerate diagnostic IDs for the rule reference. Adding or removing\n// a rule in one place propagates everywhere.\n//\n// Note: this does NOT include modules with per-file options (e.g.\n// `maskLegendModule({ fieldBits, fieldBitsHi })`, `coreSynthesisModule`,\n// etc.) — those stay constructed inline in `transform.ts` because they\n// take per-file context. The `compilerStampModule` is unconditional but\n// it's an instance-not-factory; appended separately by callers.\n\nimport type { CompilerModule } from './module.js'\nimport { bitmaskOverflowModule } from './modules/bitmask-overflow.js'\nimport { asyncUpdateModule } from './modules/async-update.js'\nimport { mapOnStateArrayModule } from './modules/map-on-state-array.js'\nimport { nestedSendInUpdateModule } from './modules/nested-send-in-update.js'\nimport { directStateInViewModule } from './modules/direct-state-in-view.js'\nimport { imperativeDomInViewModule } from './modules/imperative-dom-in-view.js'\nimport { accessorSideEffectModule } from './modules/accessor-side-effect.js'\nimport { stateMutationModule } from './modules/state-mutation.js'\nimport { effectWithoutHandlerModule } from './modules/effect-without-handler.js'\nimport { exhaustiveEffectHandlingModule } from './modules/exhaustive-effect-handling.js'\nimport { noEagerItemAccessorModule } from './modules/no-eager-item-accessor.js'\nimport { pureUpdateFunctionModule } from './modules/pure-update-function.js'\nimport { exhaustiveUpdateModule } from './modules/exhaustive-update.js'\nimport { noLetReactiveAccessorModule } from './modules/no-let-reactive-accessor.js'\nimport { eachClosureViolationModule } from './modules/each-closure-violation.js'\nimport { stringEffectCallbackModule } from './modules/string-effect-callback.js'\nimport { agentMissingIntentModule } from './modules/agent-missing-intent.js'\nimport { agentWarningOnConfirmModule } from './modules/agent-warning-on-confirm.js'\nimport { agentExampleOnPayloadModule } from './modules/agent-example-on-payload.js'\nimport { agentExclusiveAnnotationsModule } from './modules/agent-exclusive-annotations.js'\nimport { agentOptionalFieldUndocumentedModule } from './modules/agent-optional-field-undocumented.js'\nimport { agentTagsendTranslatorMissingModule } from './modules/agent-tagsend-translator-missing.js'\nimport { agentNonextractableHandlerModule } from './modules/agent-nonextractable-handler.js'\nimport { subappRequiresReasonModule } from './modules/subapp-requires-reason.js'\nimport { emptyPropsModule } from './modules/empty-props.js'\nimport { forgottenSpreadModule } from './modules/forgotten-spread.js'\nimport { accessibilityModule } from './modules/accessibility.js'\nimport { viewBagImportModule } from './modules/view-bag-import.js'\nimport { controlledInputModule } from './modules/controlled-input.js'\nimport { missingMemoModule } from './modules/missing-memo.js'\nimport { namespaceImportModule } from './modules/namespace-import.js'\nimport { noBarrelImportWhenSubpathExistsModule } from './modules/no-barrel-import-when-subpath-exists.js'\nimport { formBoilerplateModule } from './modules/form-boilerplate.js'\nimport { spreadInChildrenModule } from './modules/spread-in-children.js'\nimport { staticItemsModule } from './modules/static-items.js'\nimport { staticOnModule } from './modules/static-on.js'\nimport { noListRenderInSampleModule } from './modules/no-list-render-in-sample.js'\nimport { noSampleInAccessorModule } from './modules/no-sample-in-accessor.js'\nimport { noSampleInReactivePositionModule } from './modules/no-sample-in-reactive-position.js'\nimport { agentEmitsDriftModule } from './modules/agent-emits-drift.js'\nimport { agentMsgResolvableModule } from './modules/agent-msg-resolvable.js'\n\n/**\n * Construct fresh instances of every always-on lint module.\n *\n * Returns a new array per call. Modules are stateful within a single\n * `ModuleRegistry.run()` (slot accumulators), so reusing instances\n * across files would leak state — always call this once per file.\n */\nexport function createLintModules(): CompilerModule[] {\n return [\n bitmaskOverflowModule(),\n asyncUpdateModule(),\n mapOnStateArrayModule(),\n nestedSendInUpdateModule(),\n directStateInViewModule(),\n imperativeDomInViewModule(),\n accessorSideEffectModule(),\n stateMutationModule(),\n effectWithoutHandlerModule(),\n exhaustiveEffectHandlingModule(),\n noEagerItemAccessorModule(),\n pureUpdateFunctionModule(),\n exhaustiveUpdateModule(),\n noLetReactiveAccessorModule(),\n eachClosureViolationModule(),\n stringEffectCallbackModule(),\n agentMissingIntentModule(),\n agentWarningOnConfirmModule(),\n agentExampleOnPayloadModule(),\n agentExclusiveAnnotationsModule(),\n agentOptionalFieldUndocumentedModule(),\n agentTagsendTranslatorMissingModule(),\n agentNonextractableHandlerModule(),\n subappRequiresReasonModule(),\n emptyPropsModule(),\n forgottenSpreadModule(),\n accessibilityModule(),\n viewBagImportModule(),\n controlledInputModule(),\n missingMemoModule(),\n namespaceImportModule(),\n noBarrelImportWhenSubpathExistsModule(),\n formBoilerplateModule(),\n spreadInChildrenModule(),\n staticItemsModule(),\n staticOnModule(),\n noListRenderInSampleModule(),\n noSampleInAccessorModule(),\n noSampleInReactivePositionModule(),\n agentEmitsDriftModule(),\n agentMsgResolvableModule(),\n ]\n}\n"]}
|
|
1
|
+
{"version":3,"file":"lint-modules.js","sourceRoot":"","sources":["../src/lint-modules.ts"],"names":[],"mappings":"AAAA,0BAA0B;AAC1B,EAAE;AACF,uEAAuE;AACvE,qEAAqE;AACrE,wEAAwE;AACxE,uEAAuE;AACvE,yEAAyE;AACzE,6CAA6C;AAC7C,EAAE;AACF,kEAAkE;AAClE,yEAAyE;AACzE,uEAAuE;AACvE,wEAAwE;AACxE,gEAAgE;AAGhE,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAA;AACrE,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAA;AAC7D,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAA;AACvE,OAAO,EAAE,wBAAwB,EAAE,MAAM,oCAAoC,CAAA;AAC7E,OAAO,EAAE,uBAAuB,EAAE,MAAM,mCAAmC,CAAA;AAC3E,OAAO,EAAE,yBAAyB,EAAE,MAAM,qCAAqC,CAAA;AAC/E,OAAO,EAAE,wBAAwB,EAAE,MAAM,mCAAmC,CAAA;AAC5E,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAA;AACjE,OAAO,EAAE,0BAA0B,EAAE,MAAM,qCAAqC,CAAA;AAChF,OAAO,EAAE,8BAA8B,EAAE,MAAM,yCAAyC,CAAA;AACxF,OAAO,EAAE,yBAAyB,EAAE,MAAM,q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QACvB,sBAAsB,EAAE;QACxB,iBAAiB,EAAE;QACnB,cAAc,EAAE;QAChB,0BAA0B,EAAE;QAC5B,wBAAwB,EAAE;QAC1B,gCAAgC,EAAE;QAClC,4BAA4B,EAAE;QAC9B,2BAA2B,EAAE;QAC7B,qBAAqB,EAAE;QACvB,wBAAwB,EAAE;KAC3B,CAAA;AACH,CAAC","sourcesContent":["// Always-on lint modules.\n//\n// Every entry here is a zero-arg `CompilerModule` factory whose output\n// is registered unconditionally on every `transformLlui` invocation.\n// The function is the single source of truth — `transform.ts`'s active-\n// module list spreads it, and `scripts/generate-rule-docs.ts` calls it\n// to enumerate diagnostic IDs for the rule reference. Adding or removing\n// a rule in one place propagates everywhere.\n//\n// Note: this does NOT include modules with per-file options (e.g.\n// `maskLegendModule({ fieldBits, fieldBitsHi })`, `coreSynthesisModule`,\n// etc.) — those stay constructed inline in `transform.ts` because they\n// take per-file context. The `compilerStampModule` is unconditional but\n// it's an instance-not-factory; appended separately by callers.\n\nimport type { CompilerModule } from './module.js'\nimport { bitmaskOverflowModule } from './modules/bitmask-overflow.js'\nimport { asyncUpdateModule } from './modules/async-update.js'\nimport { mapOnStateArrayModule } from './modules/map-on-state-array.js'\nimport { nestedSendInUpdateModule } from './modules/nested-send-in-update.js'\nimport { directStateInViewModule } from './modules/direct-state-in-view.js'\nimport { imperativeDomInViewModule } from './modules/imperative-dom-in-view.js'\nimport { accessorSideEffectModule } from './modules/accessor-side-effect.js'\nimport { stateMutationModule } from './modules/state-mutation.js'\nimport { effectWithoutHandlerModule } from './modules/effect-without-handler.js'\nimport { exhaustiveEffectHandlingModule } from './modules/exhaustive-effect-handling.js'\nimport { noEagerItemAccessorModule } from './modules/no-eager-item-accessor.js'\nimport { pureUpdateFunctionModule } from './modules/pure-update-function.js'\nimport { exhaustiveUpdateModule } from './modules/exhaustive-update.js'\nimport { noLetReactiveAccessorModule } from './modules/no-let-reactive-accessor.js'\nimport { eachClosureViolationModule } from './modules/each-closure-violation.js'\nimport { stringEffectCallbackModule } from './modules/string-effect-callback.js'\nimport { agentMissingIntentModule } from './modules/agent-missing-intent.js'\nimport { agentWarningOnConfirmModule } from './modules/agent-warning-on-confirm.js'\nimport { agentExampleOnPayloadModule } from './modules/agent-example-on-payload.js'\nimport { agentExclusiveAnnotationsModule } from './modules/agent-exclusive-annotations.js'\nimport { agentOptionalFieldUndocumentedModule } from './modules/agent-optional-field-undocumented.js'\nimport { agentTagsendTranslatorMissingModule } from './modules/agent-tagsend-translator-missing.js'\nimport { agentNonextractableHandlerModule } from './modules/agent-nonextractable-handler.js'\nimport { subappRequiresReasonModule } from './modules/subapp-requires-reason.js'\nimport { emptyPropsModule } from './modules/empty-props.js'\nimport { forgottenSpreadModule } from './modules/forgotten-spread.js'\nimport { accessibilityModule } from './modules/accessibility.js'\nimport { viewBagImportModule } from './modules/view-bag-import.js'\nimport { controlledInputModule } from './modules/controlled-input.js'\nimport { missingMemoModule } from './modules/missing-memo.js'\nimport { namespaceImportModule } from './modules/namespace-import.js'\nimport { noBarrelImportWhenSubpathExistsModule } from './modules/no-barrel-import-when-subpath-exists.js'\nimport { formBoilerplateModule } from './modules/form-boilerplate.js'\nimport { spreadInChildrenModule } from './modules/spread-in-children.js'\nimport { staticItemsModule } from './modules/static-items.js'\nimport { staticOnModule } from './modules/static-on.js'\nimport { noListRenderInSampleModule } from './modules/no-list-render-in-sample.js'\nimport { noSampleInAccessorModule } from './modules/no-sample-in-accessor.js'\nimport { noSampleInReactivePositionModule } from './modules/no-sample-in-reactive-position.js'\nimport { noSampleInEventHandlerModule } from './modules/no-sample-in-event-handler.js'\nimport { noRepeatedItemCurrentModule } from './modules/no-repeated-item-current.js'\nimport { agentEmitsDriftModule } from './modules/agent-emits-drift.js'\nimport { agentMsgResolvableModule } from './modules/agent-msg-resolvable.js'\n\n/**\n * Construct fresh instances of every always-on lint module.\n *\n * Returns a new array per call. Modules are stateful within a single\n * `ModuleRegistry.run()` (slot accumulators), so reusing instances\n * across files would leak state — always call this once per file.\n */\nexport function createLintModules(): CompilerModule[] {\n return [\n bitmaskOverflowModule(),\n asyncUpdateModule(),\n mapOnStateArrayModule(),\n nestedSendInUpdateModule(),\n directStateInViewModule(),\n imperativeDomInViewModule(),\n accessorSideEffectModule(),\n stateMutationModule(),\n effectWithoutHandlerModule(),\n exhaustiveEffectHandlingModule(),\n noEagerItemAccessorModule(),\n pureUpdateFunctionModule(),\n exhaustiveUpdateModule(),\n noLetReactiveAccessorModule(),\n eachClosureViolationModule(),\n stringEffectCallbackModule(),\n agentMissingIntentModule(),\n agentWarningOnConfirmModule(),\n agentExampleOnPayloadModule(),\n agentExclusiveAnnotationsModule(),\n agentOptionalFieldUndocumentedModule(),\n agentTagsendTranslatorMissingModule(),\n agentNonextractableHandlerModule(),\n subappRequiresReasonModule(),\n emptyPropsModule(),\n forgottenSpreadModule(),\n accessibilityModule(),\n viewBagImportModule(),\n controlledInputModule(),\n missingMemoModule(),\n namespaceImportModule(),\n noBarrelImportWhenSubpathExistsModule(),\n formBoilerplateModule(),\n spreadInChildrenModule(),\n staticItemsModule(),\n staticOnModule(),\n noListRenderInSampleModule(),\n noSampleInAccessorModule(),\n noSampleInReactivePositionModule(),\n noSampleInEventHandlerModule(),\n noRepeatedItemCurrentModule(),\n agentEmitsDriftModule(),\n agentMsgResolvableModule(),\n ]\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-repeated-item-current.d.ts","sourceRoot":"","sources":["../../src/modules/no-repeated-item-current.ts"],"names":[],"mappings":"AA6BA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAoGlD,wBAAgB,2BAA2B,IAAI,cAAc,CA4C5D"}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
// `no-repeated-item-current` — warns when an `each.render` callback's
|
|
2
|
+
// accessor body calls `item.current()` more than once with a property
|
|
3
|
+
// chain after each call (e.g. `item.current().facts[K]` repeated
|
|
4
|
+
// inside the same text/show.when accessor).
|
|
5
|
+
//
|
|
6
|
+
// Two reasons the pattern is dangerous:
|
|
7
|
+
//
|
|
8
|
+
// 1. **Bitmask trap.** `item.current().X` hides the read from the
|
|
9
|
+
// compiler's static analyzer — the accessor falls back to
|
|
10
|
+
// FULL_MASK and fires on every state change instead of only when
|
|
11
|
+
// `X` changes.
|
|
12
|
+
// 2. **Reconcile-race undefined.** Repeated `.current()` calls
|
|
13
|
+
// across a single accessor body can observe intermediate state
|
|
14
|
+
// during a structural transition. The chained property access
|
|
15
|
+
// then throws `Cannot read properties of undefined (reading
|
|
16
|
+
// 'X')`. The dungeonlogs 2026-05-20 report named exactly this
|
|
17
|
+
// class of bug.
|
|
18
|
+
//
|
|
19
|
+
// The fix is one of:
|
|
20
|
+
// - destructure once: `const e = item.current(); use e.X, e.Y`
|
|
21
|
+
// - project to a row type in `items` so each cell becomes a simple
|
|
22
|
+
// field read (`item.X` shorthand)
|
|
23
|
+
//
|
|
24
|
+
// Severity: warn. A single `item.current()` call is fine (sometimes
|
|
25
|
+
// necessary, e.g. guarding for primitive T's `current` accessor); the
|
|
26
|
+
// warning fires only when the same accessor body calls it 2+ times.
|
|
27
|
+
import ts from 'typescript';
|
|
28
|
+
import { rangeFromOffsets } from '../diagnostic.js';
|
|
29
|
+
/** True when `node` is `item.current()` — bare `item` identifier root. */
|
|
30
|
+
function isItemCurrentCall(node) {
|
|
31
|
+
if (!ts.isCallExpression(node))
|
|
32
|
+
return false;
|
|
33
|
+
if (node.arguments.length !== 0)
|
|
34
|
+
return false;
|
|
35
|
+
if (!ts.isPropertyAccessExpression(node.expression))
|
|
36
|
+
return false;
|
|
37
|
+
const obj = node.expression.expression;
|
|
38
|
+
if (!ts.isIdentifier(obj) || obj.text !== 'item')
|
|
39
|
+
return false;
|
|
40
|
+
const name = node.expression.name;
|
|
41
|
+
return ts.isIdentifier(name) && name.text === 'current';
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Find direct-children `item.current()` calls of `body` that are
|
|
45
|
+
* followed by a property access (e.g. `item.current().X`). Skip nested
|
|
46
|
+
* function bodies — a `.current()` inside an inner arrow runs in a
|
|
47
|
+
* different scope.
|
|
48
|
+
*/
|
|
49
|
+
function findChainedItemCurrents(body) {
|
|
50
|
+
const out = [];
|
|
51
|
+
const walk = (n) => {
|
|
52
|
+
if (isItemCurrentCall(n)) {
|
|
53
|
+
// We only flag chained access — `item.current()` alone is fine
|
|
54
|
+
// (used as a return value, passed to a helper, etc.).
|
|
55
|
+
const parent = n.parent;
|
|
56
|
+
if (parent && ts.isPropertyAccessExpression(parent) && parent.expression === n) {
|
|
57
|
+
out.push(n);
|
|
58
|
+
}
|
|
59
|
+
else if (parent && ts.isElementAccessExpression(parent) && parent.expression === n) {
|
|
60
|
+
out.push(n);
|
|
61
|
+
}
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if ((ts.isArrowFunction(n) || ts.isFunctionExpression(n) || ts.isFunctionDeclaration(n)) &&
|
|
65
|
+
n !== body) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
ts.forEachChild(n, walk);
|
|
69
|
+
};
|
|
70
|
+
walk(body);
|
|
71
|
+
return out;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Walk a function body and report when any inner accessor (arrow arg
|
|
75
|
+
* to `text` / `unsafeHtml` / `h.show({ when })` / similar) calls
|
|
76
|
+
* `item.current().X` more than once.
|
|
77
|
+
*/
|
|
78
|
+
function checkRenderBody(body, sf, report) {
|
|
79
|
+
const visit = (n) => {
|
|
80
|
+
if (ts.isArrowFunction(n) || ts.isFunctionExpression(n)) {
|
|
81
|
+
const calls = findChainedItemCurrents(n.body);
|
|
82
|
+
if (calls.length >= 2) {
|
|
83
|
+
// Report the SECOND call — the first one is fine on its own;
|
|
84
|
+
// the warning is "you're doing this repeatedly."
|
|
85
|
+
report(calls[1]);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
ts.forEachChild(n, visit);
|
|
89
|
+
};
|
|
90
|
+
visit(body);
|
|
91
|
+
void sf;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Detect an `each(...)` or `h.each(...)` call. Returns the render
|
|
95
|
+
* function's body if present.
|
|
96
|
+
*/
|
|
97
|
+
function eachRenderBody(call) {
|
|
98
|
+
let isEach = false;
|
|
99
|
+
if (ts.isIdentifier(call.expression) && call.expression.text === 'each')
|
|
100
|
+
isEach = true;
|
|
101
|
+
else if (ts.isPropertyAccessExpression(call.expression) &&
|
|
102
|
+
ts.isIdentifier(call.expression.name) &&
|
|
103
|
+
call.expression.name.text === 'each') {
|
|
104
|
+
isEach = true;
|
|
105
|
+
}
|
|
106
|
+
if (!isEach)
|
|
107
|
+
return undefined;
|
|
108
|
+
const arg = call.arguments[0];
|
|
109
|
+
if (!arg || !ts.isObjectLiteralExpression(arg))
|
|
110
|
+
return undefined;
|
|
111
|
+
for (const prop of arg.properties) {
|
|
112
|
+
if (ts.isPropertyAssignment(prop) &&
|
|
113
|
+
ts.isIdentifier(prop.name) &&
|
|
114
|
+
prop.name.text === 'render' &&
|
|
115
|
+
(ts.isArrowFunction(prop.initializer) || ts.isFunctionExpression(prop.initializer))) {
|
|
116
|
+
return prop.initializer.body;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return undefined;
|
|
120
|
+
}
|
|
121
|
+
export function noRepeatedItemCurrentModule() {
|
|
122
|
+
return {
|
|
123
|
+
name: 'no-repeated-item-current',
|
|
124
|
+
compilerVersion: '^0.3.0',
|
|
125
|
+
diagnostics: [
|
|
126
|
+
{
|
|
127
|
+
id: 'llui/no-repeated-item-current',
|
|
128
|
+
description: 'Repeated `item.current().X` calls inside the same accessor — bitmask falls back to FULL_MASK and chained access can throw during reconcile races. Destructure once or project to a row type.',
|
|
129
|
+
},
|
|
130
|
+
],
|
|
131
|
+
visitors: {
|
|
132
|
+
[ts.SyntaxKind.SourceFile]: (ctx, node) => {
|
|
133
|
+
const visited = node;
|
|
134
|
+
const sf = ts.createSourceFile(visited.fileName, visited.text, ts.ScriptTarget.Latest, true);
|
|
135
|
+
const walk = (n) => {
|
|
136
|
+
if (ts.isCallExpression(n)) {
|
|
137
|
+
const body = eachRenderBody(n);
|
|
138
|
+
if (body) {
|
|
139
|
+
checkRenderBody(body, sf, (offender) => {
|
|
140
|
+
ctx.reportDiagnostic({
|
|
141
|
+
id: 'llui/no-repeated-item-current',
|
|
142
|
+
severity: 'warning',
|
|
143
|
+
category: 'reactivity',
|
|
144
|
+
message: `Repeated \`item.current()\` calls inside an each.render accessor. The compiler can't trace through ` +
|
|
145
|
+
`\`item.current().X\` so the binding falls back to FULL_MASK (fires on every state change), and ` +
|
|
146
|
+
`chained access can throw \`Cannot read properties of undefined\` during structural reconciles. ` +
|
|
147
|
+
`Either destructure once at the top — \`const e = item.current(); /* use e.X, e.Y */\` — or project ` +
|
|
148
|
+
`to a row type in \`items\` so each cell becomes a simple field read (\`item.X\` shorthand).`,
|
|
149
|
+
location: {
|
|
150
|
+
file: sf.fileName,
|
|
151
|
+
range: rangeFromOffsets(sf.text, offender.getStart(sf), offender.getEnd()),
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
ts.forEachChild(n, walk);
|
|
158
|
+
};
|
|
159
|
+
walk(sf);
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
//# sourceMappingURL=no-repeated-item-current.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-repeated-item-current.js","sourceRoot":"","sources":["../../src/modules/no-repeated-item-current.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,sEAAsE;AACtE,iEAAiE;AACjE,4CAA4C;AAC5C,EAAE;AACF,wCAAwC;AACxC,EAAE;AACF,oEAAoE;AACpE,+DAA+D;AAC/D,sEAAsE;AACtE,oBAAoB;AACpB,iEAAiE;AACjE,oEAAoE;AACpE,m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,IAAI,CAAC,EAAE,CAAC,CAAA;YACV,CAAC;SACF;KACF,CAAA;AACH,CAAC","sourcesContent":["// `no-repeated-item-current` — warns when an `each.render` callback's\n// accessor body calls `item.current()` more than once with a property\n// chain after each call (e.g. `item.current().facts[K]` repeated\n// inside the same text/show.when accessor).\n//\n// Two reasons the pattern is dangerous:\n//\n// 1. **Bitmask trap.** `item.current().X` hides the read from the\n// compiler's static analyzer — the accessor falls back to\n// FULL_MASK and fires on every state change instead of only when\n// `X` changes.\n// 2. **Reconcile-race undefined.** Repeated `.current()` calls\n// across a single accessor body can observe intermediate state\n// during a structural transition. The chained property access\n// then throws `Cannot read properties of undefined (reading\n// 'X')`. The dungeonlogs 2026-05-20 report named exactly this\n// class of bug.\n//\n// The fix is one of:\n// - destructure once: `const e = item.current(); use e.X, e.Y`\n// - project to a row type in `items` so each cell becomes a simple\n// field read (`item.X` shorthand)\n//\n// Severity: warn. A single `item.current()` call is fine (sometimes\n// necessary, e.g. guarding for primitive T's `current` accessor); the\n// warning fires only when the same accessor body calls it 2+ times.\n\nimport ts from 'typescript'\nimport { rangeFromOffsets } from '../diagnostic.js'\nimport type { CompilerModule } from '../module.js'\n\n/** True when `node` is `item.current()` — bare `item` identifier root. */\nfunction isItemCurrentCall(node: ts.Node): node is ts.CallExpression {\n if (!ts.isCallExpression(node)) return false\n if (node.arguments.length !== 0) return false\n if (!ts.isPropertyAccessExpression(node.expression)) return false\n const obj = node.expression.expression\n if (!ts.isIdentifier(obj) || obj.text !== 'item') return false\n const name = node.expression.name\n return ts.isIdentifier(name) && name.text === 'current'\n}\n\n/**\n * Find direct-children `item.current()` calls of `body` that are\n * followed by a property access (e.g. `item.current().X`). Skip nested\n * function bodies — a `.current()` inside an inner arrow runs in a\n * different scope.\n */\nfunction findChainedItemCurrents(body: ts.Node): ts.CallExpression[] {\n const out: ts.CallExpression[] = []\n const walk = (n: ts.Node): void => {\n if (isItemCurrentCall(n)) {\n // We only flag chained access — `item.current()` alone is fine\n // (used as a return value, passed to a helper, etc.).\n const parent = n.parent\n if (parent && ts.isPropertyAccessExpression(parent) && parent.expression === n) {\n out.push(n)\n } else if (parent && ts.isElementAccessExpression(parent) && parent.expression === n) {\n out.push(n)\n }\n return\n }\n if (\n (ts.isArrowFunction(n) || ts.isFunctionExpression(n) || ts.isFunctionDeclaration(n)) &&\n n !== body\n ) {\n return\n }\n ts.forEachChild(n, walk)\n }\n walk(body)\n return out\n}\n\n/**\n * Walk a function body and report when any inner accessor (arrow arg\n * to `text` / `unsafeHtml` / `h.show({ when })` / similar) calls\n * `item.current().X` more than once.\n */\nfunction checkRenderBody(\n body: ts.Node,\n sf: ts.SourceFile,\n report: (offender: ts.CallExpression) => void,\n): void {\n const visit = (n: ts.Node): void => {\n if (ts.isArrowFunction(n) || ts.isFunctionExpression(n)) {\n const calls = findChainedItemCurrents(n.body)\n if (calls.length >= 2) {\n // Report the SECOND call — the first one is fine on its own;\n // the warning is \"you're doing this repeatedly.\"\n report(calls[1]!)\n }\n }\n ts.forEachChild(n, visit)\n }\n visit(body)\n void sf\n}\n\n/**\n * Detect an `each(...)` or `h.each(...)` call. Returns the render\n * function's body if present.\n */\nfunction eachRenderBody(call: ts.CallExpression): ts.Node | undefined {\n let isEach = false\n if (ts.isIdentifier(call.expression) && call.expression.text === 'each') isEach = true\n else if (\n ts.isPropertyAccessExpression(call.expression) &&\n ts.isIdentifier(call.expression.name) &&\n call.expression.name.text === 'each'\n ) {\n isEach = true\n }\n if (!isEach) return undefined\n const arg = call.arguments[0]\n if (!arg || !ts.isObjectLiteralExpression(arg)) return undefined\n for (const prop of arg.properties) {\n if (\n ts.isPropertyAssignment(prop) &&\n ts.isIdentifier(prop.name) &&\n prop.name.text === 'render' &&\n (ts.isArrowFunction(prop.initializer) || ts.isFunctionExpression(prop.initializer))\n ) {\n return prop.initializer.body\n }\n }\n return undefined\n}\n\nexport function noRepeatedItemCurrentModule(): CompilerModule {\n return {\n name: 'no-repeated-item-current',\n compilerVersion: '^0.3.0',\n diagnostics: [\n {\n id: 'llui/no-repeated-item-current',\n description:\n 'Repeated `item.current().X` calls inside the same accessor — bitmask falls back to FULL_MASK and chained access can throw during reconcile races. Destructure once or project to a row type.',\n },\n ],\n visitors: {\n [ts.SyntaxKind.SourceFile]: (ctx, node) => {\n const visited = node as ts.SourceFile\n const sf = ts.createSourceFile(visited.fileName, visited.text, ts.ScriptTarget.Latest, true)\n const walk = (n: ts.Node): void => {\n if (ts.isCallExpression(n)) {\n const body = eachRenderBody(n)\n if (body) {\n checkRenderBody(body, sf, (offender) => {\n ctx.reportDiagnostic({\n id: 'llui/no-repeated-item-current',\n severity: 'warning',\n category: 'reactivity',\n message:\n `Repeated \\`item.current()\\` calls inside an each.render accessor. The compiler can't trace through ` +\n `\\`item.current().X\\` so the binding falls back to FULL_MASK (fires on every state change), and ` +\n `chained access can throw \\`Cannot read properties of undefined\\` during structural reconciles. ` +\n `Either destructure once at the top — \\`const e = item.current(); /* use e.X, e.Y */\\` — or project ` +\n `to a row type in \\`items\\` so each cell becomes a simple field read (\\`item.X\\` shorthand).`,\n location: {\n file: sf.fileName,\n range: rangeFromOffsets(sf.text, offender.getStart(sf), offender.getEnd()),\n },\n })\n })\n }\n }\n ts.forEachChild(n, walk)\n }\n walk(sf)\n },\n },\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-sample-in-event-handler.d.ts","sourceRoot":"","sources":["../../src/modules/no-sample-in-event-handler.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AA0ClD,wBAAgB,4BAA4B,IAAI,cAAc,CAgD7D"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
// `no-sample-in-event-handler` — errors when `sample()` / `h.sample()`
|
|
2
|
+
// appears inside an event-handler property (`onClick`, `onInput`,
|
|
3
|
+
// `onSubmit`, …). Event handlers run AFTER mount, with no active
|
|
4
|
+
// render context, so the runtime `sample()` throws `[LLui] sample()
|
|
5
|
+
// can only be called inside a component's view() function`.
|
|
6
|
+
//
|
|
7
|
+
// Catching at compile time turns "open the dev console, click the
|
|
8
|
+
// button, see the error" into a build failure on the offending file.
|
|
9
|
+
// Aligned with the framework's "compile-time errors not lint warnings"
|
|
10
|
+
// philosophy.
|
|
11
|
+
//
|
|
12
|
+
// The right pattern is to capture at render time:
|
|
13
|
+
// const id = h.sample((s) => s.id)
|
|
14
|
+
// button({ onClick: () => send({ type: 'select', id }) })
|
|
15
|
+
// or to use the mount handle: `handle.getState()` inside the handler.
|
|
16
|
+
import ts from 'typescript';
|
|
17
|
+
import { rangeFromOffsets } from '../diagnostic.js';
|
|
18
|
+
const EVENT_HANDLER_KEY_RE = /^on[A-Z]/;
|
|
19
|
+
function isSampleCall(n) {
|
|
20
|
+
if (!ts.isCallExpression(n))
|
|
21
|
+
return false;
|
|
22
|
+
if (ts.isIdentifier(n.expression) && n.expression.text === 'sample')
|
|
23
|
+
return true;
|
|
24
|
+
if (ts.isPropertyAccessExpression(n.expression) &&
|
|
25
|
+
ts.isIdentifier(n.expression.name) &&
|
|
26
|
+
n.expression.name.text === 'sample') {
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
function findFirstSampleInside(body) {
|
|
32
|
+
let found;
|
|
33
|
+
const walk = (n) => {
|
|
34
|
+
if (found)
|
|
35
|
+
return;
|
|
36
|
+
if (isSampleCall(n)) {
|
|
37
|
+
found = n;
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
// DON'T descend into nested functions — sample() inside an inner
|
|
41
|
+
// function (e.g. a setTimeout body or another arrow that captures
|
|
42
|
+
// the event handler's closure) runs at a different time and has
|
|
43
|
+
// its own context check at runtime. Only the directly-synchronous
|
|
44
|
+
// sample call in the handler body is the trap this rule targets.
|
|
45
|
+
if ((ts.isArrowFunction(n) || ts.isFunctionExpression(n) || ts.isFunctionDeclaration(n)) &&
|
|
46
|
+
n !== body) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
ts.forEachChild(n, walk);
|
|
50
|
+
};
|
|
51
|
+
walk(body);
|
|
52
|
+
return found;
|
|
53
|
+
}
|
|
54
|
+
export function noSampleInEventHandlerModule() {
|
|
55
|
+
return {
|
|
56
|
+
name: 'no-sample-in-event-handler',
|
|
57
|
+
compilerVersion: '^0.3.0',
|
|
58
|
+
diagnostics: [
|
|
59
|
+
{
|
|
60
|
+
id: 'llui/no-sample-in-event-handler',
|
|
61
|
+
description: '`sample()` inside an event handler — handlers run with no render context; throws at runtime. Capture at render time instead.',
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
visitors: {
|
|
65
|
+
[ts.SyntaxKind.SourceFile]: (ctx, node) => {
|
|
66
|
+
const visited = node;
|
|
67
|
+
const sf = ts.createSourceFile(visited.fileName, visited.text, ts.ScriptTarget.Latest, true);
|
|
68
|
+
const walk = (n) => {
|
|
69
|
+
if (ts.isPropertyAssignment(n)) {
|
|
70
|
+
const key = n.name;
|
|
71
|
+
if (ts.isIdentifier(key) && EVENT_HANDLER_KEY_RE.test(key.text)) {
|
|
72
|
+
const value = n.initializer;
|
|
73
|
+
if (ts.isArrowFunction(value) || ts.isFunctionExpression(value)) {
|
|
74
|
+
const offender = findFirstSampleInside(value.body);
|
|
75
|
+
if (offender) {
|
|
76
|
+
ctx.reportDiagnostic({
|
|
77
|
+
id: 'llui/no-sample-in-event-handler',
|
|
78
|
+
severity: 'error',
|
|
79
|
+
category: 'reactivity',
|
|
80
|
+
message: `\`sample()\` is being called inside the \`${key.text}\` handler. Handlers run AFTER mount with no active render context, so this throws at runtime ` +
|
|
81
|
+
`(\`[LLui] sample() can only be called inside a component's view() function\`). Capture the value at render time instead: ` +
|
|
82
|
+
`\`const id = h.sample(s => s.id); button({ ${key.text}: () => send({ ..., id }) })\`. ` +
|
|
83
|
+
`If you need the LATEST state at click time (rare), use the mount handle: ` +
|
|
84
|
+
`\`handle.getState()\` inside the handler.`,
|
|
85
|
+
location: {
|
|
86
|
+
file: sf.fileName,
|
|
87
|
+
range: rangeFromOffsets(sf.text, offender.getStart(sf), offender.getEnd()),
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
ts.forEachChild(n, walk);
|
|
95
|
+
};
|
|
96
|
+
walk(sf);
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=no-sample-in-event-handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-sample-in-event-handler.js","sourceRoot":"","sources":["../../src/modules/no-sample-in-event-handler.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,kEAAkE;AAClE,iEAAiE;AACjE,oEAAoE;AACpE,4DAA4D;AAC5D,EAAE;AACF,kEAAkE;AAClE,qEAAqE;AACrE,uEAAuE;AACvE,cAAc;AACd,EAAE;AACF,kDAAkD;AAClD,qCAAqC;AACrC,4DAA4D;AAC5D,sEAAsE;AAEtE,OAAO,EAAE,MAAM,YAAY,CAAA;AAC3B,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAGnD,MAAM,oBAAoB,GAAG,UAAU,CAAA;AAEvC,SAAS,YAAY,CAAC,CAAU;IAC9B,IAAI,CAAC,EAAE,CAAC,gBAAgB,CAAC,CAAC,CAAC;QAAE,OAAO,KAAK,CAAA;IACzC,IAAI,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,IAAI,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAA;IAChF,IACE,EAAE,CAAC,0BAA0B,CAAC,CAAC,CAAC,UAAU,CAAC;QAC3C,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC;QAClC,CAAC,CAAC,UAAU,CAAC,IAAI,C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AC","sourcesContent":["// `no-sample-in-event-handler` — errors when `sample()` / `h.sample()`\n// appears inside an event-handler property (`onClick`, `onInput`,\n// `onSubmit`, …). Event handlers run AFTER mount, with no active\n// render context, so the runtime `sample()` throws `[LLui] sample()\n// can only be called inside a component's view() function`.\n//\n// Catching at compile time turns \"open the dev console, click the\n// button, see the error\" into a build failure on the offending file.\n// Aligned with the framework's \"compile-time errors not lint warnings\"\n// philosophy.\n//\n// The right pattern is to capture at render time:\n// const id = h.sample((s) => s.id)\n// button({ onClick: () => send({ type: 'select', id }) })\n// or to use the mount handle: `handle.getState()` inside the handler.\n\nimport ts from 'typescript'\nimport { rangeFromOffsets } from '../diagnostic.js'\nimport type { CompilerModule } from '../module.js'\n\nconst EVENT_HANDLER_KEY_RE = /^on[A-Z]/\n\nfunction isSampleCall(n: ts.Node): boolean {\n if (!ts.isCallExpression(n)) return false\n if (ts.isIdentifier(n.expression) && n.expression.text === 'sample') return true\n if (\n ts.isPropertyAccessExpression(n.expression) &&\n ts.isIdentifier(n.expression.name) &&\n n.expression.name.text === 'sample'\n ) {\n return true\n }\n return false\n}\n\nfunction findFirstSampleInside(body: ts.Node): ts.CallExpression | undefined {\n let found: ts.CallExpression | undefined\n const walk = (n: ts.Node): void => {\n if (found) return\n if (isSampleCall(n)) {\n found = n as ts.CallExpression\n return\n }\n // DON'T descend into nested functions — sample() inside an inner\n // function (e.g. a setTimeout body or another arrow that captures\n // the event handler's closure) runs at a different time and has\n // its own context check at runtime. Only the directly-synchronous\n // sample call in the handler body is the trap this rule targets.\n if (\n (ts.isArrowFunction(n) || ts.isFunctionExpression(n) || ts.isFunctionDeclaration(n)) &&\n n !== body\n ) {\n return\n }\n ts.forEachChild(n, walk)\n }\n walk(body)\n return found\n}\n\nexport function noSampleInEventHandlerModule(): CompilerModule {\n return {\n name: 'no-sample-in-event-handler',\n compilerVersion: '^0.3.0',\n diagnostics: [\n {\n id: 'llui/no-sample-in-event-handler',\n description:\n '`sample()` inside an event handler — handlers run with no render context; throws at runtime. Capture at render time instead.',\n },\n ],\n visitors: {\n [ts.SyntaxKind.SourceFile]: (ctx, node) => {\n const visited = node as ts.SourceFile\n const sf = ts.createSourceFile(visited.fileName, visited.text, ts.ScriptTarget.Latest, true)\n const walk = (n: ts.Node): void => {\n if (ts.isPropertyAssignment(n)) {\n const key = n.name\n if (ts.isIdentifier(key) && EVENT_HANDLER_KEY_RE.test(key.text)) {\n const value = n.initializer\n if (ts.isArrowFunction(value) || ts.isFunctionExpression(value)) {\n const offender = findFirstSampleInside(value.body)\n if (offender) {\n ctx.reportDiagnostic({\n id: 'llui/no-sample-in-event-handler',\n severity: 'error',\n category: 'reactivity',\n message:\n `\\`sample()\\` is being called inside the \\`${key.text}\\` handler. Handlers run AFTER mount with no active render context, so this throws at runtime ` +\n `(\\`[LLui] sample() can only be called inside a component's view() function\\`). Capture the value at render time instead: ` +\n `\\`const id = h.sample(s => s.id); button({ ${key.text}: () => send({ ..., id }) })\\`. ` +\n `If you need the LATEST state at click time (rare), use the mount handle: ` +\n `\\`handle.getState()\\` inside the handler.`,\n location: {\n file: sf.fileName,\n range: rangeFromOffsets(sf.text, offender.getStart(sf), offender.getEnd()),\n },\n })\n }\n }\n }\n }\n ts.forEachChild(n, walk)\n }\n walk(sf)\n },\n },\n }\n}\n"]}
|