@llui/vite-plugin 0.0.18 → 0.0.19

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.
@@ -451,8 +451,60 @@ function checkChildStaticProps(node, sf, diagnostics) {
451
451
  line,
452
452
  column,
453
453
  });
454
+ continue;
455
+ }
456
+ // props accessor: warn when the returned object contains fresh
457
+ // object/array literals. The prop-diff in `child()` compares by
458
+ // reference per top-level key (Object.is), so a freshly-constructed
459
+ // nested value reports changed on every parent update — propsMsg
460
+ // fires every render, which is wasted work at best and an infinite
461
+ // loop vector when combined with a naive `onMsg` forwarder.
462
+ if (ts.isArrowFunction(prop.initializer) || ts.isFunctionExpression(prop.initializer)) {
463
+ const returned = getReturnedObjectLiteral(prop.initializer);
464
+ if (!returned)
465
+ continue;
466
+ for (const keyProp of returned.properties) {
467
+ if (!ts.isPropertyAssignment(keyProp))
468
+ continue;
469
+ const init = keyProp.initializer;
470
+ if (!ts.isObjectLiteralExpression(init) && !ts.isArrayLiteralExpression(init))
471
+ continue;
472
+ const keyName = ts.isIdentifier(keyProp.name)
473
+ ? keyProp.name.text
474
+ : ts.isStringLiteral(keyProp.name)
475
+ ? keyProp.name.text
476
+ : '<?>';
477
+ const kind = ts.isArrayLiteralExpression(init) ? 'array' : 'object';
478
+ const { line, column } = pos(keyProp, sf);
479
+ diagnostics.push({
480
+ message: `child() at line ${line}: the 'props' accessor returns a fresh ${kind} literal for '${keyName}'. Prop diffing uses Object.is per key, so a freshly-constructed reference reports changed every render — propsMsg will fire on every parent update. Hoist to a module-level constant, reuse a reference from state, or return null from propsMsg when the value is unchanged.`,
481
+ line,
482
+ column,
483
+ });
484
+ }
485
+ }
486
+ }
487
+ }
488
+ function getReturnedObjectLiteral(fn) {
489
+ const body = fn.body;
490
+ if (ts.isParenthesizedExpression(body) && ts.isObjectLiteralExpression(body.expression)) {
491
+ return body.expression;
492
+ }
493
+ if (ts.isObjectLiteralExpression(body))
494
+ return body;
495
+ if (ts.isBlock(body)) {
496
+ for (const stmt of body.statements) {
497
+ if (!ts.isReturnStatement(stmt) || !stmt.expression)
498
+ continue;
499
+ const expr = stmt.expression;
500
+ if (ts.isObjectLiteralExpression(expr))
501
+ return expr;
502
+ if (ts.isParenthesizedExpression(expr) && ts.isObjectLiteralExpression(expr.expression)) {
503
+ return expr.expression;
504
+ }
454
505
  }
455
506
  }
507
+ return null;
456
508
  }
457
509
  // ── Bitmask overflow warning ────────────────────────────────────
458
510
  function collectStatePaths(sf) {
@@ -1 +1 @@
1
- {"version":3,"file":"diagnostics.js","sourceRoot":"","sources":["../src/diagnostics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAA;AAQ3B,MAAM,oBAAoB,GAAG,IAAI,GAAG,CAAC;IACnC,QAAQ;IACR,GAAG;IACH,OAAO;IACP,QAAQ;IACR,UAAU;IACV,SAAS;IACT,SAAS;CACV,CAAC,CAAA;AAEF,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC;IAC9B,GAAG;IACH,MAAM;IACN,SAAS;IACT,OAAO;IACP,GAAG;IACH,YAAY;IACZ,IAAI;IACJ,QAAQ;IACR,QAAQ;IACR,MAAM;IACN,IAAI;IACJ,SAAS;IACT,QAAQ;IACR,KAAK;IACL,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,UAAU;IACV,YAAY;IACZ,QAAQ;IACR,QAAQ;IACR,MAAM;IACN,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,QAAQ;IACR,IAAI;IACJ,GAAG;IACH,QAAQ;IACR,KAAK;IACL,OAAO;IACP,OAAO;IACP,QAAQ;IACR,IAAI;IACJ,MAAM;IACN,MAAM;IACN,KAAK;IACL,IAAI;IACJ,UAAU;IACV,QAAQ;IACR,QAAQ;IACR,GAAG;IACH,KAAK;IACL,UAAU;IACV,SAAS;IACT,QAAQ;IACR,OAAO;IACP,MAAM;IACN,QAAQ;IACR,KAAK;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,CAAC,CAAC,CAAA;IAEpE,qEAAqE;IACrE,0DAA0D;IAC1D,MAAM,UAAU,GAAa,EAAE,CAAA;IAC/B,IAAI,KAAK,GAAG,CAAC,CAAA;IACb,KAAK,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,IAAI,MAAM,EAAE,CAAC;QAChC,IAAI,SAAS,GAAG,KAAK,IAAI,EAAE;YAAE,MAAK;QAClC,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QACtB,KAAK,IAAI,CAAC,CAAA;IACZ,CAAC;IACD,MAAM,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,KAAK,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAC1E,MAAM,aAAa,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAElE,WAAW,CAAC,IAAI,CAAC;QACf,OAAO,EACL,qBAAqB,IAAI,QAAQ,SAAS,6BAA6B;YACvE,IAAI,QAAQ,uCAAuC,SAAS,gBAAgB;YAC5E,wEAAwE;YACxE,0DAA0D;YAC1D,mCAAmC,SAAS,OAAO;YACnD,4BAA4B,aAAa,SAAS,UAAU,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG;YACvF,kBAAkB,UAAU,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,mBAAmB;YACvE,wEAAwE;YACxE,8DAA8D;YAC9D,uEAAuE;YACvE,sBAAsB;QACxB,IAAI;QACJ,MAAM;KACP,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import ts from 'typescript'\n\nexport interface Diagnostic {\n message: string\n line: number\n column: number\n}\n\nconst INTERACTIVE_ELEMENTS = new Set([\n 'button',\n 'a',\n 'input',\n 'select',\n 'textarea',\n 'details',\n 'summary',\n])\n\nconst ELEMENT_HELPERS = new Set([\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\nexport function diagnose(source: string): Diagnostic[] {\n const sf = ts.createSourceFile('input.ts', source, ts.ScriptTarget.Latest, true)\n const diagnostics: Diagnostic[] = []\n\n // Collect Msg type variants for exhaustive update() check\n const msgVariants = collectMsgVariants(sf)\n\n // Collect state access paths for bitmask warning\n const statePaths = collectStatePaths(sf)\n\n function visit(node: ts.Node): void {\n checkMapOnState(node, sf, diagnostics)\n checkExhaustiveUpdate(node, sf, diagnostics, msgVariants)\n checkAccessibility(node, sf, diagnostics)\n checkControlledInput(node, sf, diagnostics)\n checkChildStaticProps(node, sf, diagnostics)\n checkBitmaskOverflow(node, sf, diagnostics, statePaths)\n checkNamespaceImport(node, sf, diagnostics)\n checkSpreadChildren(node, sf, diagnostics)\n checkEmptyProps(node, sf, diagnostics)\n\n ts.forEachChild(node, visit)\n }\n\n visit(sf)\n return diagnostics\n}\n\n// ── \"Almost-optimized\" diagnostics ───────────────────────────────\n\n// Warns when a user writes `import * as L from '@llui/dom'` — the compiler\n// can only recognize named-import helpers, so namespace imports disable\n// template cloning/elSplit for every element call in the file.\nfunction checkNamespaceImport(node: ts.Node, sf: ts.SourceFile, diagnostics: Diagnostic[]): void {\n if (!ts.isImportDeclaration(node)) return\n if (!ts.isStringLiteral(node.moduleSpecifier)) return\n if (node.moduleSpecifier.text !== '@llui/dom') return\n const clause = node.importClause\n if (!clause?.namedBindings) return\n if (!ts.isNamespaceImport(clause.namedBindings)) return\n const name = clause.namedBindings.name.text\n const { line, column } = pos(clause.namedBindings, sf)\n diagnostics.push({\n message: `Namespace import '${name}' from '@llui/dom' at line ${line} disables compiler optimizations. Use named imports instead: import { div, text, ... } from '@llui/dom'.`,\n line,\n column,\n })\n}\n\n// Warns when a children array contains a spread — the compiler can't\n// analyze variable-length children, so it bails on template cloning and\n// falls back to runtime elSplit. Not fatal, but silent.\nfunction checkSpreadChildren(node: ts.Node, sf: ts.SourceFile, diagnostics: Diagnostic[]): void {\n if (!ts.isCallExpression(node)) return\n if (!ts.isIdentifier(node.expression)) return\n if (!ELEMENT_HELPERS.has(node.expression.text)) return\n // Children could be at arguments[0] (children-only overload) or arguments[1]\n for (const arg of node.arguments) {\n if (!ts.isArrayLiteralExpression(arg)) continue\n // Look for \"suspicious\" spreads — ones that aren't obviously returning\n // Node[] from a structural primitive or user-defined view helper.\n for (const el of arg.elements) {\n if (!ts.isSpreadElement(el)) continue\n if (isStructuralSpread(el.expression)) continue\n const { line, column } = pos(arg, sf)\n diagnostics.push({\n message: `Spread in children array of '${node.expression.text}()' at line ${line} disables template-clone compilation. For dynamic child counts, use each() instead.`,\n line,\n column,\n })\n return\n }\n }\n}\n\n// Array iteration methods whose result spreads are the red flag we want\n// to catch — users should use each() instead. Function calls generally\n// return Node[] from structural primitives or user view helpers and are\n// the legitimate way to compose output.\nconst ARRAY_ITERATION_METHODS = new Set([\n 'map',\n 'filter',\n 'flatMap',\n 'slice',\n 'concat',\n 'reverse',\n 'sort',\n])\n\nfunction isStructuralSpread(expr: ts.Expression): boolean {\n // Only keep the warning for suspect patterns: identifier spreads and\n // array-iteration method calls. Everything else is presumed to be a\n // structural primitive or user helper returning Node[].\n if (ts.isCallExpression(expr)) {\n const callee = expr.expression\n if (ts.isPropertyAccessExpression(callee) && ts.isIdentifier(callee.name)) {\n // `...arr.map(...)`, `...arr.filter(...)` — suspect\n return !ARRAY_ITERATION_METHODS.has(callee.name.text)\n }\n // Plain function call `...fn()` — presume structural/helper\n return true\n }\n // Identifier spread (`...arr`) — suspect\n return false\n}\n\n// Warns when an element helper is called with an empty props object — the\n// attrs argument is optional, so `h1({}, [...])` should be `h1([...])`.\nfunction checkEmptyProps(node: ts.Node, sf: ts.SourceFile, diagnostics: Diagnostic[]): void {\n if (!ts.isCallExpression(node)) return\n if (!ts.isIdentifier(node.expression)) return\n if (!ELEMENT_HELPERS.has(node.expression.text)) return\n const firstArg = node.arguments[0]\n if (!firstArg || !ts.isObjectLiteralExpression(firstArg)) return\n if (firstArg.properties.length !== 0) return\n const { line, column } = pos(firstArg, sf)\n diagnostics.push({\n message: `Empty props object passed to '${node.expression.text}()' at line ${line}. The attrs argument is optional — omit it: ${node.expression.text}([...]).`,\n line,\n column,\n })\n}\n\nfunction pos(node: ts.Node, sf: ts.SourceFile): { line: number; column: number } {\n const { line, character } = sf.getLineAndCharacterOfPosition(node.getStart(sf))\n return { line: line + 1, column: character + 1 }\n}\n\nfunction _isInsideEachRender(node: ts.Node): boolean {\n let current = node.parent\n while (current) {\n if (\n (ts.isArrowFunction(current) || ts.isFunctionExpression(current)) &&\n current.parameters.length >= 1\n ) {\n const param = current.parameters[0]!\n // Options bag: ({ item, ... }) => ...\n const hasItemParam =\n ts.isObjectBindingPattern(param.name) &&\n param.name.elements.some(\n (el) => ts.isBindingElement(el) && ts.isIdentifier(el.name) && el.name.text === 'item',\n )\n if (hasItemParam) {\n const propAssign = current.parent\n if (\n ts.isPropertyAssignment(propAssign) &&\n ts.isIdentifier(propAssign.name) &&\n propAssign.name.text === 'render'\n ) {\n return true\n }\n }\n }\n current = current.parent\n }\n return false\n}\n\n// ── .map() on state arrays ───────────────────────────────────────\n\nfunction checkMapOnState(node: ts.Node, sf: ts.SourceFile, diagnostics: Diagnostic[]): void {\n if (!ts.isCallExpression(node)) return\n if (!ts.isPropertyAccessExpression(node.expression)) return\n if (node.expression.name.text !== 'map') return\n\n // Check if receiver involves a state parameter reference\n if (!referencesStateParam(node.expression.expression)) return\n\n // Check if we're inside a view function\n if (!isInsideViewFunction(node)) return\n\n const { line, column } = pos(node, sf)\n diagnostics.push({\n message: `Array .map() on state-derived value at line ${line}. Use each() for reactive lists that update when the array changes.`,\n line,\n column,\n })\n}\n\nfunction referencesStateParam(node: ts.Node): boolean {\n if (ts.isPropertyAccessExpression(node)) {\n return referencesStateParam(node.expression)\n }\n if (ts.isIdentifier(node)) {\n // Check if the identifier is a parameter named 'state' or 's' or matches common patterns\n // Simple heuristic: check if it's a parameter of the view function\n const name = node.text\n return name === 'state' || name === 's' || name === '_state'\n }\n return false\n}\n\nfunction isInsideViewFunction(node: ts.Node): boolean {\n let current = node.parent\n while (current) {\n if (ts.isPropertyAssignment(current)) {\n if (ts.isIdentifier(current.name) && current.name.text === 'view') {\n return true\n }\n }\n current = current.parent\n }\n return false\n}\n\n// ── Exhaustive update() ──────────────────────────────────────────\n\nfunction collectMsgVariants(sf: ts.SourceFile): Set<string> {\n const variants = new Set<string>()\n\n for (const stmt of sf.statements) {\n if (!ts.isTypeAliasDeclaration(stmt)) continue\n if (stmt.name.text !== 'Msg') continue\n\n // Walk the union to find { type: 'literal' } members\n collectUnionVariants(stmt.type, variants)\n }\n\n return variants\n}\n\nfunction collectUnionVariants(type: ts.TypeNode, variants: Set<string>): void {\n if (ts.isUnionTypeNode(type)) {\n for (const member of type.types) {\n collectUnionVariants(member, variants)\n }\n return\n }\n\n if (ts.isTypeLiteralNode(type)) {\n for (const member of type.members) {\n if (!ts.isPropertySignature(member)) continue\n if (!ts.isIdentifier(member.name!) || member.name.text !== 'type') continue\n if (member.type && ts.isLiteralTypeNode(member.type)) {\n if (ts.isStringLiteral(member.type.literal)) {\n variants.add(member.type.literal.text)\n }\n }\n }\n }\n}\n\nfunction checkExhaustiveUpdate(\n node: ts.Node,\n sf: ts.SourceFile,\n diagnostics: Diagnostic[],\n msgVariants: Set<string>,\n): void {\n if (msgVariants.size === 0) return\n if (!ts.isPropertyAssignment(node)) return\n if (!ts.isIdentifier(node.name) || node.name.text !== 'update') return\n\n // Find the switch statement in the update body\n const fn = node.initializer\n if (!ts.isArrowFunction(fn) && !ts.isFunctionExpression(fn)) return\n\n const body = ts.isBlock(fn.body) ? fn.body : null\n if (!body) return\n\n const handledCases = new Set<string>()\n let hasDefault = false\n\n function findSwitch(n: ts.Node): void {\n if (ts.isSwitchStatement(n)) {\n for (const clause of n.caseBlock.clauses) {\n if (ts.isDefaultClause(clause)) {\n hasDefault = true\n } else if (ts.isCaseClause(clause) && ts.isStringLiteral(clause.expression)) {\n handledCases.add(clause.expression.text)\n }\n }\n }\n ts.forEachChild(n, findSwitch)\n }\n\n findSwitch(body)\n\n if (hasDefault) return\n\n const missing = [...msgVariants].filter((v) => !handledCases.has(v))\n if (missing.length === 0) return\n\n const { line, column } = pos(node, sf)\n diagnostics.push({\n message: `update() does not handle message type${missing.length > 1 ? 's' : ''} ${missing.map((m) => `'${m}'`).join(', ')} at line ${line}.`,\n line,\n column,\n })\n}\n\n// ── Accessibility ────────────────────────────────────────────────\n\nfunction checkAccessibility(node: ts.Node, sf: ts.SourceFile, diagnostics: Diagnostic[]): void {\n if (!ts.isCallExpression(node)) return\n if (!ts.isIdentifier(node.expression)) return\n\n const tag = node.expression.text\n if (!ELEMENT_HELPERS.has(tag)) return\n\n const propsArg = node.arguments[0]\n if (!propsArg || !ts.isObjectLiteralExpression(propsArg)) return\n\n const props = getStaticPropKeys(propsArg)\n\n // img without alt\n if (tag === 'img' && !props.has('alt')) {\n const { line, column } = pos(node, sf)\n diagnostics.push({\n message: `<img> at line ${line} has no 'alt' attribute. Add alt text for screen readers, or alt='' for decorative images.`,\n line,\n column,\n })\n }\n\n // onClick on non-interactive element without role\n if (props.has('onClick') && !INTERACTIVE_ELEMENTS.has(tag) && !props.has('role')) {\n const { line, column } = pos(node, sf)\n diagnostics.push({\n message: `onClick on <${tag}> at line ${line} without role and tabIndex. Non-interactive elements with click handlers are not keyboard-accessible. Add role='button' and tabIndex={0}, or use <button>.`,\n line,\n column,\n })\n }\n}\n\n// ── Controlled input ─────────────────────────────────────────────\n\nfunction checkControlledInput(node: ts.Node, sf: ts.SourceFile, diagnostics: Diagnostic[]): void {\n if (!ts.isCallExpression(node)) return\n if (!ts.isIdentifier(node.expression)) return\n\n const tag = node.expression.text\n if (tag !== 'input' && tag !== 'textarea') return\n\n const propsArg = node.arguments[0]\n if (!propsArg || !ts.isObjectLiteralExpression(propsArg)) return\n\n const props = getProps(propsArg)\n\n // Check if value is a reactive binding (arrow function)\n const valueProp = props.get('value')\n if (!valueProp) return\n if (!ts.isArrowFunction(valueProp) && !ts.isFunctionExpression(valueProp)) return\n\n // Must have onInput\n if (!props.has('onInput') && !props.has('onChange')) {\n const { line, column } = pos(node, sf)\n diagnostics.push({\n message: `Controlled input at line ${line}: reactive 'value' binding without 'onInput' handler. The binding will overwrite user input on every state update.`,\n line,\n column,\n })\n }\n}\n\nfunction getStaticPropKeys(obj: ts.ObjectLiteralExpression): Set<string> {\n const keys = new Set<string>()\n for (const prop of obj.properties) {\n if (ts.isPropertyAssignment(prop) && ts.isIdentifier(prop.name)) {\n keys.add(prop.name.text)\n }\n }\n return keys\n}\n\nfunction getProps(obj: ts.ObjectLiteralExpression): Map<string, ts.Expression> {\n const map = new Map<string, ts.Expression>()\n for (const prop of obj.properties) {\n if (ts.isPropertyAssignment(prop) && ts.isIdentifier(prop.name)) {\n map.set(prop.name.text, prop.initializer)\n }\n }\n return map\n}\n\n// ── child() static props ────────────────────────────────────────\n\nfunction checkChildStaticProps(node: ts.Node, sf: ts.SourceFile, diagnostics: Diagnostic[]): void {\n if (!ts.isCallExpression(node)) return\n if (!ts.isIdentifier(node.expression) || node.expression.text !== 'child') return\n\n const arg = node.arguments[0]\n if (!arg || !ts.isObjectLiteralExpression(arg)) return\n\n for (const prop of arg.properties) {\n if (!ts.isPropertyAssignment(prop)) continue\n if (!ts.isIdentifier(prop.name) || prop.name.text !== 'props') continue\n\n // props must be a function, not an object literal\n if (ts.isObjectLiteralExpression(prop.initializer)) {\n const { line, column } = pos(node, sf)\n diagnostics.push({\n message: `child() at line ${line}: 'props' is a static object literal. It must be a reactive accessor function (s => ({ ... })) so props update when parent state changes.`,\n line,\n column,\n })\n }\n }\n}\n\n// ── Bitmask overflow warning ────────────────────────────────────\n\nfunction collectStatePaths(sf: ts.SourceFile): Set<string> {\n const paths = new Set<string>()\n\n function visit(node: ts.Node): void {\n if (\n (ts.isArrowFunction(node) || ts.isFunctionExpression(node)) &&\n node.parameters.length === 1\n ) {\n const param = node.parameters[0]!.name\n if (ts.isIdentifier(param)) {\n // Check if this looks like a reactive accessor\n const parent = node.parent\n if (ts.isPropertyAssignment(parent)) {\n const key = parent.name\n if (ts.isIdentifier(key) && !/^on[A-Z]/.test(key.text)) {\n extractAccessPaths(node.body, param.text, paths)\n }\n } else if (ts.isCallExpression(parent) && parent.arguments[0] === node) {\n extractAccessPaths(node.body, param.text, paths)\n }\n }\n }\n ts.forEachChild(node, visit)\n }\n\n visit(sf)\n return paths\n}\n\nfunction extractAccessPaths(node: ts.Node, paramName: string, paths: Set<string>): void {\n if (ts.isPropertyAccessExpression(node)) {\n const chain = resolveSimpleChain(node, paramName)\n if (chain) paths.add(chain)\n }\n ts.forEachChild(node, (child) => extractAccessPaths(child, paramName, paths))\n}\n\nfunction resolveSimpleChain(node: ts.PropertyAccessExpression, paramName: string): string | null {\n const parts: string[] = []\n let current: ts.Expression = node\n while (ts.isPropertyAccessExpression(current)) {\n parts.unshift(current.name.text)\n current = current.expression\n }\n if (!ts.isIdentifier(current) || current.text !== paramName) return null\n if (parts.length > 2) return parts.slice(0, 2).join('.')\n return parts.join('.')\n}\n\nfunction checkBitmaskOverflow(\n node: ts.Node,\n sf: ts.SourceFile,\n diagnostics: Diagnostic[],\n paths: Set<string>,\n): void {\n // Only emit once, on the component() call\n if (!ts.isCallExpression(node)) return\n if (!ts.isIdentifier(node.expression) || node.expression.text !== 'component') return\n\n const pathCount = paths.size\n if (pathCount <= 31) return\n\n const overflow = pathCount - 31\n const { line, column } = pos(node, sf)\n\n // Group paths by top-level field so authors know which slice to extract.\n // `resolveSimpleChain` already truncates to depth 2 (e.g. \"user.name\"),\n // so splitting on \".\" gives us the top-level field.\n const byTopLevel = new Map<string, number>()\n for (const p of paths) {\n const top = p.split('.', 1)[0]!\n byTopLevel.set(top, (byTopLevel.get(top) ?? 0) + 1)\n }\n const sorted = [...byTopLevel.entries()].sort((a, b) => b[1] - a[1])\n\n // Pick the top fields whose combined path count would bring us under\n // the 31 limit. These are the best candidates to extract.\n const candidates: string[] = []\n let saved = 0\n for (const [field, n] of sorted) {\n if (pathCount - saved <= 31) break\n candidates.push(field)\n saved += n\n }\n const breakdown = sorted.map(([field, n]) => `${field} (${n})`).join(', ')\n const candidateList = candidates.map((f) => `\\`${f}\\``).join(', ')\n\n diagnostics.push({\n message:\n `Component at line ${line} has ${pathCount} unique state access paths ` +\n `(${overflow} past the 31-path limit). Paths 32..${pathCount} fall back to ` +\n `FULL_MASK — their changes re-evaluate every binding in the component, ` +\n `negating the bitmask optimization for those updates.\\n\\n` +\n `Top-level fields by path count: ${breakdown}.\\n\\n` +\n `Recommended fix: extract ${candidateList} into ${candidates.length === 1 ? 'a' : ''} ` +\n `child component${candidates.length === 1 ? '' : 's'} via \\`child()\\` ` +\n `(see /api/dom#child). Each child gets its own 31-path bitmask, so the ` +\n `extracted paths no longer count against the parent's limit. ` +\n `Alternative: use \\`sliceHandler\\` to embed a state machine that owns ` +\n `the field's reducer.`,\n line,\n column,\n })\n}\n"]}
1
+ {"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CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAElE,WAAW,CAAC,IAAI,CAAC;QACf,OAAO,EACL,qBAAqB,IAAI,QAAQ,SAAS,6BAA6B;YACvE,IAAI,QAAQ,uCAAuC,SAAS,gBAAgB;YAC5E,wEAAwE;YACxE,0DAA0D;YAC1D,mCAAmC,SAAS,OAAO;YACnD,4BAA4B,aAAa,SAAS,UAAU,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG;YACvF,kBAAkB,UAAU,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,mBAAmB;YACvE,wEAAwE;YACxE,8DAA8D;YAC9D,uEAAuE;YACvE,sBAAsB;QACxB,IAAI;QACJ,MAAM;KACP,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import ts from 'typescript'\n\nexport interface Diagnostic {\n message: string\n line: number\n column: number\n}\n\nconst INTERACTIVE_ELEMENTS = new Set([\n 'button',\n 'a',\n 'input',\n 'select',\n 'textarea',\n 'details',\n 'summary',\n])\n\nconst ELEMENT_HELPERS = new Set([\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\nexport function diagnose(source: string): Diagnostic[] {\n const sf = ts.createSourceFile('input.ts', source, ts.ScriptTarget.Latest, true)\n const diagnostics: Diagnostic[] = []\n\n // Collect Msg type variants for exhaustive update() check\n const msgVariants = collectMsgVariants(sf)\n\n // Collect state access paths for bitmask warning\n const statePaths = collectStatePaths(sf)\n\n function visit(node: ts.Node): void {\n checkMapOnState(node, sf, diagnostics)\n checkExhaustiveUpdate(node, sf, diagnostics, msgVariants)\n checkAccessibility(node, sf, diagnostics)\n checkControlledInput(node, sf, diagnostics)\n checkChildStaticProps(node, sf, diagnostics)\n checkBitmaskOverflow(node, sf, diagnostics, statePaths)\n checkNamespaceImport(node, sf, diagnostics)\n checkSpreadChildren(node, sf, diagnostics)\n checkEmptyProps(node, sf, diagnostics)\n\n ts.forEachChild(node, visit)\n }\n\n visit(sf)\n return diagnostics\n}\n\n// ── \"Almost-optimized\" diagnostics ───────────────────────────────\n\n// Warns when a user writes `import * as L from '@llui/dom'` — the compiler\n// can only recognize named-import helpers, so namespace imports disable\n// template cloning/elSplit for every element call in the file.\nfunction checkNamespaceImport(node: ts.Node, sf: ts.SourceFile, diagnostics: Diagnostic[]): void {\n if (!ts.isImportDeclaration(node)) return\n if (!ts.isStringLiteral(node.moduleSpecifier)) return\n if (node.moduleSpecifier.text !== '@llui/dom') return\n const clause = node.importClause\n if (!clause?.namedBindings) return\n if (!ts.isNamespaceImport(clause.namedBindings)) return\n const name = clause.namedBindings.name.text\n const { line, column } = pos(clause.namedBindings, sf)\n diagnostics.push({\n message: `Namespace import '${name}' from '@llui/dom' at line ${line} disables compiler optimizations. Use named imports instead: import { div, text, ... } from '@llui/dom'.`,\n line,\n column,\n })\n}\n\n// Warns when a children array contains a spread — the compiler can't\n// analyze variable-length children, so it bails on template cloning and\n// falls back to runtime elSplit. Not fatal, but silent.\nfunction checkSpreadChildren(node: ts.Node, sf: ts.SourceFile, diagnostics: Diagnostic[]): void {\n if (!ts.isCallExpression(node)) return\n if (!ts.isIdentifier(node.expression)) return\n if (!ELEMENT_HELPERS.has(node.expression.text)) return\n // Children could be at arguments[0] (children-only overload) or arguments[1]\n for (const arg of node.arguments) {\n if (!ts.isArrayLiteralExpression(arg)) continue\n // Look for \"suspicious\" spreads — ones that aren't obviously returning\n // Node[] from a structural primitive or user-defined view helper.\n for (const el of arg.elements) {\n if (!ts.isSpreadElement(el)) continue\n if (isStructuralSpread(el.expression)) continue\n const { line, column } = pos(arg, sf)\n diagnostics.push({\n message: `Spread in children array of '${node.expression.text}()' at line ${line} disables template-clone compilation. For dynamic child counts, use each() instead.`,\n line,\n column,\n })\n return\n }\n }\n}\n\n// Array iteration methods whose result spreads are the red flag we want\n// to catch — users should use each() instead. Function calls generally\n// return Node[] from structural primitives or user view helpers and are\n// the legitimate way to compose output.\nconst ARRAY_ITERATION_METHODS = new Set([\n 'map',\n 'filter',\n 'flatMap',\n 'slice',\n 'concat',\n 'reverse',\n 'sort',\n])\n\nfunction isStructuralSpread(expr: ts.Expression): boolean {\n // Only keep the warning for suspect patterns: identifier spreads and\n // array-iteration method calls. Everything else is presumed to be a\n // structural primitive or user helper returning Node[].\n if (ts.isCallExpression(expr)) {\n const callee = expr.expression\n if (ts.isPropertyAccessExpression(callee) && ts.isIdentifier(callee.name)) {\n // `...arr.map(...)`, `...arr.filter(...)` — suspect\n return !ARRAY_ITERATION_METHODS.has(callee.name.text)\n }\n // Plain function call `...fn()` — presume structural/helper\n return true\n }\n // Identifier spread (`...arr`) — suspect\n return false\n}\n\n// Warns when an element helper is called with an empty props object — the\n// attrs argument is optional, so `h1({}, [...])` should be `h1([...])`.\nfunction checkEmptyProps(node: ts.Node, sf: ts.SourceFile, diagnostics: Diagnostic[]): void {\n if (!ts.isCallExpression(node)) return\n if (!ts.isIdentifier(node.expression)) return\n if (!ELEMENT_HELPERS.has(node.expression.text)) return\n const firstArg = node.arguments[0]\n if (!firstArg || !ts.isObjectLiteralExpression(firstArg)) return\n if (firstArg.properties.length !== 0) return\n const { line, column } = pos(firstArg, sf)\n diagnostics.push({\n message: `Empty props object passed to '${node.expression.text}()' at line ${line}. The attrs argument is optional — omit it: ${node.expression.text}([...]).`,\n line,\n column,\n })\n}\n\nfunction pos(node: ts.Node, sf: ts.SourceFile): { line: number; column: number } {\n const { line, character } = sf.getLineAndCharacterOfPosition(node.getStart(sf))\n return { line: line + 1, column: character + 1 }\n}\n\nfunction _isInsideEachRender(node: ts.Node): boolean {\n let current = node.parent\n while (current) {\n if (\n (ts.isArrowFunction(current) || ts.isFunctionExpression(current)) &&\n current.parameters.length >= 1\n ) {\n const param = current.parameters[0]!\n // Options bag: ({ item, ... }) => ...\n const hasItemParam =\n ts.isObjectBindingPattern(param.name) &&\n param.name.elements.some(\n (el) => ts.isBindingElement(el) && ts.isIdentifier(el.name) && el.name.text === 'item',\n )\n if (hasItemParam) {\n const propAssign = current.parent\n if (\n ts.isPropertyAssignment(propAssign) &&\n ts.isIdentifier(propAssign.name) &&\n propAssign.name.text === 'render'\n ) {\n return true\n }\n }\n }\n current = current.parent\n }\n return false\n}\n\n// ── .map() on state arrays ───────────────────────────────────────\n\nfunction checkMapOnState(node: ts.Node, sf: ts.SourceFile, diagnostics: Diagnostic[]): void {\n if (!ts.isCallExpression(node)) return\n if (!ts.isPropertyAccessExpression(node.expression)) return\n if (node.expression.name.text !== 'map') return\n\n // Check if receiver involves a state parameter reference\n if (!referencesStateParam(node.expression.expression)) return\n\n // Check if we're inside a view function\n if (!isInsideViewFunction(node)) return\n\n const { line, column } = pos(node, sf)\n diagnostics.push({\n message: `Array .map() on state-derived value at line ${line}. Use each() for reactive lists that update when the array changes.`,\n line,\n column,\n })\n}\n\nfunction referencesStateParam(node: ts.Node): boolean {\n if (ts.isPropertyAccessExpression(node)) {\n return referencesStateParam(node.expression)\n }\n if (ts.isIdentifier(node)) {\n // Check if the identifier is a parameter named 'state' or 's' or matches common patterns\n // Simple heuristic: check if it's a parameter of the view function\n const name = node.text\n return name === 'state' || name === 's' || name === '_state'\n }\n return false\n}\n\nfunction isInsideViewFunction(node: ts.Node): boolean {\n let current = node.parent\n while (current) {\n if (ts.isPropertyAssignment(current)) {\n if (ts.isIdentifier(current.name) && current.name.text === 'view') {\n return true\n }\n }\n current = current.parent\n }\n return false\n}\n\n// ── Exhaustive update() ──────────────────────────────────────────\n\nfunction collectMsgVariants(sf: ts.SourceFile): Set<string> {\n const variants = new Set<string>()\n\n for (const stmt of sf.statements) {\n if (!ts.isTypeAliasDeclaration(stmt)) continue\n if (stmt.name.text !== 'Msg') continue\n\n // Walk the union to find { type: 'literal' } members\n collectUnionVariants(stmt.type, variants)\n }\n\n return variants\n}\n\nfunction collectUnionVariants(type: ts.TypeNode, variants: Set<string>): void {\n if (ts.isUnionTypeNode(type)) {\n for (const member of type.types) {\n collectUnionVariants(member, variants)\n }\n return\n }\n\n if (ts.isTypeLiteralNode(type)) {\n for (const member of type.members) {\n if (!ts.isPropertySignature(member)) continue\n if (!ts.isIdentifier(member.name!) || member.name.text !== 'type') continue\n if (member.type && ts.isLiteralTypeNode(member.type)) {\n if (ts.isStringLiteral(member.type.literal)) {\n variants.add(member.type.literal.text)\n }\n }\n }\n }\n}\n\nfunction checkExhaustiveUpdate(\n node: ts.Node,\n sf: ts.SourceFile,\n diagnostics: Diagnostic[],\n msgVariants: Set<string>,\n): void {\n if (msgVariants.size === 0) return\n if (!ts.isPropertyAssignment(node)) return\n if (!ts.isIdentifier(node.name) || node.name.text !== 'update') return\n\n // Find the switch statement in the update body\n const fn = node.initializer\n if (!ts.isArrowFunction(fn) && !ts.isFunctionExpression(fn)) return\n\n const body = ts.isBlock(fn.body) ? fn.body : null\n if (!body) return\n\n const handledCases = new Set<string>()\n let hasDefault = false\n\n function findSwitch(n: ts.Node): void {\n if (ts.isSwitchStatement(n)) {\n for (const clause of n.caseBlock.clauses) {\n if (ts.isDefaultClause(clause)) {\n hasDefault = true\n } else if (ts.isCaseClause(clause) && ts.isStringLiteral(clause.expression)) {\n handledCases.add(clause.expression.text)\n }\n }\n }\n ts.forEachChild(n, findSwitch)\n }\n\n findSwitch(body)\n\n if (hasDefault) return\n\n const missing = [...msgVariants].filter((v) => !handledCases.has(v))\n if (missing.length === 0) return\n\n const { line, column } = pos(node, sf)\n diagnostics.push({\n message: `update() does not handle message type${missing.length > 1 ? 's' : ''} ${missing.map((m) => `'${m}'`).join(', ')} at line ${line}.`,\n line,\n column,\n })\n}\n\n// ── Accessibility ────────────────────────────────────────────────\n\nfunction checkAccessibility(node: ts.Node, sf: ts.SourceFile, diagnostics: Diagnostic[]): void {\n if (!ts.isCallExpression(node)) return\n if (!ts.isIdentifier(node.expression)) return\n\n const tag = node.expression.text\n if (!ELEMENT_HELPERS.has(tag)) return\n\n const propsArg = node.arguments[0]\n if (!propsArg || !ts.isObjectLiteralExpression(propsArg)) return\n\n const props = getStaticPropKeys(propsArg)\n\n // img without alt\n if (tag === 'img' && !props.has('alt')) {\n const { line, column } = pos(node, sf)\n diagnostics.push({\n message: `<img> at line ${line} has no 'alt' attribute. Add alt text for screen readers, or alt='' for decorative images.`,\n line,\n column,\n })\n }\n\n // onClick on non-interactive element without role\n if (props.has('onClick') && !INTERACTIVE_ELEMENTS.has(tag) && !props.has('role')) {\n const { line, column } = pos(node, sf)\n diagnostics.push({\n message: `onClick on <${tag}> at line ${line} without role and tabIndex. Non-interactive elements with click handlers are not keyboard-accessible. Add role='button' and tabIndex={0}, or use <button>.`,\n line,\n column,\n })\n }\n}\n\n// ── Controlled input ─────────────────────────────────────────────\n\nfunction checkControlledInput(node: ts.Node, sf: ts.SourceFile, diagnostics: Diagnostic[]): void {\n if (!ts.isCallExpression(node)) return\n if (!ts.isIdentifier(node.expression)) return\n\n const tag = node.expression.text\n if (tag !== 'input' && tag !== 'textarea') return\n\n const propsArg = node.arguments[0]\n if (!propsArg || !ts.isObjectLiteralExpression(propsArg)) return\n\n const props = getProps(propsArg)\n\n // Check if value is a reactive binding (arrow function)\n const valueProp = props.get('value')\n if (!valueProp) return\n if (!ts.isArrowFunction(valueProp) && !ts.isFunctionExpression(valueProp)) return\n\n // Must have onInput\n if (!props.has('onInput') && !props.has('onChange')) {\n const { line, column } = pos(node, sf)\n diagnostics.push({\n message: `Controlled input at line ${line}: reactive 'value' binding without 'onInput' handler. The binding will overwrite user input on every state update.`,\n line,\n column,\n })\n }\n}\n\nfunction getStaticPropKeys(obj: ts.ObjectLiteralExpression): Set<string> {\n const keys = new Set<string>()\n for (const prop of obj.properties) {\n if (ts.isPropertyAssignment(prop) && ts.isIdentifier(prop.name)) {\n keys.add(prop.name.text)\n }\n }\n return keys\n}\n\nfunction getProps(obj: ts.ObjectLiteralExpression): Map<string, ts.Expression> {\n const map = new Map<string, ts.Expression>()\n for (const prop of obj.properties) {\n if (ts.isPropertyAssignment(prop) && ts.isIdentifier(prop.name)) {\n map.set(prop.name.text, prop.initializer)\n }\n }\n return map\n}\n\n// ── child() static props ────────────────────────────────────────\n\nfunction checkChildStaticProps(node: ts.Node, sf: ts.SourceFile, diagnostics: Diagnostic[]): void {\n if (!ts.isCallExpression(node)) return\n if (!ts.isIdentifier(node.expression) || node.expression.text !== 'child') return\n\n const arg = node.arguments[0]\n if (!arg || !ts.isObjectLiteralExpression(arg)) return\n\n for (const prop of arg.properties) {\n if (!ts.isPropertyAssignment(prop)) continue\n if (!ts.isIdentifier(prop.name) || prop.name.text !== 'props') continue\n\n // props must be a function, not an object literal\n if (ts.isObjectLiteralExpression(prop.initializer)) {\n const { line, column } = pos(node, sf)\n diagnostics.push({\n message: `child() at line ${line}: 'props' is a static object literal. It must be a reactive accessor function (s => ({ ... })) so props update when parent state changes.`,\n line,\n column,\n })\n continue\n }\n\n // props accessor: warn when the returned object contains fresh\n // object/array literals. The prop-diff in `child()` compares by\n // reference per top-level key (Object.is), so a freshly-constructed\n // nested value reports changed on every parent update — propsMsg\n // fires every render, which is wasted work at best and an infinite\n // loop vector when combined with a naive `onMsg` forwarder.\n if (ts.isArrowFunction(prop.initializer) || ts.isFunctionExpression(prop.initializer)) {\n const returned = getReturnedObjectLiteral(prop.initializer)\n if (!returned) continue\n for (const keyProp of returned.properties) {\n if (!ts.isPropertyAssignment(keyProp)) continue\n const init = keyProp.initializer\n if (!ts.isObjectLiteralExpression(init) && !ts.isArrayLiteralExpression(init)) continue\n const keyName = ts.isIdentifier(keyProp.name)\n ? keyProp.name.text\n : ts.isStringLiteral(keyProp.name)\n ? keyProp.name.text\n : '<?>'\n const kind = ts.isArrayLiteralExpression(init) ? 'array' : 'object'\n const { line, column } = pos(keyProp, sf)\n diagnostics.push({\n message: `child() at line ${line}: the 'props' accessor returns a fresh ${kind} literal for '${keyName}'. Prop diffing uses Object.is per key, so a freshly-constructed reference reports changed every render — propsMsg will fire on every parent update. Hoist to a module-level constant, reuse a reference from state, or return null from propsMsg when the value is unchanged.`,\n line,\n column,\n })\n }\n }\n }\n}\n\nfunction getReturnedObjectLiteral(\n fn: ts.ArrowFunction | ts.FunctionExpression,\n): ts.ObjectLiteralExpression | null {\n const body = fn.body\n if (ts.isParenthesizedExpression(body) && ts.isObjectLiteralExpression(body.expression)) {\n return body.expression\n }\n if (ts.isObjectLiteralExpression(body)) return body\n if (ts.isBlock(body)) {\n for (const stmt of body.statements) {\n if (!ts.isReturnStatement(stmt) || !stmt.expression) continue\n const expr = stmt.expression\n if (ts.isObjectLiteralExpression(expr)) return expr\n if (ts.isParenthesizedExpression(expr) && ts.isObjectLiteralExpression(expr.expression)) {\n return expr.expression\n }\n }\n }\n return null\n}\n\n// ── Bitmask overflow warning ────────────────────────────────────\n\nfunction collectStatePaths(sf: ts.SourceFile): Set<string> {\n const paths = new Set<string>()\n\n function visit(node: ts.Node): void {\n if (\n (ts.isArrowFunction(node) || ts.isFunctionExpression(node)) &&\n node.parameters.length === 1\n ) {\n const param = node.parameters[0]!.name\n if (ts.isIdentifier(param)) {\n // Check if this looks like a reactive accessor\n const parent = node.parent\n if (ts.isPropertyAssignment(parent)) {\n const key = parent.name\n if (ts.isIdentifier(key) && !/^on[A-Z]/.test(key.text)) {\n extractAccessPaths(node.body, param.text, paths)\n }\n } else if (ts.isCallExpression(parent) && parent.arguments[0] === node) {\n extractAccessPaths(node.body, param.text, paths)\n }\n }\n }\n ts.forEachChild(node, visit)\n }\n\n visit(sf)\n return paths\n}\n\nfunction extractAccessPaths(node: ts.Node, paramName: string, paths: Set<string>): void {\n if (ts.isPropertyAccessExpression(node)) {\n const chain = resolveSimpleChain(node, paramName)\n if (chain) paths.add(chain)\n }\n ts.forEachChild(node, (child) => extractAccessPaths(child, paramName, paths))\n}\n\nfunction resolveSimpleChain(node: ts.PropertyAccessExpression, paramName: string): string | null {\n const parts: string[] = []\n let current: ts.Expression = node\n while (ts.isPropertyAccessExpression(current)) {\n parts.unshift(current.name.text)\n current = current.expression\n }\n if (!ts.isIdentifier(current) || current.text !== paramName) return null\n if (parts.length > 2) return parts.slice(0, 2).join('.')\n return parts.join('.')\n}\n\nfunction checkBitmaskOverflow(\n node: ts.Node,\n sf: ts.SourceFile,\n diagnostics: Diagnostic[],\n paths: Set<string>,\n): void {\n // Only emit once, on the component() call\n if (!ts.isCallExpression(node)) return\n if (!ts.isIdentifier(node.expression) || node.expression.text !== 'component') return\n\n const pathCount = paths.size\n if (pathCount <= 31) return\n\n const overflow = pathCount - 31\n const { line, column } = pos(node, sf)\n\n // Group paths by top-level field so authors know which slice to extract.\n // `resolveSimpleChain` already truncates to depth 2 (e.g. \"user.name\"),\n // so splitting on \".\" gives us the top-level field.\n const byTopLevel = new Map<string, number>()\n for (const p of paths) {\n const top = p.split('.', 1)[0]!\n byTopLevel.set(top, (byTopLevel.get(top) ?? 0) + 1)\n }\n const sorted = [...byTopLevel.entries()].sort((a, b) => b[1] - a[1])\n\n // Pick the top fields whose combined path count would bring us under\n // the 31 limit. These are the best candidates to extract.\n const candidates: string[] = []\n let saved = 0\n for (const [field, n] of sorted) {\n if (pathCount - saved <= 31) break\n candidates.push(field)\n saved += n\n }\n const breakdown = sorted.map(([field, n]) => `${field} (${n})`).join(', ')\n const candidateList = candidates.map((f) => `\\`${f}\\``).join(', ')\n\n diagnostics.push({\n message:\n `Component at line ${line} has ${pathCount} unique state access paths ` +\n `(${overflow} past the 31-path limit). Paths 32..${pathCount} fall back to ` +\n `FULL_MASK — their changes re-evaluate every binding in the component, ` +\n `negating the bitmask optimization for those updates.\\n\\n` +\n `Top-level fields by path count: ${breakdown}.\\n\\n` +\n `Recommended fix: extract ${candidateList} into ${candidates.length === 1 ? 'a' : ''} ` +\n `child component${candidates.length === 1 ? '' : 's'} via \\`child()\\` ` +\n `(see /api/dom#child). Each child gets its own 31-path bitmask, so the ` +\n `extracted paths no longer count against the parent's limit. ` +\n `Alternative: use \\`sliceHandler\\` to embed a state machine that owns ` +\n `the field's reducer.`,\n line,\n column,\n })\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAiB,MAAM,MAAM,CAAA;AA0BjD,MAAM,WAAW,iBAAiB;IAChC;;;;;;;;;OASG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,KAAK,CAAA;CACzB;AAED,MAAM,CAAC,OAAO,UAAU,IAAI,CAAC,OAAO,GAAE,iBAAsB,GAAG,MAAM,CA6IpE"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAiB,MAAM,MAAM,CAAA;AA0BjD,MAAM,WAAW,iBAAiB;IAChC;;;;;;;;;OASG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,KAAK,CAAA;CACzB;AAED,MAAM,CAAC,OAAO,UAAU,IAAI,CAAC,OAAO,GAAE,iBAAsB,GAAG,MAAM,CAqMpE"}
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import MagicString from 'magic-string';
2
- import { existsSync, readFileSync, watch as fsWatch } from 'node:fs';
2
+ import { existsSync, readFileSync, writeFileSync, watch as fsWatch } from 'node:fs';
3
3
  import { dirname, resolve } from 'node:path';
4
4
  import { transformLlui } from './transform.js';
5
5
  import { diagnose } from './diagnostics.js';
@@ -38,22 +38,52 @@ export default function llui(options = {}) {
38
38
  const activeFilePath = resolve(findWorkspaceRoot(), 'node_modules/.cache/llui-mcp/active.json');
39
39
  let mcpWatcher = null;
40
40
  let dirWatcher = null;
41
- function readMcpPort() {
41
+ // Cached once Vite's HTTP server emits `listening`. `stampDevUrl()`
42
+ // uses this to write the URL into the marker file — either immediately
43
+ // (if MCP already started and wrote one) or later when the marker
44
+ // appears via the directory watcher (MCP-starts-after-Vite path).
45
+ let cachedDevUrl = null;
46
+ function readMcpMarker() {
42
47
  try {
43
48
  if (!existsSync(activeFilePath))
44
49
  return null;
45
50
  const data = JSON.parse(readFileSync(activeFilePath, 'utf8'));
46
- return typeof data.port === 'number' ? data.port : null;
51
+ if (typeof data.port !== 'number')
52
+ return null;
53
+ return { port: data.port, ...(data.devUrl ? { devUrl: data.devUrl } : {}) };
47
54
  }
48
55
  catch {
49
56
  return null;
50
57
  }
51
58
  }
59
+ /**
60
+ * Idempotently write `cachedDevUrl` into the marker file. No-op if the
61
+ * URL hasn't been captured yet (Vite hasn't emitted `listening`) or if
62
+ * the marker file doesn't exist (MCP hasn't started yet). Covers both
63
+ * orderings — the listening hook calls this after caching, and the
64
+ * directory watcher calls it when the marker appears later.
65
+ */
66
+ function stampDevUrl() {
67
+ if (cachedDevUrl === null)
68
+ return;
69
+ if (!existsSync(activeFilePath))
70
+ return;
71
+ try {
72
+ const marker = JSON.parse(readFileSync(activeFilePath, 'utf8'));
73
+ if (marker.devUrl === cachedDevUrl)
74
+ return;
75
+ marker.devUrl = cachedDevUrl;
76
+ writeFileSync(activeFilePath, JSON.stringify(marker));
77
+ }
78
+ catch {
79
+ // Best-effort — failure to update the marker should not crash Vite
80
+ }
81
+ }
52
82
  function notifyMcpReady(server) {
53
- const port = readMcpPort();
54
- if (port === null)
83
+ const marker = readMcpMarker();
84
+ if (marker === null)
55
85
  return;
56
- server.ws.send({ type: 'custom', event: 'llui:mcp-ready', data: { port } });
86
+ server.ws.send({ type: 'custom', event: 'llui:mcp-ready', data: marker });
57
87
  }
58
88
  function notifyMcpOffline(server) {
59
89
  server.ws.send({ type: 'custom', event: 'llui:mcp-offline', data: {} });
@@ -73,15 +103,15 @@ export default function llui(options = {}) {
73
103
  // the browser connect to the actual port (which may differ from
74
104
  // the compile-time default if MCP was started with LLUI_MCP_PORT).
75
105
  server.middlewares.use('/__llui_mcp_status', (_req, res) => {
76
- const port = readMcpPort();
77
- if (port === null) {
106
+ const marker = readMcpMarker();
107
+ if (marker === null) {
78
108
  res.statusCode = 404;
79
109
  res.end();
80
110
  return;
81
111
  }
82
112
  res.statusCode = 200;
83
113
  res.setHeader('content-type', 'application/json');
84
- res.end(JSON.stringify({ port }));
114
+ res.end(JSON.stringify({ port: marker.port }));
85
115
  });
86
116
  // Watch the marker file for create/delete. fs.watch on the parent
87
117
  // directory catches both events; the file itself may not exist
@@ -96,6 +126,11 @@ export default function llui(options = {}) {
96
126
  if (filename !== 'active.json')
97
127
  return;
98
128
  if (existsSync(activeFilePath)) {
129
+ // Stamp BEFORE notifying so the `llui:mcp-ready` payload
130
+ // carries the cached devUrl. This is the MCP-after-Vite
131
+ // path: listening already fired and cached the URL; the
132
+ // marker is only now appearing.
133
+ stampDevUrl();
99
134
  notifyMcpReady(server);
100
135
  }
101
136
  else {
@@ -133,6 +168,27 @@ export default function llui(options = {}) {
133
168
  mcpWatcher = null;
134
169
  dirWatcher = null;
135
170
  });
171
+ // Once Vite's HTTP server is listening, cache our dev URL and stamp
172
+ // it into the marker file. Two orderings are possible:
173
+ // (a) MCP started FIRST → marker exists now → stampDevUrl() writes
174
+ // it, and we broadcast llui:mcp-ready so the browser picks up
175
+ // the devUrl without relying on an incidental fs.watch tick
176
+ // (which can miss on NFS/SMB).
177
+ // (b) MCP will start LATER → marker doesn't exist yet → stamp is a
178
+ // no-op. When MCP eventually writes the marker, the directory
179
+ // watcher fires, calls stampDevUrl(), and notifies.
180
+ server.httpServer?.once('listening', () => {
181
+ const address = server.httpServer?.address();
182
+ if (!address || typeof address !== 'object')
183
+ return;
184
+ const host = address.address === '::' || address.address === '0.0.0.0' ? 'localhost' : address.address;
185
+ cachedDevUrl = `http://${host}:${address.port}`;
186
+ stampDevUrl();
187
+ // Broadcast after stamping so the payload carries devUrl. Only
188
+ // fires in case (a) — notifyMcpReady no-ops when the marker is
189
+ // absent.
190
+ notifyMcpReady(server);
191
+ });
136
192
  },
137
193
  transform(code, id) {
138
194
  if (!id.endsWith('.ts') && !id.endsWith('.tsx'))
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,WAAW,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,KAAK,IAAI,OAAO,EAAkB,MAAM,SAAS,CAAA;AACpF,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAE3C;;;;;GAKG;AACH,SAAS,iBAAiB,CAAC,QAAgB,OAAO,CAAC,GAAG,EAAE;IACtD,IAAI,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC,CAAA;IACxB,IAAI,eAAe,GAAkB,IAAI,CAAA;IACzC,OAAO,IAAI,EAAE,CAAC;QACZ,IAAI,UAAU,CAAC,OAAO,CAAC,GAAG,EAAE,qBAAqB,CAAC,CAAC;YAAE,OAAO,GAAG,CAAA;QAC/D,IAAI,UAAU,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;YAAE,OAAO,GAAG,CAAA;QAChD,IAAI,UAAU,CAAC,OAAO,CAAC,GA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C;oBACN,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,WAAW,CAAC,CAAA;gBACrD,CAAC;YACH,CAAC;YAED,OAAO;gBACL,IAAI,EAAE,CAAC,CAAC,QAAQ,EAAE;gBAClB,GAAG,EAAE,CAAC,CAAC,WAAW,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,cAAc,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;aACtE,CAAA;QACH,CAAC;KACF,CAAA;AACH,CAAC","sourcesContent":["import type { Plugin, ViteDevServer } from 'vite'\nimport MagicString from 'magic-string'\nimport { existsSync, readFileSync, watch as fsWatch, type FSWatcher } from 'node:fs'\nimport { dirname, resolve } from 'node:path'\nimport { transformLlui } from './transform.js'\nimport { diagnose } from './diagnostics.js'\n\n/**\n * Locate the workspace root so we share the MCP active marker file\n * with @llui/mcp regardless of which subdirectory the dev server runs in.\n * Mirrors `findWorkspaceRoot` from @llui/mcp — duplicated to avoid a\n * vite-plugin → mcp dependency cycle. The contract must stay in sync.\n */\nfunction findWorkspaceRoot(start: string = process.cwd()): string {\n let dir = resolve(start)\n let lastPackageJson: string | null = null\n while (true) {\n if (existsSync(resolve(dir, 'pnpm-workspace.yaml'))) return dir\n if (existsSync(resolve(dir, '.git'))) return dir\n if (existsSync(resolve(dir, 'package.json'))) lastPackageJson = dir\n const parent = dirname(dir)\n if (parent === dir) return lastPackageJson ?? start\n dir = parent\n }\n}\n\nexport interface LluiPluginOptions {\n /**\n * Port for the MCP debug bridge. In dev mode, the runtime relay connects\n * to `ws://127.0.0.1:<port>` so an external `llui-mcp` server can forward\n * tool calls into the running app.\n *\n * Defaults to `false` (opt-in). Pass a number (typically `5200`) to\n * enable. When enabled but the MCP server isn't running, the plugin\n * returns 404 from its discovery endpoint and the browser silently\n * skips the connection — no retry noise.\n */\n mcpPort?: number | false\n}\n\nexport default function llui(options: LluiPluginOptions = {}): Plugin {\n let devMode = false\n // MCP is opt-in: developers who want interactive debugging pass an\n // explicit port. Leaving it off avoids 404 polling in projects that\n // don't use the companion server.\n const mcpPort =\n options.mcpPort === false || options.mcpPort === undefined ? null : options.mcpPort\n\n // File-based handshake with @llui/mcp. The MCP server writes a marker\n // file when its bridge starts; we watch it and send a Vite HMR custom\n // event so the browser can call __lluiConnect() automatically — without\n // retry spam, regardless of whether MCP or Vite started first.\n const activeFilePath = resolve(findWorkspaceRoot(), 'node_modules/.cache/llui-mcp/active.json')\n let mcpWatcher: FSWatcher | null = null\n let dirWatcher: FSWatcher | null = null\n\n function readMcpPort(): number | null {\n try {\n if (!existsSync(activeFilePath)) return null\n const data = JSON.parse(readFileSync(activeFilePath, 'utf8')) as { port?: number }\n return typeof data.port === 'number' ? data.port : null\n } catch {\n return null\n }\n }\n\n function notifyMcpReady(server: ViteDevServer): void {\n const port = readMcpPort()\n if (port === null) return\n server.ws.send({ type: 'custom', event: 'llui:mcp-ready', data: { port } })\n }\n\n function notifyMcpOffline(server: ViteDevServer): void {\n server.ws.send({ type: 'custom', event: 'llui:mcp-offline', data: {} })\n }\n\n return {\n name: 'llui',\n enforce: 'pre',\n\n configResolved(config) {\n devMode = config.command === 'serve' || config.mode === 'development'\n },\n\n configureServer(server) {\n if (mcpPort === null) return\n\n // HTTP endpoint: the browser fetches this on load to discover the\n // current MCP port. Avoids the race where HMR events sent before\n // the import.meta.hot listener registers get dropped — and lets\n // the browser connect to the actual port (which may differ from\n // the compile-time default if MCP was started with LLUI_MCP_PORT).\n server.middlewares.use('/__llui_mcp_status', (_req, res) => {\n const port = readMcpPort()\n if (port === null) {\n res.statusCode = 404\n res.end()\n return\n }\n res.statusCode = 200\n res.setHeader('content-type', 'application/json')\n res.end(JSON.stringify({ port }))\n })\n\n // Watch the marker file for create/delete. fs.watch on the parent\n // directory catches both events; the file itself may not exist\n // when we start watching.\n const dir = dirname(activeFilePath)\n try {\n // Watch the parent directory for the marker file appearing/disappearing\n const watchDir = (): void => {\n if (!existsSync(dir)) return\n dirWatcher = fsWatch(dir, (_event, filename) => {\n if (filename !== 'active.json') return\n if (existsSync(activeFilePath)) {\n notifyMcpReady(server)\n } else {\n notifyMcpOffline(server)\n }\n })\n }\n if (existsSync(dir)) {\n watchDir()\n } else {\n // Parent directory doesn't exist yet — poll for it briefly\n const poll = setInterval(() => {\n if (existsSync(dir)) {\n clearInterval(poll)\n watchDir()\n }\n }, 1000)\n // Clean up the poller if vite shuts down before MCP starts\n server.httpServer?.on('close', () => clearInterval(poll))\n }\n } catch {\n // fs.watch can fail on some filesystems — degrade silently\n }\n\n // Re-send the ready event when a new HMR client connects, in case\n // the page loads while MCP is already running.\n server.ws.on('connection', () => {\n if (existsSync(activeFilePath)) notifyMcpReady(server)\n })\n\n server.httpServer?.on('close', () => {\n mcpWatcher?.close()\n dirWatcher?.close()\n mcpWatcher = null\n dirWatcher = null\n })\n },\n\n transform(code, id) {\n if (!id.endsWith('.ts') && !id.endsWith('.tsx')) return\n\n for (const d of diagnose(code)) {\n this.warn(d.message, { line: d.line, column: d.column })\n }\n\n const result = transformLlui(code, id, devMode, mcpPort)\n if (!result) return undefined\n\n // Apply per-statement edits via MagicString for accurate source maps.\n // Untouched statements keep their original positions.\n const s = new MagicString(code)\n for (const edit of result.edits) {\n if (edit.start === edit.end) {\n // Insert at position — appendRight for middle, append for end-of-file\n if (edit.start === code.length) s.append(edit.replacement)\n else s.appendRight(edit.start, edit.replacement)\n } else {\n s.overwrite(edit.start, edit.end, edit.replacement)\n }\n }\n\n return {\n code: s.toString(),\n map: s.generateMap({ source: id, includeContent: true, hires: true }),\n }\n },\n }\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,WAAW,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,KAAK,IAAI,OAAO,EAAkB,MAAM,SAAS,CAAA;AACnG,OAAO,EAAE,O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plugin, ViteDevServer } from 'vite'\nimport MagicString from 'magic-string'\nimport { existsSync, readFileSync, writeFileSync, watch as fsWatch, type FSWatcher } from 'node:fs'\nimport { dirname, resolve } from 'node:path'\nimport { transformLlui } from './transform.js'\nimport { diagnose } from './diagnostics.js'\n\n/**\n * Locate the workspace root so we share the MCP active marker file\n * with @llui/mcp regardless of which subdirectory the dev server runs in.\n * Mirrors `findWorkspaceRoot` from @llui/mcp — duplicated to avoid a\n * vite-plugin → mcp dependency cycle. The contract must stay in sync.\n */\nfunction findWorkspaceRoot(start: string = process.cwd()): string {\n let dir = resolve(start)\n let lastPackageJson: string | null = null\n while (true) {\n if (existsSync(resolve(dir, 'pnpm-workspace.yaml'))) return dir\n if (existsSync(resolve(dir, '.git'))) return dir\n if (existsSync(resolve(dir, 'package.json'))) lastPackageJson = dir\n const parent = dirname(dir)\n if (parent === dir) return lastPackageJson ?? start\n dir = parent\n }\n}\n\nexport interface LluiPluginOptions {\n /**\n * Port for the MCP debug bridge. In dev mode, the runtime relay connects\n * to `ws://127.0.0.1:<port>` so an external `llui-mcp` server can forward\n * tool calls into the running app.\n *\n * Defaults to `false` (opt-in). Pass a number (typically `5200`) to\n * enable. When enabled but the MCP server isn't running, the plugin\n * returns 404 from its discovery endpoint and the browser silently\n * skips the connection — no retry noise.\n */\n mcpPort?: number | false\n}\n\nexport default function llui(options: LluiPluginOptions = {}): Plugin {\n let devMode = false\n // MCP is opt-in: developers who want interactive debugging pass an\n // explicit port. Leaving it off avoids 404 polling in projects that\n // don't use the companion server.\n const mcpPort =\n options.mcpPort === false || options.mcpPort === undefined ? null : options.mcpPort\n\n // File-based handshake with @llui/mcp. The MCP server writes a marker\n // file when its bridge starts; we watch it and send a Vite HMR custom\n // event so the browser can call __lluiConnect() automatically — without\n // retry spam, regardless of whether MCP or Vite started first.\n const activeFilePath = resolve(findWorkspaceRoot(), 'node_modules/.cache/llui-mcp/active.json')\n let mcpWatcher: FSWatcher | null = null\n let dirWatcher: FSWatcher | null = null\n // Cached once Vite's HTTP server emits `listening`. `stampDevUrl()`\n // uses this to write the URL into the marker file — either immediately\n // (if MCP already started and wrote one) or later when the marker\n // appears via the directory watcher (MCP-starts-after-Vite path).\n let cachedDevUrl: string | null = null\n\n function readMcpMarker(): { port: number; devUrl?: string } | null {\n try {\n if (!existsSync(activeFilePath)) return null\n const data = JSON.parse(readFileSync(activeFilePath, 'utf8')) as {\n port?: number\n devUrl?: string\n }\n if (typeof data.port !== 'number') return null\n return { port: data.port, ...(data.devUrl ? { devUrl: data.devUrl } : {}) }\n } catch {\n return null\n }\n }\n\n /**\n * Idempotently write `cachedDevUrl` into the marker file. No-op if the\n * URL hasn't been captured yet (Vite hasn't emitted `listening`) or if\n * the marker file doesn't exist (MCP hasn't started yet). Covers both\n * orderings — the listening hook calls this after caching, and the\n * directory watcher calls it when the marker appears later.\n */\n function stampDevUrl(): void {\n if (cachedDevUrl === null) return\n if (!existsSync(activeFilePath)) return\n try {\n const marker = JSON.parse(readFileSync(activeFilePath, 'utf8')) as Record<string, unknown>\n if (marker.devUrl === cachedDevUrl) return\n marker.devUrl = cachedDevUrl\n writeFileSync(activeFilePath, JSON.stringify(marker))\n } catch {\n // Best-effort — failure to update the marker should not crash Vite\n }\n }\n\n function notifyMcpReady(server: ViteDevServer): void {\n const marker = readMcpMarker()\n if (marker === null) return\n server.ws.send({ type: 'custom', event: 'llui:mcp-ready', data: marker })\n }\n\n function notifyMcpOffline(server: ViteDevServer): void {\n server.ws.send({ type: 'custom', event: 'llui:mcp-offline', data: {} })\n }\n\n return {\n name: 'llui',\n enforce: 'pre',\n\n configResolved(config) {\n devMode = config.command === 'serve' || config.mode === 'development'\n },\n\n configureServer(server) {\n if (mcpPort === null) return\n\n // HTTP endpoint: the browser fetches this on load to discover the\n // current MCP port. Avoids the race where HMR events sent before\n // the import.meta.hot listener registers get dropped — and lets\n // the browser connect to the actual port (which may differ from\n // the compile-time default if MCP was started with LLUI_MCP_PORT).\n server.middlewares.use('/__llui_mcp_status', (_req, res) => {\n const marker = readMcpMarker()\n if (marker === null) {\n res.statusCode = 404\n res.end()\n return\n }\n res.statusCode = 200\n res.setHeader('content-type', 'application/json')\n res.end(JSON.stringify({ port: marker.port }))\n })\n\n // Watch the marker file for create/delete. fs.watch on the parent\n // directory catches both events; the file itself may not exist\n // when we start watching.\n const dir = dirname(activeFilePath)\n try {\n // Watch the parent directory for the marker file appearing/disappearing\n const watchDir = (): void => {\n if (!existsSync(dir)) return\n dirWatcher = fsWatch(dir, (_event, filename) => {\n if (filename !== 'active.json') return\n if (existsSync(activeFilePath)) {\n // Stamp BEFORE notifying so the `llui:mcp-ready` payload\n // carries the cached devUrl. This is the MCP-after-Vite\n // path: listening already fired and cached the URL; the\n // marker is only now appearing.\n stampDevUrl()\n notifyMcpReady(server)\n } else {\n notifyMcpOffline(server)\n }\n })\n }\n if (existsSync(dir)) {\n watchDir()\n } else {\n // Parent directory doesn't exist yet — poll for it briefly\n const poll = setInterval(() => {\n if (existsSync(dir)) {\n clearInterval(poll)\n watchDir()\n }\n }, 1000)\n // Clean up the poller if vite shuts down before MCP starts\n server.httpServer?.on('close', () => clearInterval(poll))\n }\n } catch {\n // fs.watch can fail on some filesystems — degrade silently\n }\n\n // Re-send the ready event when a new HMR client connects, in case\n // the page loads while MCP is already running.\n server.ws.on('connection', () => {\n if (existsSync(activeFilePath)) notifyMcpReady(server)\n })\n\n server.httpServer?.on('close', () => {\n mcpWatcher?.close()\n dirWatcher?.close()\n mcpWatcher = null\n dirWatcher = null\n })\n\n // Once Vite's HTTP server is listening, cache our dev URL and stamp\n // it into the marker file. Two orderings are possible:\n // (a) MCP started FIRST → marker exists now → stampDevUrl() writes\n // it, and we broadcast llui:mcp-ready so the browser picks up\n // the devUrl without relying on an incidental fs.watch tick\n // (which can miss on NFS/SMB).\n // (b) MCP will start LATER → marker doesn't exist yet → stamp is a\n // no-op. When MCP eventually writes the marker, the directory\n // watcher fires, calls stampDevUrl(), and notifies.\n server.httpServer?.once('listening', () => {\n const address = server.httpServer?.address()\n if (!address || typeof address !== 'object') return\n const host =\n address.address === '::' || address.address === '0.0.0.0' ? 'localhost' : address.address\n cachedDevUrl = `http://${host}:${address.port}`\n stampDevUrl()\n // Broadcast after stamping so the payload carries devUrl. Only\n // fires in case (a) — notifyMcpReady no-ops when the marker is\n // absent.\n notifyMcpReady(server)\n })\n },\n\n transform(code, id) {\n if (!id.endsWith('.ts') && !id.endsWith('.tsx')) return\n\n for (const d of diagnose(code)) {\n this.warn(d.message, { line: d.line, column: d.column })\n }\n\n const result = transformLlui(code, id, devMode, mcpPort)\n if (!result) return undefined\n\n // Apply per-statement edits via MagicString for accurate source maps.\n // Untouched statements keep their original positions.\n const s = new MagicString(code)\n for (const edit of result.edits) {\n if (edit.start === edit.end) {\n // Insert at position — appendRight for middle, append for end-of-file\n if (edit.start === code.length) s.append(edit.replacement)\n else s.appendRight(edit.start, edit.replacement)\n } else {\n s.overwrite(edit.start, edit.end, edit.replacement)\n }\n }\n\n return {\n code: s.toString(),\n map: s.generateMap({ source: id, includeContent: true, hires: true }),\n }\n },\n }\n}\n"]}
package/dist/transform.js CHANGED
@@ -1267,8 +1267,16 @@ function analyzeModifiedFields(stateExpr, stateName, topLevelBits) {
1267
1267
  const modified = [];
1268
1268
  for (const prop of stateExpr.properties) {
1269
1269
  if (ts.isSpreadAssignment(prop)) {
1270
- // { ...state }the spread doesn't modify fields
1271
- continue;
1270
+ // Only `...state` is safe to ignore re-spreading state back into
1271
+ // state doesn't change any field's identity. ANY other spread
1272
+ // (e.g. `...msg.props`, `...someObj`) can overwrite arbitrary
1273
+ // top-level fields with new references, and we cannot know which
1274
+ // ones statically. Bail out so the generic Phase 2 path runs
1275
+ // `__dirty` at runtime and produces a correct mask.
1276
+ if (ts.isIdentifier(prop.expression) && prop.expression.text === stateName) {
1277
+ continue;
1278
+ }
1279
+ return null;
1272
1280
  }
1273
1281
  if (ts.isPropertyAssignment(prop) && ts.isIdentifier(prop.name)) {
1274
1282
  const fieldName = prop.name.text;