@pyreon/compiler 0.12.4 → 0.12.5
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/lib/analysis/index.js.html +1 -1
- package/lib/index.js +84 -8
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
- package/src/jsx.ts +79 -9
- package/src/tests/jsx.test.ts +73 -1
|
@@ -5386,7 +5386,7 @@ var drawChart = (function (exports) {
|
|
|
5386
5386
|
</script>
|
|
5387
5387
|
<script>
|
|
5388
5388
|
/*<!--*/
|
|
5389
|
-
const data = {"version":2,"tree":{"name":"root","children":[{"name":"index.js","children":[{"name":"src","children":[{"uid":"
|
|
5389
|
+
const data = {"version":2,"tree":{"name":"root","children":[{"name":"index.js","children":[{"name":"src","children":[{"uid":"c92f44a6-1","name":"jsx.ts"},{"uid":"c92f44a6-3","name":"project-scanner.ts"},{"uid":"c92f44a6-5","name":"react-intercept.ts"},{"uid":"c92f44a6-7","name":"index.ts"}]}]}],"isRoot":true},"nodeParts":{"c92f44a6-1":{"renderedLength":28290,"gzipLength":7871,"brotliLength":0,"metaUid":"c92f44a6-0"},"c92f44a6-3":{"renderedLength":4762,"gzipLength":1730,"brotliLength":0,"metaUid":"c92f44a6-2"},"c92f44a6-5":{"renderedLength":27692,"gzipLength":6920,"brotliLength":0,"metaUid":"c92f44a6-4"},"c92f44a6-7":{"renderedLength":0,"gzipLength":0,"brotliLength":0,"metaUid":"c92f44a6-6"}},"nodeMetas":{"c92f44a6-0":{"id":"/src/jsx.ts","moduleParts":{"index.js":"c92f44a6-1"},"imported":[{"uid":"c92f44a6-8"}],"importedBy":[{"uid":"c92f44a6-6"}]},"c92f44a6-2":{"id":"/src/project-scanner.ts","moduleParts":{"index.js":"c92f44a6-3"},"imported":[{"uid":"c92f44a6-9"},{"uid":"c92f44a6-10"}],"importedBy":[{"uid":"c92f44a6-6"}]},"c92f44a6-4":{"id":"/src/react-intercept.ts","moduleParts":{"index.js":"c92f44a6-5"},"imported":[{"uid":"c92f44a6-8"}],"importedBy":[{"uid":"c92f44a6-6"}]},"c92f44a6-6":{"id":"/src/index.ts","moduleParts":{"index.js":"c92f44a6-7"},"imported":[{"uid":"c92f44a6-0"},{"uid":"c92f44a6-2"},{"uid":"c92f44a6-4"}],"importedBy":[],"isEntry":true},"c92f44a6-8":{"id":"typescript","moduleParts":{},"imported":[],"importedBy":[{"uid":"c92f44a6-0"},{"uid":"c92f44a6-4"}]},"c92f44a6-9":{"id":"node:fs","moduleParts":{},"imported":[],"importedBy":[{"uid":"c92f44a6-2"}]},"c92f44a6-10":{"id":"node:path","moduleParts":{},"imported":[],"importedBy":[{"uid":"c92f44a6-2"}]}},"env":{"rollup":"4.23.0"},"options":{"gzip":true,"brotli":false,"sourcemap":false}};
|
|
5390
5390
|
|
|
5391
5391
|
const run = () => {
|
|
5392
5392
|
const width = window.innerWidth;
|
package/lib/index.js
CHANGED
|
@@ -85,6 +85,7 @@ function transformJSX(code, filename = "input.tsx") {
|
|
|
85
85
|
let needsBindTextImportGlobal = false;
|
|
86
86
|
let needsBindDirectImportGlobal = false;
|
|
87
87
|
let needsBindImportGlobal = false;
|
|
88
|
+
let needsApplyPropsImportGlobal = false;
|
|
88
89
|
/**
|
|
89
90
|
* If `node` is a fully-static JSX element/fragment, register a module-scope
|
|
90
91
|
* hoist for it and return the generated variable name. Otherwise return null.
|
|
@@ -122,7 +123,7 @@ function transformJSX(code, filename = "input.tsx") {
|
|
|
122
123
|
}
|
|
123
124
|
/** Try to emit a template for a JsxElement. Returns true if handled. */
|
|
124
125
|
function tryTemplateEmit(node) {
|
|
125
|
-
if (templateElementCount(node) < 1) return false;
|
|
126
|
+
if (templateElementCount(node, true) < 1) return false;
|
|
126
127
|
const tplCall = buildTemplateCall(node);
|
|
127
128
|
if (!tplCall) return false;
|
|
128
129
|
const start = node.getStart(sf);
|
|
@@ -236,6 +237,7 @@ function transformJSX(code, filename = "input.tsx") {
|
|
|
236
237
|
const runtimeDomImports = ["_tpl"];
|
|
237
238
|
if (needsBindDirectImportGlobal) runtimeDomImports.push("_bindDirect");
|
|
238
239
|
if (needsBindTextImportGlobal) runtimeDomImports.push("_bindText");
|
|
240
|
+
if (needsApplyPropsImportGlobal) runtimeDomImports.push("_applyProps");
|
|
239
241
|
const reactivityImports = needsBindImportGlobal ? `\nimport { _bind } from "@pyreon/reactivity";` : "";
|
|
240
242
|
result = `import { ${runtimeDomImports.join(", ")} } from "@pyreon/runtime-dom";${reactivityImports}\n` + result;
|
|
241
243
|
}
|
|
@@ -245,10 +247,18 @@ function transformJSX(code, filename = "input.tsx") {
|
|
|
245
247
|
usesTemplates: needsTplImport,
|
|
246
248
|
warnings
|
|
247
249
|
};
|
|
248
|
-
/**
|
|
249
|
-
|
|
250
|
+
/**
|
|
251
|
+
* Check if attributes prevent template emission.
|
|
252
|
+
* - `key` always bails (VNode reconciliation prop)
|
|
253
|
+
* - Spread on inner elements bails (too complex to merge in _bind)
|
|
254
|
+
* - Spread on root element is allowed — applied via applyProps in _bind
|
|
255
|
+
*/
|
|
256
|
+
function hasBailAttr(node, isRoot = false) {
|
|
250
257
|
for (const attr of jsxAttrs(node)) {
|
|
251
|
-
if (ts.isJsxSpreadAttribute(attr))
|
|
258
|
+
if (ts.isJsxSpreadAttribute(attr)) {
|
|
259
|
+
if (isRoot) continue;
|
|
260
|
+
return true;
|
|
261
|
+
}
|
|
252
262
|
if (ts.isJsxAttribute(attr) && ts.isIdentifier(attr.name) && attr.name.text === "key") return true;
|
|
253
263
|
}
|
|
254
264
|
return false;
|
|
@@ -271,10 +281,10 @@ function transformJSX(code, filename = "input.tsx") {
|
|
|
271
281
|
* Count DOM elements in a JSX subtree. Returns -1 if the tree is not
|
|
272
282
|
* eligible for template emission.
|
|
273
283
|
*/
|
|
274
|
-
function templateElementCount(node) {
|
|
284
|
+
function templateElementCount(node, isRoot = false) {
|
|
275
285
|
const tag = jsxTagName(node);
|
|
276
286
|
if (!tag || !isLowerCase(tag)) return -1;
|
|
277
|
-
if (hasBailAttr(node)) return -1;
|
|
287
|
+
if (hasBailAttr(node, isRoot)) return -1;
|
|
278
288
|
if (!ts.isJsxElement(node)) return 1;
|
|
279
289
|
let count = 1;
|
|
280
290
|
for (const child of node.children) {
|
|
@@ -306,6 +316,7 @@ function transformJSX(code, filename = "input.tsx") {
|
|
|
306
316
|
const reactiveBindExprs = [];
|
|
307
317
|
let needsBindTextImport = false;
|
|
308
318
|
let needsBindDirectImport = false;
|
|
319
|
+
let needsApplyPropsImport = false;
|
|
309
320
|
function nextVar() {
|
|
310
321
|
return `__e${varIdx++}`;
|
|
311
322
|
}
|
|
@@ -434,6 +445,13 @@ function transformJSX(code, filename = "input.tsx") {
|
|
|
434
445
|
}
|
|
435
446
|
/** Process a single attribute, returning HTML to append. */
|
|
436
447
|
function processOneAttr(attr, varName) {
|
|
448
|
+
if (ts.isJsxSpreadAttribute(attr)) {
|
|
449
|
+
const expr = sliceExpr(attr.expression);
|
|
450
|
+
needsApplyPropsImport = true;
|
|
451
|
+
if (containsCall(attr.expression)) reactiveBindExprs.push(`_applyProps(${varName}, ${expr})`);
|
|
452
|
+
else bindLines.push(`_applyProps(${varName}, ${expr})`);
|
|
453
|
+
return "";
|
|
454
|
+
}
|
|
437
455
|
if (!ts.isJsxAttribute(attr)) return "";
|
|
438
456
|
const attrName = ts.isIdentifier(attr.name) ? attr.name.text : "";
|
|
439
457
|
if (attrName === "key") return "";
|
|
@@ -457,7 +475,11 @@ function transformJSX(code, filename = "input.tsx") {
|
|
|
457
475
|
needsBindTextImport = true;
|
|
458
476
|
const d = nextDisp();
|
|
459
477
|
bindLines.push(`const ${d} = _bindText(${directRef}, ${tVar})`);
|
|
460
|
-
} else
|
|
478
|
+
} else {
|
|
479
|
+
needsBindImportGlobal = true;
|
|
480
|
+
const d = nextDisp();
|
|
481
|
+
bindLines.push(`const ${d} = _bind(() => { ${tVar}.data = ${expr} })`);
|
|
482
|
+
}
|
|
461
483
|
return needsPlaceholder ? "<!>" : "";
|
|
462
484
|
}
|
|
463
485
|
/** Emit bind lines for a static text expression child. */
|
|
@@ -516,6 +538,7 @@ function transformJSX(code, filename = "input.tsx") {
|
|
|
516
538
|
if (html === null) return null;
|
|
517
539
|
if (needsBindTextImport) needsBindTextImportGlobal = true;
|
|
518
540
|
if (needsBindDirectImport) needsBindDirectImportGlobal = true;
|
|
541
|
+
if (needsApplyPropsImport) needsApplyPropsImportGlobal = true;
|
|
519
542
|
const escaped = html.replace(/\\/g, "\\\\").replace(/"/g, "\\\"");
|
|
520
543
|
if (reactiveBindExprs.length > 0) {
|
|
521
544
|
needsBindImportGlobal = true;
|
|
@@ -668,13 +691,66 @@ function isStaticChild(child) {
|
|
|
668
691
|
function isStatic(node) {
|
|
669
692
|
return ts.isStringLiteral(node) || ts.isNumericLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node) || node.kind === ts.SyntaxKind.TrueKeyword || node.kind === ts.SyntaxKind.FalseKeyword || node.kind === ts.SyntaxKind.NullKeyword || node.kind === ts.SyntaxKind.UndefinedKeyword;
|
|
670
693
|
}
|
|
694
|
+
/** Known pure global functions that don't read signals. */
|
|
695
|
+
const PURE_CALLS = new Set([
|
|
696
|
+
"Math.max",
|
|
697
|
+
"Math.min",
|
|
698
|
+
"Math.abs",
|
|
699
|
+
"Math.floor",
|
|
700
|
+
"Math.ceil",
|
|
701
|
+
"Math.round",
|
|
702
|
+
"Math.pow",
|
|
703
|
+
"Math.sqrt",
|
|
704
|
+
"Math.random",
|
|
705
|
+
"Math.trunc",
|
|
706
|
+
"Math.sign",
|
|
707
|
+
"Number.parseInt",
|
|
708
|
+
"Number.parseFloat",
|
|
709
|
+
"Number.isNaN",
|
|
710
|
+
"Number.isFinite",
|
|
711
|
+
"parseInt",
|
|
712
|
+
"parseFloat",
|
|
713
|
+
"isNaN",
|
|
714
|
+
"isFinite",
|
|
715
|
+
"String.fromCharCode",
|
|
716
|
+
"String.fromCodePoint",
|
|
717
|
+
"Object.keys",
|
|
718
|
+
"Object.values",
|
|
719
|
+
"Object.entries",
|
|
720
|
+
"Object.assign",
|
|
721
|
+
"Object.freeze",
|
|
722
|
+
"Object.create",
|
|
723
|
+
"Array.from",
|
|
724
|
+
"Array.isArray",
|
|
725
|
+
"Array.of",
|
|
726
|
+
"JSON.stringify",
|
|
727
|
+
"JSON.parse",
|
|
728
|
+
"encodeURIComponent",
|
|
729
|
+
"decodeURIComponent",
|
|
730
|
+
"encodeURI",
|
|
731
|
+
"decodeURI",
|
|
732
|
+
"Date.now"
|
|
733
|
+
]);
|
|
734
|
+
/** Check if a call expression calls a known pure function with static args. */
|
|
735
|
+
function isPureStaticCall(node) {
|
|
736
|
+
const callee = node.expression;
|
|
737
|
+
let name = "";
|
|
738
|
+
if (ts.isIdentifier(callee)) name = callee.text;
|
|
739
|
+
else if (ts.isPropertyAccessExpression(callee) && ts.isIdentifier(callee.expression)) name = `${callee.expression.text}.${callee.name.text}`;
|
|
740
|
+
if (!PURE_CALLS.has(name)) return false;
|
|
741
|
+
return node.arguments.every((arg) => !ts.isSpreadElement(arg) && isStatic(arg));
|
|
742
|
+
}
|
|
671
743
|
function shouldWrap(node) {
|
|
672
744
|
if (ts.isArrowFunction(node) || ts.isFunctionExpression(node)) return false;
|
|
673
745
|
if (isStatic(node)) return false;
|
|
746
|
+
if (ts.isCallExpression(node) && isPureStaticCall(node)) return false;
|
|
674
747
|
return containsCall(node);
|
|
675
748
|
}
|
|
676
749
|
function containsCall(node) {
|
|
677
|
-
if (ts.isCallExpression(node))
|
|
750
|
+
if (ts.isCallExpression(node)) {
|
|
751
|
+
if (isPureStaticCall(node)) return false;
|
|
752
|
+
return true;
|
|
753
|
+
}
|
|
678
754
|
if (ts.isTaggedTemplateExpression(node)) return true;
|
|
679
755
|
if (ts.isArrowFunction(node) || ts.isFunctionExpression(node)) return false;
|
|
680
756
|
return ts.forEachChild(node, containsCall) ?? false;
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/jsx.ts","../src/project-scanner.ts","../src/react-intercept.ts"],"sourcesContent":["/**\n * JSX transform — wraps dynamic JSX expressions in `() =>` so the Pyreon runtime\n * receives reactive getters instead of eagerly-evaluated snapshot values.\n *\n * Rules:\n * - `<div>{expr}</div>` → `<div>{() => expr}</div>` (child)\n * - `<div class={expr}>` → `<div class={() => expr}>` (prop)\n * - `<button onClick={fn}>` → unchanged (event handler)\n * - `<div>{() => expr}</div>` → unchanged (already wrapped)\n * - `<div>{\"literal\"}</div>` → unchanged (static)\n *\n * Static VNode hoisting:\n * - Fully static JSX in expression containers is hoisted to module scope:\n * `{<span>Hello</span>}` → `const _$h0 = <span>Hello</span>` + `{_$h0}`\n * - Hoisted nodes are created ONCE at module initialisation, not per-instance.\n * - A JSX node is static if: all props are string literals / booleans / static\n * values, and all children are text nodes or other static JSX nodes.\n *\n * Template emission:\n * - JSX element trees with ≥ 2 DOM elements (no components, no spread attrs)\n * are compiled to `_tpl(html, bindFn)` calls instead of nested `h()` calls.\n * - The HTML string is parsed once via <template>.innerHTML, then cloneNode(true)\n * for each instance (~5-10x faster than sequential createElement calls).\n * - Static attributes are baked into the HTML string; dynamic attributes and\n * text content use renderEffect in the bind function.\n *\n * Implementation: TypeScript parser for positions + magic-string replacements.\n * No extra runtime dependencies — `typescript` is already in devDependencies.\n *\n * Known limitation (v0): expressions inside *nested* JSX within a child\n * expression container are not individually wrapped. They are still reactive\n * because the outer wrapper re-evaluates the whole subtree, just at a coarser\n * granularity. Fine-grained nested wrapping is planned for a future pass.\n */\n\nimport ts from 'typescript'\n\nexport interface CompilerWarning {\n /** Warning message */\n message: string\n /** Source file line number (1-based) */\n line: number\n /** Source file column number (0-based) */\n column: number\n /** Warning code for filtering */\n code: 'signal-call-in-jsx' | 'missing-key-on-for' | 'signal-in-static-prop'\n}\n\nexport interface TransformResult {\n /** Transformed source code (JSX preserved, only expression containers modified) */\n code: string\n /** Whether the output uses _tpl/_re template helpers (needs auto-import) */\n usesTemplates?: boolean\n /** Compiler warnings for common mistakes */\n warnings: CompilerWarning[]\n}\n\n// Props that should never be wrapped in a reactive getter\nconst SKIP_PROPS = new Set(['key', 'ref'])\n// Event handler pattern: onClick, onInput, onMouseEnter, …\nconst EVENT_RE = /^on[A-Z]/\n// Events delegated to the container — must match runtime DELEGATED_EVENTS set\nconst DELEGATED_EVENTS = new Set([\n 'click',\n 'dblclick',\n 'contextmenu',\n 'focusin',\n 'focusout',\n 'input',\n 'change',\n 'keydown',\n 'keyup',\n 'mousedown',\n 'mouseup',\n 'mousemove',\n 'mouseover',\n 'mouseout',\n 'pointerdown',\n 'pointerup',\n 'pointermove',\n 'pointerover',\n 'pointerout',\n 'touchstart',\n 'touchend',\n 'touchmove',\n 'submit',\n])\n\nexport function transformJSX(code: string, filename = 'input.tsx'): TransformResult {\n const scriptKind =\n filename.endsWith('.tsx') || filename.endsWith('.jsx') ? ts.ScriptKind.TSX : ts.ScriptKind.TSX // default to TSX so JSX is always parsed\n\n const sf = ts.createSourceFile(\n filename,\n code,\n ts.ScriptTarget.ESNext,\n /* setParentNodes */ true,\n scriptKind,\n )\n\n type Replacement = { start: number; end: number; text: string }\n const replacements: Replacement[] = []\n const warnings: CompilerWarning[] = []\n\n function warn(node: ts.Node, message: string, warnCode: CompilerWarning['code']): void {\n const { line, character } = sf.getLineAndCharacterOfPosition(node.getStart(sf))\n warnings.push({ message, line: line + 1, column: character, code: warnCode })\n }\n\n // ── Static hoisting state ─────────────────────────────────────────────────\n type Hoist = { name: string; text: string }\n const hoists: Hoist[] = []\n let hoistIdx = 0\n let needsTplImport = false\n let needsRpImport = false\n let needsBindTextImportGlobal = false\n let needsBindDirectImportGlobal = false\n let needsBindImportGlobal = false\n\n /**\n * If `node` is a fully-static JSX element/fragment, register a module-scope\n * hoist for it and return the generated variable name. Otherwise return null.\n */\n function maybeHoist(node: ts.Node): string | null {\n if (\n (ts.isJsxElement(node) || ts.isJsxSelfClosingElement(node) || ts.isJsxFragment(node)) &&\n isStaticJSXNode(node as ts.JsxElement | ts.JsxSelfClosingElement | ts.JsxFragment)\n ) {\n const name = `_$h${hoistIdx++}`\n const text = code.slice(node.getStart(sf), node.getEnd())\n hoists.push({ name, text })\n return name\n }\n return null\n }\n\n function wrap(expr: ts.Expression): void {\n const start = expr.getStart(sf)\n const end = expr.getEnd()\n replacements.push({ start, end, text: `() => ${code.slice(start, end)}` })\n }\n\n /** Try to hoist or wrap an expression, pushing a replacement if needed. */\n function hoistOrWrap(expr: ts.Expression): void {\n const hoistName = maybeHoist(expr)\n if (hoistName) {\n replacements.push({ start: expr.getStart(sf), end: expr.getEnd(), text: hoistName })\n } else if (shouldWrap(expr)) {\n wrap(expr)\n }\n }\n\n // ── walk sub-handlers ───────────────────────────────────────────────────────\n\n /** Try to emit a template for a JsxElement. Returns true if handled. */\n function tryTemplateEmit(node: ts.JsxElement): boolean {\n const elemCount = templateElementCount(node)\n if (elemCount < 1) return false\n const tplCall = buildTemplateCall(node)\n if (!tplCall) return false\n const start = node.getStart(sf)\n const end = node.getEnd()\n const parent = node.parent\n const needsBraces = parent && (ts.isJsxElement(parent) || ts.isJsxFragment(parent))\n replacements.push({ start, end, text: needsBraces ? `{${tplCall}}` : tplCall })\n needsTplImport = true\n return true\n }\n\n /** Emit warnings for common JSX mistakes (e.g. <For> without by). */\n function checkForWarnings(node: ts.JsxElement | ts.JsxSelfClosingElement): void {\n const opening = ts.isJsxElement(node) ? node.openingElement : node\n const tagName = ts.isIdentifier(opening.tagName) ? opening.tagName.text : ''\n if (tagName !== 'For') return\n const hasBy = opening.attributes.properties.some(\n (p) => ts.isJsxAttribute(p) && ts.isIdentifier(p.name) && p.name.text === 'by',\n )\n if (!hasBy) {\n warn(\n opening.tagName,\n `<For> without a \"by\" prop will use index-based diffing, which is slower and may cause bugs with stateful children. Add by={(item) => item.id} for efficient keyed reconciliation.`,\n 'missing-key-on-for',\n )\n }\n }\n\n /** Handle a JSX attribute node — wrap or hoist its value if needed.\n *\n * Both DOM and component props are processed:\n * - DOM props: () => expr — applyProp creates renderEffect\n * - Component props: _rp(() => expr) — makeReactiveProps converts to getters\n *\n * The _rp() brand distinguishes compiler wrappers from user-written accessor\n * props (like Show's when, For's each) so makeReactiveProps only converts\n * compiler-emitted wrappers.\n */\n function handleJsxAttribute(node: ts.JsxAttribute): void {\n const name = ts.isIdentifier(node.name) ? node.name.text : ''\n if (SKIP_PROPS.has(name) || EVENT_RE.test(name)) return\n if (!node.initializer || !ts.isJsxExpression(node.initializer)) return\n const expr = node.initializer.expression\n if (!expr) return\n\n const openingEl = node.parent.parent as ts.JsxOpeningElement | ts.JsxSelfClosingElement\n const tagName = ts.isIdentifier(openingEl.tagName) ? openingEl.tagName.text : ''\n const isComponent = tagName.length > 0 && tagName.charAt(0) !== tagName.charAt(0).toLowerCase()\n\n if (isComponent) {\n // Component prop: wrap with _rp() brand so makeReactiveProps recognizes it.\n //\n // EXCEPTION: If the expression is a single JSX element (not a conditional),\n // do NOT wrap the outer expression. The JSX element is created once (stable VNode).\n // Its own inner props will be wrapped individually via recursive walk().\n // This prevents remounting: <Icon name={x()} /> stays one Icon instance,\n // only its name prop updates reactively.\n const isSingleJsx = ts.isJsxElement(expr) || ts.isJsxSelfClosingElement(expr)\n if (isSingleJsx) {\n // Don't wrap — recurse into the JSX element's attributes instead\n ts.forEachChild(expr, walk)\n return\n }\n\n const hoistName = maybeHoist(expr)\n if (hoistName) {\n replacements.push({ start: expr.getStart(sf), end: expr.getEnd(), text: hoistName })\n } else if (shouldWrap(expr)) {\n const start = expr.getStart(sf)\n const end = expr.getEnd()\n replacements.push({ start, end, text: `_rp(() => ${code.slice(start, end)})` })\n needsRpImport = true\n }\n } else {\n // DOM prop: standard () => expr wrapping\n hoistOrWrap(expr)\n }\n }\n\n /** Handle a JSX expression in child position — wrap, hoist, or recurse. */\n function handleJsxExpression(node: ts.JsxExpression): void {\n const expr = node.expression\n if (!expr) return\n const hoistName = maybeHoist(expr)\n if (hoistName) {\n replacements.push({ start: expr.getStart(sf), end: expr.getEnd(), text: hoistName })\n return\n }\n if (shouldWrap(expr)) {\n wrap(expr)\n return\n }\n // Not hoisted, not wrapped (e.g., arrow function in For callback).\n // Recurse into the expression body to find nested JSX elements\n // that should be compiled to _tpl() calls.\n ts.forEachChild(expr, walk)\n }\n\n function walk(node: ts.Node): void {\n if (ts.isJsxElement(node) && tryTemplateEmit(node)) return\n if (ts.isJsxSelfClosingElement(node) || ts.isJsxElement(node)) checkForWarnings(node)\n if (ts.isJsxAttribute(node)) {\n handleJsxAttribute(node)\n return\n }\n if (ts.isJsxExpression(node)) {\n handleJsxExpression(node)\n return\n }\n ts.forEachChild(node, walk)\n }\n\n walk(sf)\n\n if (replacements.length === 0 && hoists.length === 0) return { code, warnings }\n\n // Apply replacements left-to-right via string builder — O(n) single join\n replacements.sort((a, b) => a.start - b.start)\n\n const parts: string[] = []\n let lastPos = 0\n for (const r of replacements) {\n parts.push(code.slice(lastPos, r.start))\n parts.push(r.text)\n lastPos = r.end\n }\n parts.push(code.slice(lastPos))\n let result = parts.join('')\n\n // Prepend module-scope hoisted static VNode declarations\n if (hoists.length > 0) {\n const preamble = hoists.map((h) => `const ${h.name} = /*@__PURE__*/ ${h.text}\\n`).join('')\n result = preamble + result\n }\n\n // Prepend template imports if _tpl() was emitted\n if (needsTplImport) {\n const runtimeDomImports = ['_tpl']\n if (needsBindDirectImportGlobal) runtimeDomImports.push('_bindDirect')\n if (needsBindTextImportGlobal) runtimeDomImports.push('_bindText')\n const reactivityImports = needsBindImportGlobal\n ? `\\nimport { _bind } from \"@pyreon/reactivity\";`\n : ''\n result =\n `import { ${runtimeDomImports.join(', ')} } from \"@pyreon/runtime-dom\";${reactivityImports}\\n` +\n result\n }\n\n // Prepend _rp import if reactive component props were emitted\n if (needsRpImport) {\n result = `import { _rp } from \"@pyreon/core\";\\n` + result\n }\n\n return { code: result, usesTemplates: needsTplImport, warnings }\n\n // ── Template emission helpers (closures over sf, code) ──────────────────────\n\n /** Check if a single attribute would prevent template emission. */\n function hasBailAttr(node: ts.JsxElement | ts.JsxSelfClosingElement): boolean {\n for (const attr of jsxAttrs(node)) {\n if (ts.isJsxSpreadAttribute(attr)) return true\n if (ts.isJsxAttribute(attr) && ts.isIdentifier(attr.name) && attr.name.text === 'key')\n return true\n }\n return false\n }\n\n /**\n * Count template-eligible elements for a single JSX child.\n * Returns 0 for skippable children, -1 for bail, positive for element count.\n */\n function countChildForTemplate(child: ts.JsxChild): number {\n if (ts.isJsxText(child)) return 0\n if (ts.isJsxElement(child) || ts.isJsxSelfClosingElement(child))\n return templateElementCount(child)\n if (ts.isJsxExpression(child)) {\n if (!child.expression) return 0\n return containsJSXInExpr(child.expression) ? -1 : 0\n }\n if (ts.isJsxFragment(child)) return templateFragmentCount(child)\n return -1\n }\n\n /**\n * Count DOM elements in a JSX subtree. Returns -1 if the tree is not\n * eligible for template emission.\n */\n function templateElementCount(node: ts.JsxElement | ts.JsxSelfClosingElement): number {\n const tag = jsxTagName(node)\n if (!tag || !isLowerCase(tag)) return -1\n if (hasBailAttr(node)) return -1\n if (!ts.isJsxElement(node)) return 1\n\n let count = 1\n for (const child of node.children) {\n const c = countChildForTemplate(child)\n if (c === -1) return -1\n count += c\n }\n return count\n }\n\n /** Count template-eligible elements inside a fragment. */\n function templateFragmentCount(frag: ts.JsxFragment): number {\n let count = 0\n for (const child of frag.children) {\n const c = countChildForTemplate(child)\n if (c === -1) return -1\n count += c\n }\n return count\n }\n\n /**\n * Build the complete `_tpl(\"html\", (__root) => { ... })` call string\n * for a template-eligible JSX element tree. Returns null if codegen fails.\n */\n function buildTemplateCall(node: ts.JsxElement | ts.JsxSelfClosingElement): string | null {\n const bindLines: string[] = []\n const disposerNames: string[] = []\n let varIdx = 0\n let dispIdx = 0\n // Reactive expressions that will be combined into a single _bind call\n const reactiveBindExprs: string[] = []\n let needsBindTextImport = false\n let needsBindDirectImport = false\n\n function nextVar(): string {\n return `__e${varIdx++}`\n }\n function nextDisp(): string {\n const name = `__d${dispIdx++}`\n disposerNames.push(name)\n return name\n }\n function nextTextVar(): string {\n return `__t${varIdx++}`\n }\n\n /** Resolve the variable name for an element given its accessor path. */\n function resolveElementVar(accessor: string, hasDynamic: boolean): string {\n if (accessor === '__root') return '__root'\n if (hasDynamic) {\n const v = nextVar()\n bindLines.push(`const ${v} = ${accessor}`)\n return v\n }\n return accessor\n }\n\n /** Emit bind line for a ref attribute. */\n function emitRef(attr: ts.JsxAttribute, varName: string): void {\n if (!attr.initializer || !ts.isJsxExpression(attr.initializer)) return\n if (!attr.initializer.expression) return\n bindLines.push(`${sliceExpr(attr.initializer.expression)}.current = ${varName}`)\n }\n\n /** Emit event handler bind line — delegated (expando) or addEventListener. */\n function emitEventListener(attr: ts.JsxAttribute, attrName: string, varName: string): void {\n const eventName = (attrName[2] ?? '').toLowerCase() + attrName.slice(3)\n if (!attr.initializer || !ts.isJsxExpression(attr.initializer)) return\n if (!attr.initializer.expression) return\n const handler = sliceExpr(attr.initializer.expression)\n if (DELEGATED_EVENTS.has(eventName)) {\n // Delegated: store handler as expando property — container listener picks it up\n bindLines.push(`${varName}.__ev_${eventName} = ${handler}`)\n } else {\n bindLines.push(`${varName}.addEventListener(\"${eventName}\", ${handler})`)\n }\n }\n\n /** Return HTML string for a static attribute expression, or null if not static. */\n function staticAttrToHtml(exprNode: ts.Expression, htmlAttrName: string): string | null {\n if (!isStatic(exprNode)) return null\n if (ts.isStringLiteral(exprNode)) return ` ${htmlAttrName}=\"${escapeHtmlAttr(exprNode.text)}\"`\n if (ts.isNumericLiteral(exprNode)) return ` ${htmlAttrName}=\"${exprNode.text}\"`\n if (exprNode.kind === ts.SyntaxKind.TrueKeyword) return ` ${htmlAttrName}`\n return '' // false/null/undefined → omit\n }\n\n /**\n * Try to extract a direct signal reference from an expression.\n * Returns the callee text (e.g. \"count\" or \"row.label\") if the expression\n * is a single call with no arguments, otherwise null.\n */\n function tryDirectSignalRef(exprNode: ts.Expression): string | null {\n let inner = exprNode\n // Unwrap concise arrow: () => expr\n if (ts.isArrowFunction(inner) && !ts.isBlock(inner.body)) {\n inner = inner.body as ts.Expression\n }\n if (!ts.isCallExpression(inner)) return null\n if (inner.arguments.length > 0) return null\n const callee = inner.expression\n // Only match simple identifiers: count() → _bindText(count, node)\n // Property access like obj.method() is NOT safe — detaching the method\n // loses `this` context (e.g. value.toLocaleString becomes unbound).\n if (ts.isIdentifier(callee)) {\n return sliceExpr(callee)\n }\n return null\n }\n\n /** Unwrap a reactive accessor expression for use inside _bind(). */\n function unwrapAccessor(exprNode: ts.Expression): { expr: string; isReactive: boolean } {\n // Concise arrow: () => value() → unwrap to \"value()\"\n if (ts.isArrowFunction(exprNode) && !ts.isBlock(exprNode.body)) {\n return { expr: sliceExpr(exprNode.body as ts.Expression), isReactive: true }\n }\n // Block-body arrow/function: invoke it\n if (ts.isArrowFunction(exprNode) || ts.isFunctionExpression(exprNode)) {\n return { expr: `(${sliceExpr(exprNode)})()`, isReactive: true }\n }\n return { expr: sliceExpr(exprNode), isReactive: containsCall(exprNode) }\n }\n\n /** Build a setter expression for an attribute. */\n function attrSetter(htmlAttrName: string, varName: string, expr: string): string {\n if (htmlAttrName === 'class') return `${varName}.className = ${expr}`\n if (htmlAttrName === 'style') return `${varName}.style.cssText = ${expr}`\n return `${varName}.setAttribute(\"${htmlAttrName}\", ${expr})`\n }\n\n /** Emit bind line for a dynamic (non-static) attribute. */\n function emitDynamicAttr(\n _expr: string,\n exprNode: ts.Expression,\n htmlAttrName: string,\n varName: string,\n ): void {\n const { expr, isReactive } = unwrapAccessor(exprNode)\n\n if (!isReactive) {\n bindLines.push(attrSetter(htmlAttrName, varName, expr))\n return\n }\n\n // Direct signal binding for bare signal calls (e.g. class={() => active()})\n const directRef = tryDirectSignalRef(exprNode)\n if (directRef) {\n needsBindDirectImport = true\n const d = nextDisp()\n const updater =\n htmlAttrName === 'class'\n ? `(v) => { ${varName}.className = v == null ? \"\" : String(v) }`\n : htmlAttrName === 'style'\n ? `(v) => { if (typeof v === \"string\") ${varName}.style.cssText = v; else if (v) Object.assign(${varName}.style, v) }`\n : `(v) => { ${varName}.setAttribute(\"${htmlAttrName}\", v == null ? \"\" : String(v)) }`\n bindLines.push(`const ${d} = _bindDirect(${directRef}, ${updater})`)\n return\n }\n\n reactiveBindExprs.push(attrSetter(htmlAttrName, varName, expr))\n }\n\n /** Emit bind line or HTML for an expression attribute value. */\n function emitAttrExpression(\n exprNode: ts.Expression,\n htmlAttrName: string,\n varName: string,\n ): string {\n const staticHtml = staticAttrToHtml(exprNode, htmlAttrName)\n if (staticHtml !== null) return staticHtml\n\n // style={{...}} → Object.assign(el.style, {...}) for object expressions\n if (htmlAttrName === 'style' && ts.isObjectLiteralExpression(exprNode)) {\n bindLines.push(`Object.assign(${varName}.style, ${sliceExpr(exprNode)})`)\n return ''\n }\n\n emitDynamicAttr(sliceExpr(exprNode), exprNode, htmlAttrName, varName)\n return ''\n }\n\n /** Emit side-effects for special attrs (ref, event). Returns true if handled. */\n function tryEmitSpecialAttr(attr: ts.JsxAttribute, attrName: string, varName: string): boolean {\n if (attrName === 'ref') {\n emitRef(attr, varName)\n return true\n }\n if (EVENT_RE.test(attrName)) {\n emitEventListener(attr, attrName, varName)\n return true\n }\n return false\n }\n\n /** Convert an attribute initializer to HTML. Returns empty string for side-effect-only attrs. */\n function attrInitializerToHtml(\n attr: ts.JsxAttribute,\n htmlAttrName: string,\n varName: string,\n ): string {\n if (!attr.initializer) return ` ${htmlAttrName}`\n if (ts.isStringLiteral(attr.initializer))\n return ` ${htmlAttrName}=\"${escapeHtmlAttr(attr.initializer.text)}\"`\n if (ts.isJsxExpression(attr.initializer) && attr.initializer.expression)\n return emitAttrExpression(attr.initializer.expression, htmlAttrName, varName)\n return ''\n }\n\n /** Process a single attribute, returning HTML to append. */\n function processOneAttr(attr: ts.JsxAttributeLike, varName: string): string {\n if (!ts.isJsxAttribute(attr)) return ''\n const attrName = ts.isIdentifier(attr.name) ? attr.name.text : ''\n if (attrName === 'key') return ''\n if (tryEmitSpecialAttr(attr, attrName, varName)) return ''\n return attrInitializerToHtml(attr, JSX_TO_HTML_ATTR[attrName] ?? attrName, varName)\n }\n\n /** Process all attributes on an element, returning the HTML attribute string. */\n function processAttrs(el: ts.JsxElement | ts.JsxSelfClosingElement, varName: string): string {\n let htmlAttrs = ''\n for (const attr of jsxAttrs(el)) htmlAttrs += processOneAttr(attr, varName)\n return htmlAttrs\n }\n\n /** Emit bind lines for a reactive text expression child. */\n function emitReactiveTextChild(\n expr: string,\n exprNode: ts.Expression,\n varName: string,\n parentRef: string,\n childNodeIdx: number,\n needsPlaceholder: boolean,\n ): string {\n const tVar = nextTextVar()\n bindLines.push(`const ${tVar} = document.createTextNode(\"\")`)\n if (needsPlaceholder) {\n bindLines.push(\n `${parentRef}.replaceChild(${tVar}, ${parentRef}.childNodes[${childNodeIdx}])`,\n )\n } else {\n bindLines.push(`${varName}.appendChild(${tVar})`)\n }\n // Direct signal binding: bypass effect system entirely\n const directRef = tryDirectSignalRef(exprNode)\n if (directRef) {\n needsBindTextImport = true\n const d = nextDisp()\n bindLines.push(`const ${d} = _bindText(${directRef}, ${tVar})`)\n } else {\n // Collected into the combined _bind at the end\n reactiveBindExprs.push(`${tVar}.data = ${expr}`)\n }\n return needsPlaceholder ? '<!>' : ''\n }\n\n /** Emit bind lines for a static text expression child. */\n function emitStaticTextChild(\n expr: string,\n varName: string,\n parentRef: string,\n childNodeIdx: number,\n needsPlaceholder: boolean,\n ): string {\n if (needsPlaceholder) {\n const tVar = nextTextVar()\n bindLines.push(`const ${tVar} = document.createTextNode(${expr})`)\n bindLines.push(\n `${parentRef}.replaceChild(${tVar}, ${parentRef}.childNodes[${childNodeIdx}])`,\n )\n return '<!>'\n }\n bindLines.push(`${varName}.textContent = ${expr}`)\n return ''\n }\n\n /** Process a single flat child, returning the HTML contribution or null on failure. */\n function processOneChild(\n child: FlatChild,\n varName: string,\n parentRef: string,\n useMixed: boolean,\n useMultiExpr: boolean,\n childNodeIdx: number,\n ): string | null {\n if (child.kind === 'text') return escapeHtmlText(child.text)\n if (child.kind === 'element') {\n const childAccessor = useMixed\n ? `${parentRef}.childNodes[${childNodeIdx}]`\n : `${parentRef}.children[${child.elemIdx}]`\n return processElement(child.node, childAccessor)\n }\n // expression\n const needsPlaceholder = useMixed || useMultiExpr\n const { expr, isReactive } = unwrapAccessor(child.expression)\n if (isReactive) {\n return emitReactiveTextChild(\n expr,\n child.expression,\n varName,\n parentRef,\n childNodeIdx,\n needsPlaceholder,\n )\n }\n return emitStaticTextChild(expr, varName, parentRef, childNodeIdx, needsPlaceholder)\n }\n\n /** Process children of a JsxElement, returning the children HTML. */\n function processChildren(el: ts.JsxElement, varName: string, accessor: string): string | null {\n const flatChildren = flattenChildren(el.children)\n const { useMixed, useMultiExpr } = analyzeChildren(flatChildren)\n const parentRef = accessor === '__root' ? '__root' : varName\n\n let html = ''\n let childNodeIdx = 0\n\n for (const child of flatChildren) {\n const childHtml = processOneChild(\n child,\n varName,\n parentRef,\n useMixed,\n useMultiExpr,\n childNodeIdx,\n )\n if (childHtml === null) return null\n html += childHtml\n childNodeIdx++\n }\n\n return html\n }\n\n /** Process a single DOM element for template emission. Returns the HTML string or null. */\n function processElement(\n el: ts.JsxElement | ts.JsxSelfClosingElement,\n accessor: string,\n ): string | null {\n const tag = jsxTagName(el)\n if (!tag) return null\n\n const varName = resolveElementVar(accessor, elementHasDynamic(el))\n const htmlAttrs = processAttrs(el, varName)\n let html = `<${tag}${htmlAttrs}>`\n\n if (ts.isJsxElement(el)) {\n const childHtml = processChildren(el, varName, accessor)\n if (childHtml === null) return null\n html += childHtml\n }\n\n if (!VOID_ELEMENTS.has(tag)) html += `</${tag}>`\n return html\n }\n\n const html = processElement(node, '__root')\n if (html === null) return null\n\n if (needsBindTextImport) needsBindTextImportGlobal = true\n if (needsBindDirectImport) needsBindDirectImportGlobal = true\n\n // Build bind function body\n const escaped = html.replace(/\\\\/g, '\\\\\\\\').replace(/\"/g, '\\\\\"')\n\n // Emit combined _bind for reactive attribute/text expressions that\n // weren't handled by _bindText. This merges N separate _bind calls into\n // one — saving N-1 closures + deps arrays per template instance.\n // Emit a single combined _bind for all reactive attribute/text expressions\n // that weren't handled by _bindText. Merges N separate _bind calls into one —\n // saving N-1 closures + deps arrays per template instance.\n if (reactiveBindExprs.length > 0) {\n needsBindImportGlobal = true\n const combinedName = nextDisp()\n const combinedBody = reactiveBindExprs.join('; ')\n bindLines.push(`const ${combinedName} = _bind(() => { ${combinedBody} })`)\n }\n\n if (bindLines.length === 0 && disposerNames.length === 0) {\n return `_tpl(\"${escaped}\", () => null)`\n }\n\n let body = bindLines.map((l) => ` ${l}`).join('\\n')\n if (disposerNames.length > 0) {\n body += `\\n return () => { ${disposerNames.map((d) => `${d}()`).join('; ')} }`\n } else {\n body += '\\n return null'\n }\n\n return `_tpl(\"${escaped}\", (__root) => {\\n${body}\\n})`\n }\n\n /** Flat child descriptor for template children processing */\n type FlatChild =\n | { kind: 'text'; text: string }\n | { kind: 'element'; node: ts.JsxElement | ts.JsxSelfClosingElement; elemIdx: number }\n | { kind: 'expression'; expression: ts.Expression }\n\n /** Classify a single JSX child into a FlatChild descriptor. */\n function classifyJsxChild(\n child: ts.JsxChild,\n out: FlatChild[],\n elemIdxRef: { value: number },\n recurse: (kids: ts.NodeArray<ts.JsxChild>) => void,\n ): void {\n if (ts.isJsxText(child)) {\n const trimmed = child.text.replace(/\\n\\s*/g, '').trim()\n if (trimmed) out.push({ kind: 'text', text: trimmed })\n return\n }\n if (ts.isJsxElement(child) || ts.isJsxSelfClosingElement(child)) {\n out.push({ kind: 'element', node: child, elemIdx: elemIdxRef.value++ })\n return\n }\n if (ts.isJsxExpression(child)) {\n if (child.expression) out.push({ kind: 'expression', expression: child.expression })\n return\n }\n if (ts.isJsxFragment(child)) recurse(child.children)\n }\n\n /**\n * Flatten JSX children, inlining fragment children and stripping whitespace-only text.\n * Returns a flat array of child descriptors with element indices pre-computed.\n */\n function flattenChildren(children: ts.NodeArray<ts.JsxChild>): FlatChild[] {\n const flatList: FlatChild[] = []\n const elemIdxRef = { value: 0 }\n\n function addChildren(kids: ts.NodeArray<ts.JsxChild>): void {\n for (const child of kids) classifyJsxChild(child, flatList, elemIdxRef, addChildren)\n }\n\n addChildren(children)\n return flatList\n }\n\n /** Analyze flat children to determine indexing strategy. */\n function analyzeChildren(flatChildren: FlatChild[]): {\n useMixed: boolean\n useMultiExpr: boolean\n } {\n const hasElem = flatChildren.some((c) => c.kind === 'element')\n const hasNonElem = flatChildren.some((c) => c.kind !== 'element')\n const exprCount = flatChildren.filter((c) => c.kind === 'expression').length\n return { useMixed: hasElem && hasNonElem, useMultiExpr: exprCount > 1 }\n }\n\n /** Check if a single attribute is dynamic (has ref, event, or non-static expression). */\n function attrIsDynamic(attr: ts.JsxAttributeLike): boolean {\n if (!ts.isJsxAttribute(attr)) return false\n const name = ts.isIdentifier(attr.name) ? attr.name.text : ''\n if (name === 'ref') return true\n if (EVENT_RE.test(name)) return true\n if (!attr.initializer || !ts.isJsxExpression(attr.initializer)) return false\n const expr = attr.initializer.expression\n return expr ? !isStatic(expr) : false\n }\n\n /** Check if an element has any dynamic attributes, events, ref, or expression children */\n function elementHasDynamic(node: ts.JsxElement | ts.JsxSelfClosingElement): boolean {\n if (jsxAttrs(node).some(attrIsDynamic)) return true\n if (ts.isJsxElement(node)) {\n return node.children.some((c) => ts.isJsxExpression(c) && c.expression !== undefined)\n }\n return false\n }\n\n /** Slice expression source from the original code */\n function sliceExpr(expr: ts.Expression): string {\n return code.slice(expr.getStart(sf), expr.getEnd())\n }\n\n /** Get tag name string */\n function jsxTagName(node: ts.JsxElement | ts.JsxSelfClosingElement): string {\n const tag = ts.isJsxElement(node) ? node.openingElement.tagName : node.tagName\n return ts.isIdentifier(tag) ? tag.text : ''\n }\n\n /** Get attribute list */\n function jsxAttrs(\n node: ts.JsxElement | ts.JsxSelfClosingElement,\n ): ts.NodeArray<ts.JsxAttributeLike> {\n return ts.isJsxElement(node)\n ? node.openingElement.attributes.properties\n : node.attributes.properties\n }\n}\n\n// ─── Template constants ──────────────────────────────────────────────────────\n\nconst VOID_ELEMENTS = new Set([\n 'area',\n 'base',\n 'br',\n 'col',\n 'embed',\n 'hr',\n 'img',\n 'input',\n 'link',\n 'meta',\n 'param',\n 'source',\n 'track',\n 'wbr',\n])\n\nconst JSX_TO_HTML_ATTR: Record<string, string> = {\n className: 'class',\n htmlFor: 'for',\n}\n\nfunction isLowerCase(s: string): boolean {\n return s.length > 0 && s[0] === s[0]?.toLowerCase()\n}\n\n/** Check if an expression subtree contains JSX nodes */\nfunction containsJSXInExpr(node: ts.Node): boolean {\n if (ts.isJsxElement(node) || ts.isJsxSelfClosingElement(node) || ts.isJsxFragment(node))\n return true\n return ts.forEachChild(node, containsJSXInExpr) ?? false\n}\n\nfunction escapeHtmlAttr(s: string): string {\n return s.replace(/&/g, '&').replace(/\"/g, '"')\n}\n\nfunction escapeHtmlText(s: string): string {\n return s.replace(/&/g, '&').replace(/</g, '<')\n}\n\n// ─── Static JSX analysis ──────────────────────────────────────────────────────\n\ntype StaticJSXNode = ts.JsxElement | ts.JsxSelfClosingElement | ts.JsxFragment\n\nfunction isStaticJSXNode(node: StaticJSXNode): boolean {\n if (ts.isJsxSelfClosingElement(node)) {\n return isStaticAttrs(node.attributes)\n }\n if (ts.isJsxFragment(node)) {\n return node.children.every(isStaticChild)\n }\n // JsxElement\n return isStaticAttrs(node.openingElement.attributes) && node.children.every(isStaticChild)\n}\n\nfunction isStaticAttrs(attrs: ts.JsxAttributes): boolean {\n return attrs.properties.every((prop) => {\n // Spread attribute — always dynamic\n if (!ts.isJsxAttribute(prop)) return false\n // Boolean shorthand: <input disabled />\n if (!prop.initializer) return true\n // String literal: class=\"foo\"\n if (ts.isStringLiteral(prop.initializer)) return true\n // Must be JsxExpression — the only remaining JsxAttributeValue type\n const expr = (prop.initializer as ts.JsxExpression).expression\n return expr ? isStatic(expr) : true\n })\n}\n\nfunction isStaticChild(child: ts.JsxChild): boolean {\n // Plain text content\n if (ts.isJsxText(child)) return true\n // Nested JSX elements\n if (ts.isJsxSelfClosingElement(child)) return isStaticJSXNode(child)\n if (ts.isJsxElement(child)) return isStaticJSXNode(child)\n if (ts.isJsxFragment(child)) return isStaticJSXNode(child)\n // Must be JsxExpression — the only remaining JsxChild type\n const expr = (child as ts.JsxExpression).expression\n return expr ? isStatic(expr) : true\n}\n\n// ─── General helpers ──────────────────────────────────────────────────────────\n\nfunction isStatic(node: ts.Expression): boolean {\n return (\n ts.isStringLiteral(node) ||\n ts.isNumericLiteral(node) ||\n ts.isNoSubstitutionTemplateLiteral(node) ||\n node.kind === ts.SyntaxKind.TrueKeyword ||\n node.kind === ts.SyntaxKind.FalseKeyword ||\n node.kind === ts.SyntaxKind.NullKeyword ||\n node.kind === ts.SyntaxKind.UndefinedKeyword\n )\n}\n\nfunction shouldWrap(node: ts.Expression): boolean {\n // Already a function — user explicitly wrapped or it's a callback\n if (ts.isArrowFunction(node) || ts.isFunctionExpression(node)) return false\n // Static literal — no signals involved\n if (isStatic(node)) return false\n // Only wrap if the expression tree contains a call — signal reads are always\n // function calls (e.g. `count()`, `name()`). Plain identifiers, object literals\n // like `style={{ color: \"red\" }}`, array literals, and member accesses are\n // left as-is to avoid unnecessary reactive wrappers.\n return containsCall(node)\n}\n\nfunction containsCall(node: ts.Node): boolean {\n if (ts.isCallExpression(node)) return true\n if (ts.isTaggedTemplateExpression(node)) return true\n // Don't recurse into nested functions — they're self-contained\n if (ts.isArrowFunction(node) || ts.isFunctionExpression(node)) return false\n return ts.forEachChild(node, containsCall) ?? false\n}\n","/**\n * Project scanner — extracts route, component, and island information from source files.\n */\n\nimport * as fs from 'node:fs'\nimport * as path from 'node:path'\n\nexport interface RouteInfo {\n path: string\n name?: string | undefined\n component?: string | undefined\n hasLoader: boolean\n hasGuard: boolean\n params: string[]\n}\n\nexport interface ComponentInfo {\n name: string\n file: string\n hasSignals: boolean\n signalNames: string[]\n props: string[]\n}\n\nexport interface IslandInfo {\n name: string\n file: string\n hydrate: string\n}\n\nexport interface ProjectContext {\n framework: 'pyreon'\n version: string\n generatedAt: string\n routes: RouteInfo[]\n components: ComponentInfo[]\n islands: IslandInfo[]\n}\n\nexport function generateContext(cwd: string): ProjectContext {\n const files = collectSourceFiles(cwd)\n const version = readVersion(cwd)\n\n return {\n framework: 'pyreon',\n version,\n generatedAt: new Date().toISOString(),\n routes: extractRoutes(files, cwd),\n components: extractComponents(files, cwd),\n islands: extractIslands(files, cwd),\n }\n}\n\nfunction collectSourceFiles(cwd: string): string[] {\n const results: string[] = []\n const extensions = new Set(['.tsx', '.jsx', '.ts', '.js'])\n const ignoreDirs = new Set(['node_modules', 'dist', 'lib', '.pyreon', '.git', 'build'])\n\n function walk(dir: string): void {\n let entries: fs.Dirent[]\n try {\n entries = fs.readdirSync(dir, { withFileTypes: true })\n } catch {\n return\n }\n for (const entry of entries) {\n if (entry.name.startsWith('.') && entry.isDirectory()) continue\n if (ignoreDirs.has(entry.name) && entry.isDirectory()) continue\n const fullPath = path.join(dir, entry.name)\n if (entry.isDirectory()) {\n walk(fullPath)\n } else if (entry.isFile() && extensions.has(path.extname(entry.name))) {\n results.push(fullPath)\n }\n }\n }\n\n walk(cwd)\n return results\n}\n\nfunction extractRoutes(files: string[], _cwd: string): RouteInfo[] {\n const routes: RouteInfo[] = []\n\n for (const file of files) {\n let code: string\n try {\n code = fs.readFileSync(file, 'utf-8')\n } catch {\n continue\n }\n\n const routeArrayRe =\n /(?:createRouter\\s*\\(\\s*\\[|(?:const|let)\\s+routes\\s*(?::\\s*RouteRecord\\[\\])?\\s*=\\s*\\[)([\\s\\S]*?)\\]/g\n let match: RegExpExecArray | null\n for (match = routeArrayRe.exec(code); match; match = routeArrayRe.exec(code)) {\n const block = match[1] ?? ''\n const routeObjRe = /path\\s*:\\s*[\"']([^\"']+)[\"']/g\n let routeMatch: RegExpExecArray | null\n for (routeMatch = routeObjRe.exec(block); routeMatch; routeMatch = routeObjRe.exec(block)) {\n const routePath = routeMatch[1] ?? ''\n const surroundingStart = Math.max(0, routeMatch.index - 50)\n const surroundingEnd = Math.min(block.length, routeMatch.index + 200)\n const surrounding = block.slice(surroundingStart, surroundingEnd)\n\n routes.push({\n path: routePath,\n name: surrounding.match(/name\\s*:\\s*[\"']([^\"']+)[\"']/)?.[1],\n hasLoader: /loader\\s*:/.test(surrounding),\n hasGuard: /beforeEnter\\s*:|beforeLeave\\s*:/.test(surrounding),\n params: extractParams(routePath),\n })\n }\n }\n }\n\n return routes\n}\n\nfunction extractComponents(files: string[], cwd: string): ComponentInfo[] {\n const components: ComponentInfo[] = []\n\n for (const file of files) {\n let code: string\n try {\n code = fs.readFileSync(file, 'utf-8')\n } catch {\n continue\n }\n\n const componentRe =\n /(?:export\\s+)?(?:const|function)\\s+([A-Z]\\w*)\\s*(?::\\s*ComponentFn<[^>]+>\\s*)?=?\\s*\\(?(?:\\s*\\{?\\s*([^)]*?)\\s*\\}?\\s*)?\\)?\\s*(?:=>|{)/g\n let match: RegExpExecArray | null\n\n for (match = componentRe.exec(code); match; match = componentRe.exec(code)) {\n const name = match[1] ?? 'Unknown'\n const propsStr = match[2] ?? ''\n const props = propsStr\n .split(/[,;]/)\n .map((p) => p.trim().replace(/[{}]/g, '').trim().split(':')[0]?.split('=')[0]?.trim() ?? '')\n .filter((p) => p && p !== 'props')\n\n const bodyStart = match.index + match[0].length\n const body = code.slice(bodyStart, Math.min(code.length, bodyStart + 2000))\n const signalNames: string[] = []\n const signalRe = /(?:const|let)\\s+(\\w+)\\s*=\\s*signal\\s*[<(]/g\n let sigMatch: RegExpExecArray | null\n for (sigMatch = signalRe.exec(body); sigMatch; sigMatch = signalRe.exec(body)) {\n if (sigMatch[1]) signalNames.push(sigMatch[1])\n }\n\n components.push({\n name,\n file: path.relative(cwd, file),\n hasSignals: signalNames.length > 0,\n signalNames,\n props,\n })\n }\n }\n\n return components\n}\n\nfunction extractIslands(files: string[], cwd: string): IslandInfo[] {\n const islands: IslandInfo[] = []\n\n for (const file of files) {\n let code: string\n try {\n code = fs.readFileSync(file, 'utf-8')\n } catch {\n continue\n }\n\n const islandRe =\n /island\\s*\\(\\s*\\(\\)\\s*=>\\s*import\\(.+?\\)\\s*,\\s*\\{[^}]*name\\s*:\\s*[\"']([^\"']+)[\"'][^}]*?(?:hydrate\\s*:\\s*[\"']([^\"']+)[\"'])?[^}]*\\}/g\n let match: RegExpExecArray | null\n for (match = islandRe.exec(code); match; match = islandRe.exec(code)) {\n if (match[1]) {\n islands.push({\n name: match[1],\n file: path.relative(cwd, file),\n hydrate: match[2] ?? 'load',\n })\n }\n }\n }\n\n return islands\n}\n\nfunction extractParams(routePath: string): string[] {\n const params: string[] = []\n const paramRe = /:(\\w+)\\??/g\n let match: RegExpExecArray | null\n for (match = paramRe.exec(routePath); match; match = paramRe.exec(routePath)) {\n if (match[1]) params.push(match[1])\n }\n return params\n}\n\nfunction readVersion(cwd: string): string {\n try {\n const pkg = JSON.parse(fs.readFileSync(path.join(cwd, 'package.json'), 'utf-8'))\n const deps: Record<string, unknown> = { ...pkg.dependencies, ...pkg.devDependencies }\n for (const [name, ver] of Object.entries(deps)) {\n if (name.startsWith('@pyreon/') && typeof ver === 'string') return ver.replace(/^[\\^~]/, '')\n }\n return (pkg.version as string) || 'unknown'\n } catch {\n return 'unknown'\n }\n}\n","/**\n * React Pattern Interceptor — detects React/Vue patterns in code and provides\n * structured diagnostics with exact fix suggestions for AI-assisted migration.\n *\n * Two modes:\n * - `detectReactPatterns(code)` — returns diagnostics only (non-destructive)\n * - `migrateReactCode(code)` — applies auto-fixes and returns transformed code\n *\n * Designed for three consumers:\n * 1. Compiler pre-pass (warnings during build)\n * 2. CLI `pyreon doctor` (project-wide scanning)\n * 3. MCP server `migrate_react` / `validate` tools (AI agent integration)\n */\n\nimport ts from 'typescript'\n\n// ═══════════════════════════════════════════════════════════════════════════════\n// Types\n// ═══════════════════════════════════════════════════════════════════════════════\n\nexport type ReactDiagnosticCode =\n | 'react-import'\n | 'react-dom-import'\n | 'react-router-import'\n | 'use-state'\n | 'use-effect-mount'\n | 'use-effect-deps'\n | 'use-effect-no-deps'\n | 'use-memo'\n | 'use-callback'\n | 'use-ref-dom'\n | 'use-ref-box'\n | 'use-reducer'\n | 'use-layout-effect'\n | 'memo-wrapper'\n | 'forward-ref'\n | 'class-name-prop'\n | 'html-for-prop'\n | 'on-change-input'\n | 'dangerously-set-inner-html'\n | 'dot-value-signal'\n | 'array-map-jsx'\n | 'key-on-for-child'\n | 'create-context-import'\n | 'use-context-import'\n\nexport interface ReactDiagnostic {\n /** Machine-readable code for filtering and programmatic handling */\n code: ReactDiagnosticCode\n /** Human-readable message explaining the issue */\n message: string\n /** 1-based line number */\n line: number\n /** 0-based column */\n column: number\n /** The code as written */\n current: string\n /** The suggested Pyreon equivalent */\n suggested: string\n /** Whether migrateReactCode can auto-fix this */\n fixable: boolean\n}\n\nexport interface MigrationChange {\n type: 'replace' | 'remove' | 'add'\n line: number\n description: string\n}\n\nexport interface MigrationResult {\n /** Transformed source code */\n code: string\n /** All detected patterns (including unfixable ones) */\n diagnostics: ReactDiagnostic[]\n /** Description of changes applied */\n changes: MigrationChange[]\n}\n\n// ═══════════════════════════════════════════════════════════════════════════════\n// React Hook → Pyreon mapping\n// ═══════════════════════════════════════════════════════════════════════════════\n\ninterface HookMapping {\n pyreonFn: string\n pyreonImport: string\n description: string\n example: string\n}\n\nconst _REACT_HOOK_MAP: Record<string, HookMapping> = {\n useState: {\n pyreonFn: 'signal',\n pyreonImport: '@pyreon/reactivity',\n description: 'Signals are callable functions — read: count(), write: count.set(5)',\n example:\n 'const count = signal(0)\\n// Read: count() Write: count.set(5) Update: count.update(n => n + 1)',\n },\n useEffect: {\n pyreonFn: 'effect',\n pyreonImport: '@pyreon/reactivity',\n description: 'Effects auto-track signal dependencies — no dependency array needed',\n example: 'effect(() => {\\n console.log(count()) // auto-subscribes to count\\n})',\n },\n useLayoutEffect: {\n pyreonFn: 'effect',\n pyreonImport: '@pyreon/reactivity',\n description: 'Pyreon effects run synchronously after signal updates',\n example: 'effect(() => {\\n // runs sync after signal changes\\n})',\n },\n useMemo: {\n pyreonFn: 'computed',\n pyreonImport: '@pyreon/reactivity',\n description: 'Computed values auto-track dependencies and memoize',\n example: 'const doubled = computed(() => count() * 2)',\n },\n useCallback: {\n pyreonFn: '(plain function)',\n pyreonImport: '',\n description:\n 'Not needed — Pyreon components run once, so closures never go stale. Use a plain function',\n example: 'const handleClick = () => doSomething(count())',\n },\n useReducer: {\n pyreonFn: 'signal',\n pyreonImport: '@pyreon/reactivity',\n description: 'Use signal with update() for reducer-like patterns',\n example:\n 'const state = signal(initialState)\\nconst dispatch = (action) => state.update(s => reducer(s, action))',\n },\n}\n\n/** React import sources → Pyreon equivalents */\nconst IMPORT_REWRITES: Record<string, string | null> = {\n react: '@pyreon/core',\n 'react-dom': '@pyreon/runtime-dom',\n 'react-dom/client': '@pyreon/runtime-dom',\n 'react-dom/server': '@pyreon/runtime-server',\n 'react-router': '@pyreon/router',\n 'react-router-dom': '@pyreon/router',\n}\n\n/** React specifiers that map to specific Pyreon imports */\nconst SPECIFIER_REWRITES: Record<string, { name: string; from: string }> = {\n useState: { name: 'signal', from: '@pyreon/reactivity' },\n useEffect: { name: 'effect', from: '@pyreon/reactivity' },\n useLayoutEffect: { name: 'effect', from: '@pyreon/reactivity' },\n useMemo: { name: 'computed', from: '@pyreon/reactivity' },\n useReducer: { name: 'signal', from: '@pyreon/reactivity' },\n useRef: { name: 'signal', from: '@pyreon/reactivity' },\n createContext: { name: 'createContext', from: '@pyreon/core' },\n useContext: { name: 'useContext', from: '@pyreon/core' },\n Fragment: { name: 'Fragment', from: '@pyreon/core' },\n Suspense: { name: 'Suspense', from: '@pyreon/core' },\n lazy: { name: 'lazy', from: '@pyreon/core' },\n memo: { name: '', from: '' }, // removed, not needed\n forwardRef: { name: '', from: '' }, // removed, not needed\n createRoot: { name: 'mount', from: '@pyreon/runtime-dom' },\n hydrateRoot: { name: 'hydrateRoot', from: '@pyreon/runtime-dom' },\n // React Router\n useNavigate: { name: 'useRouter', from: '@pyreon/router' },\n useParams: { name: 'useRoute', from: '@pyreon/router' },\n useLocation: { name: 'useRoute', from: '@pyreon/router' },\n Link: { name: 'RouterLink', from: '@pyreon/router' },\n NavLink: { name: 'RouterLink', from: '@pyreon/router' },\n Outlet: { name: 'RouterView', from: '@pyreon/router' },\n useSearchParams: { name: 'useSearchParams', from: '@pyreon/router' },\n}\n\n/** JSX attribute rewrites (React → standard HTML) */\nconst JSX_ATTR_REWRITES: Record<string, string> = {\n className: 'class',\n htmlFor: 'for',\n}\n\n// ═══════════════════════════════════════════════════════════════════════════════\n// Detection (diagnostic-only, no modifications)\n// ═══════════════════════════════════════════════════════════════════════════════\n\ninterface DetectContext {\n sf: ts.SourceFile\n code: string\n diagnostics: ReactDiagnostic[]\n reactImportedHooks: Set<string>\n}\n\nfunction detectGetNodeText(ctx: DetectContext, node: ts.Node): string {\n return ctx.code.slice(node.getStart(ctx.sf), node.getEnd())\n}\n\nfunction detectDiag(\n ctx: DetectContext,\n node: ts.Node,\n diagCode: ReactDiagnosticCode,\n message: string,\n current: string,\n suggested: string,\n fixable: boolean,\n): void {\n const { line, character } = ctx.sf.getLineAndCharacterOfPosition(node.getStart(ctx.sf))\n ctx.diagnostics.push({\n code: diagCode,\n message,\n line: line + 1,\n column: character,\n current: current.trim(),\n suggested: suggested.trim(),\n fixable,\n })\n}\n\nfunction detectImportDeclaration(ctx: DetectContext, node: ts.ImportDeclaration): void {\n if (!node.moduleSpecifier) return\n const source = (node.moduleSpecifier as ts.StringLiteral).text\n const pyreonSource = IMPORT_REWRITES[source]\n\n if (pyreonSource !== undefined) {\n if (node.importClause?.namedBindings && ts.isNamedImports(node.importClause.namedBindings)) {\n for (const spec of node.importClause.namedBindings.elements) {\n ctx.reactImportedHooks.add(spec.name.text)\n }\n }\n\n const diagCode = source.startsWith('react-router')\n ? 'react-router-import'\n : source.startsWith('react-dom')\n ? 'react-dom-import'\n : 'react-import'\n\n detectDiag(\n ctx,\n node,\n diagCode,\n `Import from '${source}' is a React package. Use Pyreon equivalent.`,\n detectGetNodeText(ctx, node),\n pyreonSource\n ? `import { ... } from \"${pyreonSource}\"`\n : 'Remove this import — not needed in Pyreon',\n true,\n )\n }\n}\n\nfunction detectUseState(ctx: DetectContext, node: ts.CallExpression): void {\n const parent = node.parent\n if (\n ts.isVariableDeclaration(parent) &&\n parent.name &&\n ts.isArrayBindingPattern(parent.name) &&\n parent.name.elements.length >= 1\n ) {\n const firstEl = parent.name.elements[0]\n const valueName =\n firstEl && ts.isBindingElement(firstEl) ? (firstEl.name as ts.Identifier).text : 'value'\n const initArg = node.arguments[0] ? detectGetNodeText(ctx, node.arguments[0]) : 'undefined'\n\n detectDiag(\n ctx,\n node,\n 'use-state',\n `useState is a React API. In Pyreon, use signal(). Read: ${valueName}(), Write: ${valueName}.set(x)`,\n detectGetNodeText(ctx, parent),\n `${valueName} = signal(${initArg})`,\n true,\n )\n } else {\n detectDiag(\n ctx,\n node,\n 'use-state',\n 'useState is a React API. In Pyreon, use signal().',\n detectGetNodeText(ctx, node),\n 'signal(initialValue)',\n true,\n )\n }\n}\n\nfunction callbackHasCleanup(callbackArg: ts.Expression): boolean {\n if (!ts.isArrowFunction(callbackArg) && !ts.isFunctionExpression(callbackArg)) return false\n const body = callbackArg.body\n if (!ts.isBlock(body)) return false\n for (const stmt of body.statements) {\n if (ts.isReturnStatement(stmt) && stmt.expression) return true\n }\n return false\n}\n\nfunction detectUseEffect(ctx: DetectContext, node: ts.CallExpression): void {\n const hookName = (node.expression as ts.Identifier).text\n const depsArg = node.arguments[1]\n const callbackArg = node.arguments[0]\n\n if (depsArg && ts.isArrayLiteralExpression(depsArg) && depsArg.elements.length === 0) {\n const hasCleanup = callbackArg ? callbackHasCleanup(callbackArg) : false\n\n detectDiag(\n ctx,\n node,\n 'use-effect-mount',\n `${hookName} with empty deps [] means \"run once on mount\". Use onMount() in Pyreon.`,\n detectGetNodeText(ctx, node),\n hasCleanup\n ? 'onMount(() => {\\n // setup...\\n return () => { /* cleanup */ }\\n})'\n : 'onMount(() => {\\n // setup...\\n})',\n true,\n )\n } else if (depsArg && ts.isArrayLiteralExpression(depsArg)) {\n detectDiag(\n ctx,\n node,\n 'use-effect-deps',\n `${hookName} with dependency array. In Pyreon, effect() auto-tracks dependencies — no array needed.`,\n detectGetNodeText(ctx, node),\n 'effect(() => {\\n // reads are auto-tracked\\n})',\n true,\n )\n } else if (!depsArg) {\n detectDiag(\n ctx,\n node,\n 'use-effect-no-deps',\n `${hookName} with no dependency array. In Pyreon, use effect() — it auto-tracks signal reads.`,\n detectGetNodeText(ctx, node),\n 'effect(() => {\\n // runs when accessed signals change\\n})',\n true,\n )\n }\n}\n\nfunction detectUseMemo(ctx: DetectContext, node: ts.CallExpression): void {\n const computeFn = node.arguments[0]\n const computeText = computeFn ? detectGetNodeText(ctx, computeFn) : '() => value'\n\n detectDiag(\n ctx,\n node,\n 'use-memo',\n 'useMemo is a React API. In Pyreon, use computed() — dependencies auto-tracked.',\n detectGetNodeText(ctx, node),\n `computed(${computeText})`,\n true,\n )\n}\n\nfunction detectUseCallback(ctx: DetectContext, node: ts.CallExpression): void {\n const callbackFn = node.arguments[0]\n const callbackText = callbackFn ? detectGetNodeText(ctx, callbackFn) : '() => {}'\n\n detectDiag(\n ctx,\n node,\n 'use-callback',\n 'useCallback is not needed in Pyreon. Components run once, so closures never go stale. Use a plain function.',\n detectGetNodeText(ctx, node),\n callbackText,\n true,\n )\n}\n\nfunction detectUseRef(ctx: DetectContext, node: ts.CallExpression): void {\n const arg = node.arguments[0]\n const isNullInit =\n arg &&\n (arg.kind === ts.SyntaxKind.NullKeyword || (ts.isIdentifier(arg) && arg.text === 'undefined'))\n\n if (isNullInit) {\n detectDiag(\n ctx,\n node,\n 'use-ref-dom',\n 'useRef(null) for DOM refs. In Pyreon, use createRef() from @pyreon/core.',\n detectGetNodeText(ctx, node),\n 'createRef()',\n true,\n )\n } else {\n const initText = arg ? detectGetNodeText(ctx, arg) : 'undefined'\n detectDiag(\n ctx,\n node,\n 'use-ref-box',\n 'useRef for mutable values. In Pyreon, use signal() — it works the same way but is reactive.',\n detectGetNodeText(ctx, node),\n `signal(${initText})`,\n true,\n )\n }\n}\n\nfunction detectUseReducer(ctx: DetectContext, node: ts.CallExpression): void {\n detectDiag(\n ctx,\n node,\n 'use-reducer',\n 'useReducer is a React API. In Pyreon, use signal() with update() for reducer patterns.',\n detectGetNodeText(ctx, node),\n 'const state = signal(initialState)\\nconst dispatch = (action) => state.update(s => reducer(s, action))',\n false,\n )\n}\n\nfunction isCallToReactDot(callee: ts.Expression, methodName: string): boolean {\n return (\n ts.isPropertyAccessExpression(callee) &&\n ts.isIdentifier(callee.expression) &&\n callee.expression.text === 'React' &&\n callee.name.text === methodName\n )\n}\n\nfunction detectMemoWrapper(ctx: DetectContext, node: ts.CallExpression): void {\n const callee = node.expression\n const isMemo =\n (ts.isIdentifier(callee) && callee.text === 'memo') || isCallToReactDot(callee, 'memo')\n\n if (isMemo) {\n const inner = node.arguments[0]\n const innerText = inner ? detectGetNodeText(ctx, inner) : 'Component'\n\n detectDiag(\n ctx,\n node,\n 'memo-wrapper',\n 'memo() is not needed in Pyreon. Components run once — only signals trigger updates, not re-renders.',\n detectGetNodeText(ctx, node),\n innerText,\n true,\n )\n }\n}\n\nfunction detectForwardRef(ctx: DetectContext, node: ts.CallExpression): void {\n const callee = node.expression\n const isForwardRef =\n (ts.isIdentifier(callee) && callee.text === 'forwardRef') ||\n isCallToReactDot(callee, 'forwardRef')\n\n if (isForwardRef) {\n detectDiag(\n ctx,\n node,\n 'forward-ref',\n 'forwardRef is not needed in Pyreon. Pass ref as a regular prop.',\n detectGetNodeText(ctx, node),\n '// Just pass ref as a prop:\\nconst MyInput = (props) => <input ref={props.ref} />',\n true,\n )\n }\n}\n\nfunction detectJsxAttributes(ctx: DetectContext, node: ts.JsxAttribute): void {\n const attrName = (node.name as ts.Identifier).text\n\n if (attrName in JSX_ATTR_REWRITES) {\n const htmlAttr = JSX_ATTR_REWRITES[attrName] as string\n detectDiag(\n ctx,\n node,\n attrName === 'className' ? 'class-name-prop' : 'html-for-prop',\n `'${attrName}' is a React JSX attribute. Use '${htmlAttr}' in Pyreon (standard HTML).`,\n detectGetNodeText(ctx, node),\n detectGetNodeText(ctx, node).replace(attrName, htmlAttr),\n true,\n )\n }\n\n if (attrName === 'onChange') {\n const jsxElement = findParentJsxElement(node)\n if (jsxElement) {\n const tagName = getJsxTagName(jsxElement)\n if (tagName === 'input' || tagName === 'textarea' || tagName === 'select') {\n detectDiag(\n ctx,\n node,\n 'on-change-input',\n `onChange on <${tagName}> fires on blur in Pyreon (native DOM behavior). For keypress-by-keypress updates, use onInput.`,\n detectGetNodeText(ctx, node),\n detectGetNodeText(ctx, node).replace('onChange', 'onInput'),\n true,\n )\n }\n }\n }\n\n if (attrName === 'dangerouslySetInnerHTML') {\n detectDiag(\n ctx,\n node,\n 'dangerously-set-inner-html',\n 'dangerouslySetInnerHTML is React-specific. Use innerHTML prop in Pyreon.',\n detectGetNodeText(ctx, node),\n 'innerHTML={htmlString}',\n true,\n )\n }\n}\n\nfunction detectDotValueSignal(ctx: DetectContext, node: ts.PropertyAccessExpression): void {\n const varName = (node.expression as ts.Identifier).text\n const parent = node.parent\n if (ts.isBinaryExpression(parent) && parent.left === node) {\n detectDiag(\n ctx,\n node,\n 'dot-value-signal',\n `'${varName}.value' looks like a Vue ref pattern. Pyreon signals are callable functions. Use ${varName}.set(x) to write.`,\n detectGetNodeText(ctx, parent),\n `${varName}.set(${detectGetNodeText(ctx, parent.right)})`,\n false,\n )\n }\n}\n\nfunction detectArrayMapJsx(ctx: DetectContext, node: ts.CallExpression): void {\n const parent = node.parent\n if (ts.isJsxExpression(parent)) {\n const arrayExpr = detectGetNodeText(\n ctx,\n (node.expression as ts.PropertyAccessExpression).expression,\n )\n const mapCallback = node.arguments[0]\n const mapCallbackText = mapCallback\n ? detectGetNodeText(ctx, mapCallback)\n : 'item => <li>{item}</li>'\n\n detectDiag(\n ctx,\n node,\n 'array-map-jsx',\n 'Array.map() in JSX is not reactive in Pyreon. Use <For> for efficient keyed list rendering.',\n detectGetNodeText(ctx, node),\n `<For each={${arrayExpr}} by={item => item.id}>\\n {${mapCallbackText}}\\n</For>`,\n false,\n )\n }\n}\n\nfunction isCallToHook(node: ts.Node, hookName: string): node is ts.CallExpression {\n return (\n ts.isCallExpression(node) &&\n ts.isIdentifier(node.expression) &&\n node.expression.text === hookName\n )\n}\n\nfunction isCallToEffectHook(node: ts.Node): node is ts.CallExpression {\n return (\n ts.isCallExpression(node) &&\n ts.isIdentifier(node.expression) &&\n (node.expression.text === 'useEffect' || node.expression.text === 'useLayoutEffect')\n )\n}\n\nfunction isMapCallExpression(node: ts.Node): node is ts.CallExpression {\n return (\n ts.isCallExpression(node) &&\n ts.isPropertyAccessExpression(node.expression) &&\n ts.isIdentifier(node.expression.name) &&\n node.expression.name.text === 'map'\n )\n}\n\nfunction isDotValueAccess(node: ts.Node): node is ts.PropertyAccessExpression {\n return (\n ts.isPropertyAccessExpression(node) &&\n ts.isIdentifier(node.name) &&\n node.name.text === 'value' &&\n ts.isIdentifier(node.expression)\n )\n}\n\nfunction detectVisitNode(ctx: DetectContext, node: ts.Node): void {\n if (ts.isImportDeclaration(node)) detectImportDeclaration(ctx, node)\n if (isCallToHook(node, 'useState')) detectUseState(ctx, node)\n if (isCallToEffectHook(node)) detectUseEffect(ctx, node)\n if (isCallToHook(node, 'useMemo')) detectUseMemo(ctx, node)\n if (isCallToHook(node, 'useCallback')) detectUseCallback(ctx, node)\n if (isCallToHook(node, 'useRef')) detectUseRef(ctx, node)\n if (isCallToHook(node, 'useReducer')) detectUseReducer(ctx, node)\n if (ts.isCallExpression(node)) detectMemoWrapper(ctx, node)\n if (ts.isCallExpression(node)) detectForwardRef(ctx, node)\n if (ts.isJsxAttribute(node) && ts.isIdentifier(node.name)) detectJsxAttributes(ctx, node)\n if (isDotValueAccess(node)) detectDotValueSignal(ctx, node)\n if (isMapCallExpression(node)) detectArrayMapJsx(ctx, node)\n}\n\nfunction detectVisit(ctx: DetectContext, node: ts.Node): void {\n ts.forEachChild(node, (child) => {\n detectVisitNode(ctx, child)\n detectVisit(ctx, child)\n })\n}\n\nexport function detectReactPatterns(code: string, filename = 'input.tsx'): ReactDiagnostic[] {\n const sf = ts.createSourceFile(filename, code, ts.ScriptTarget.ESNext, true, ts.ScriptKind.TSX)\n const ctx: DetectContext = {\n sf,\n code,\n diagnostics: [],\n reactImportedHooks: new Set<string>(),\n }\n\n detectVisit(ctx, sf)\n return ctx.diagnostics\n}\n\n// ═══════════════════════════════════════════════════════════════════════════════\n// Migration (detection + auto-fix)\n// ═══════════════════════════════════════════════════════════════════════════════\n\ntype Replacement = { start: number; end: number; text: string }\n\ninterface MigrateContext {\n sf: ts.SourceFile\n code: string\n replacements: Replacement[]\n changes: MigrationChange[]\n pyreonImports: Map<string, Set<string>>\n importsToRemove: Set<ts.ImportDeclaration>\n specifierRewrites: Map<ts.ImportSpecifier, { name: string; from: string }>\n}\n\nfunction migrateAddImport(ctx: MigrateContext, source: string, specifier: string): void {\n if (!source || !specifier) return\n let specs = ctx.pyreonImports.get(source)\n if (!specs) {\n specs = new Set()\n ctx.pyreonImports.set(source, specs)\n }\n specs.add(specifier)\n}\n\nfunction migrateReplace(ctx: MigrateContext, node: ts.Node, text: string): void {\n ctx.replacements.push({ start: node.getStart(ctx.sf), end: node.getEnd(), text })\n}\n\nfunction migrateGetNodeText(ctx: MigrateContext, node: ts.Node): string {\n return ctx.code.slice(node.getStart(ctx.sf), node.getEnd())\n}\n\nfunction migrateGetLine(ctx: MigrateContext, node: ts.Node): number {\n return ctx.sf.getLineAndCharacterOfPosition(node.getStart(ctx.sf)).line + 1\n}\n\nfunction migrateImportDeclaration(ctx: MigrateContext, node: ts.ImportDeclaration): void {\n if (!node.moduleSpecifier) return\n const source = (node.moduleSpecifier as ts.StringLiteral).text\n if (!(source in IMPORT_REWRITES)) return\n\n if (node.importClause?.namedBindings && ts.isNamedImports(node.importClause.namedBindings)) {\n for (const spec of node.importClause.namedBindings.elements) {\n const name = spec.name.text\n const rewrite = SPECIFIER_REWRITES[name]\n if (rewrite) {\n if (rewrite.name) {\n migrateAddImport(ctx, rewrite.from, rewrite.name)\n }\n ctx.specifierRewrites.set(spec, rewrite)\n }\n }\n }\n ctx.importsToRemove.add(node)\n}\n\nfunction migrateUseState(ctx: MigrateContext, node: ts.CallExpression): void {\n const parent = node.parent\n if (\n ts.isVariableDeclaration(parent) &&\n parent.name &&\n ts.isArrayBindingPattern(parent.name) &&\n parent.name.elements.length >= 1\n ) {\n const firstEl = parent.name.elements[0]\n const valueName =\n firstEl && ts.isBindingElement(firstEl) ? (firstEl.name as ts.Identifier).text : 'value'\n const initArg = node.arguments[0] ? migrateGetNodeText(ctx, node.arguments[0]) : 'undefined'\n\n const declStart = parent.getStart(ctx.sf)\n const declEnd = parent.getEnd()\n ctx.replacements.push({\n start: declStart,\n end: declEnd,\n text: `${valueName} = signal(${initArg})`,\n })\n migrateAddImport(ctx, '@pyreon/reactivity', 'signal')\n ctx.changes.push({\n type: 'replace',\n line: migrateGetLine(ctx, node),\n description: `useState → signal: ${valueName}`,\n })\n }\n}\n\nfunction migrateUseEffect(ctx: MigrateContext, node: ts.CallExpression): void {\n const depsArg = node.arguments[1]\n const callbackArg = node.arguments[0]\n const hookName = (node.expression as ts.Identifier).text\n\n if (\n depsArg &&\n ts.isArrayLiteralExpression(depsArg) &&\n depsArg.elements.length === 0 &&\n callbackArg\n ) {\n const callbackText = migrateGetNodeText(ctx, callbackArg)\n migrateReplace(ctx, node, `onMount(${callbackText})`)\n migrateAddImport(ctx, '@pyreon/core', 'onMount')\n ctx.changes.push({\n type: 'replace',\n line: migrateGetLine(ctx, node),\n description: `${hookName}(fn, []) → onMount(fn)`,\n })\n } else if (callbackArg) {\n const callbackText = migrateGetNodeText(ctx, callbackArg)\n migrateReplace(ctx, node, `effect(${callbackText})`)\n migrateAddImport(ctx, '@pyreon/reactivity', 'effect')\n ctx.changes.push({\n type: 'replace',\n line: migrateGetLine(ctx, node),\n description: `${hookName} → effect (auto-tracks deps)`,\n })\n }\n}\n\nfunction migrateUseMemo(ctx: MigrateContext, node: ts.CallExpression): void {\n const computeFn = node.arguments[0]\n if (computeFn) {\n migrateReplace(ctx, node, `computed(${migrateGetNodeText(ctx, computeFn)})`)\n migrateAddImport(ctx, '@pyreon/reactivity', 'computed')\n ctx.changes.push({\n type: 'replace',\n line: migrateGetLine(ctx, node),\n description: 'useMemo → computed (auto-tracks deps)',\n })\n }\n}\n\nfunction migrateUseCallback(ctx: MigrateContext, node: ts.CallExpression): void {\n const callbackFn = node.arguments[0]\n if (callbackFn) {\n migrateReplace(ctx, node, migrateGetNodeText(ctx, callbackFn))\n ctx.changes.push({\n type: 'replace',\n line: migrateGetLine(ctx, node),\n description: 'useCallback → plain function (not needed in Pyreon)',\n })\n }\n}\n\nfunction migrateUseRef(ctx: MigrateContext, node: ts.CallExpression): void {\n const arg = node.arguments[0]\n const isNullInit =\n arg &&\n (arg.kind === ts.SyntaxKind.NullKeyword || (ts.isIdentifier(arg) && arg.text === 'undefined'))\n\n if (isNullInit || !arg) {\n migrateReplace(ctx, node, 'createRef()')\n migrateAddImport(ctx, '@pyreon/core', 'createRef')\n ctx.changes.push({\n type: 'replace',\n line: migrateGetLine(ctx, node),\n description: 'useRef(null) → createRef()',\n })\n } else {\n migrateReplace(ctx, node, `signal(${migrateGetNodeText(ctx, arg)})`)\n migrateAddImport(ctx, '@pyreon/reactivity', 'signal')\n ctx.changes.push({\n type: 'replace',\n line: migrateGetLine(ctx, node),\n description: 'useRef(value) → signal(value)',\n })\n }\n}\n\nfunction migrateMemoWrapper(ctx: MigrateContext, node: ts.CallExpression): void {\n const callee = node.expression\n const isMemo =\n (ts.isIdentifier(callee) && callee.text === 'memo') || isCallToReactDot(callee, 'memo')\n\n if (isMemo && node.arguments[0]) {\n migrateReplace(ctx, node, migrateGetNodeText(ctx, node.arguments[0]))\n ctx.changes.push({\n type: 'remove',\n line: migrateGetLine(ctx, node),\n description: 'Removed memo() wrapper (not needed in Pyreon)',\n })\n }\n}\n\nfunction migrateForwardRef(ctx: MigrateContext, node: ts.CallExpression): void {\n const callee = node.expression\n const isForwardRef =\n (ts.isIdentifier(callee) && callee.text === 'forwardRef') ||\n isCallToReactDot(callee, 'forwardRef')\n\n if (isForwardRef && node.arguments[0]) {\n migrateReplace(ctx, node, migrateGetNodeText(ctx, node.arguments[0]))\n ctx.changes.push({\n type: 'remove',\n line: migrateGetLine(ctx, node),\n description: 'Removed forwardRef wrapper (pass ref as normal prop in Pyreon)',\n })\n }\n}\n\nfunction migrateJsxAttributes(ctx: MigrateContext, node: ts.JsxAttribute): void {\n const attrName = (node.name as ts.Identifier).text\n\n if (attrName in JSX_ATTR_REWRITES) {\n const htmlAttr = JSX_ATTR_REWRITES[attrName] as string\n ctx.replacements.push({\n start: node.name.getStart(ctx.sf),\n end: node.name.getEnd(),\n text: htmlAttr,\n })\n ctx.changes.push({\n type: 'replace',\n line: migrateGetLine(ctx, node),\n description: `${attrName} → ${htmlAttr}`,\n })\n }\n\n if (attrName === 'onChange') {\n const jsxElement = findParentJsxElement(node)\n if (jsxElement) {\n const tagName = getJsxTagName(jsxElement)\n if (tagName === 'input' || tagName === 'textarea' || tagName === 'select') {\n ctx.replacements.push({\n start: node.name.getStart(ctx.sf),\n end: node.name.getEnd(),\n text: 'onInput',\n })\n ctx.changes.push({\n type: 'replace',\n line: migrateGetLine(ctx, node),\n description: `onChange on <${tagName}> → onInput (native DOM events)`,\n })\n }\n }\n }\n\n if (attrName === 'dangerouslySetInnerHTML') {\n migrateDangerouslySetInnerHTML(ctx, node)\n }\n}\n\nfunction migrateDangerouslySetInnerHTML(ctx: MigrateContext, node: ts.JsxAttribute): void {\n if (!node.initializer || !ts.isJsxExpression(node.initializer) || !node.initializer.expression) {\n return\n }\n const expr = node.initializer.expression\n if (!ts.isObjectLiteralExpression(expr)) return\n\n const htmlProp = expr.properties.find(\n (p) => ts.isPropertyAssignment(p) && ts.isIdentifier(p.name) && p.name.text === '__html',\n ) as ts.PropertyAssignment | undefined\n\n if (htmlProp) {\n const valueText = migrateGetNodeText(ctx, htmlProp.initializer)\n migrateReplace(ctx, node, `innerHTML={${valueText}}`)\n ctx.changes.push({\n type: 'replace',\n line: migrateGetLine(ctx, node),\n description: 'dangerouslySetInnerHTML → innerHTML',\n })\n }\n}\n\nfunction applyReplacements(code: string, ctx: MigrateContext): string {\n // Remove React import declarations\n for (const imp of ctx.importsToRemove) {\n ctx.replacements.push({ start: imp.getStart(ctx.sf), end: imp.getEnd(), text: '' })\n ctx.changes.push({\n type: 'remove',\n line: ctx.sf.getLineAndCharacterOfPosition(imp.getStart(ctx.sf)).line + 1,\n description: 'Removed React import',\n })\n }\n\n // Sort descending for dedup (outermost replacements win over inner overlapping ones)\n ctx.replacements.sort((a, b) => b.start - a.start)\n\n // Deduplicate overlapping replacements (keep the outermost / first added)\n const applied = new Set<string>()\n const deduped: Replacement[] = []\n for (const r of ctx.replacements) {\n const key = `${r.start}:${r.end}`\n let overlaps = false\n for (const d of deduped) {\n if (r.start < d.end && r.end > d.start) {\n overlaps = true\n break\n }\n }\n if (!overlaps && !applied.has(key)) {\n applied.add(key)\n deduped.push(r)\n }\n }\n\n // Re-sort ascending for string builder — O(n) single join\n deduped.sort((a, b) => a.start - b.start)\n const parts: string[] = []\n let lastPos = 0\n for (const r of deduped) {\n parts.push(code.slice(lastPos, r.start))\n parts.push(r.text)\n lastPos = r.end\n }\n parts.push(code.slice(lastPos))\n return parts.join('')\n}\n\nfunction insertPyreonImports(code: string, pyreonImports: Map<string, Set<string>>): string {\n if (pyreonImports.size === 0) return code\n\n const importLines: string[] = []\n const sorted = [...pyreonImports.entries()].sort(([a], [b]) => a.localeCompare(b))\n for (const [source, specs] of sorted) {\n const specList = [...specs].sort().join(', ')\n importLines.push(`import { ${specList} } from \"${source}\"`)\n }\n const importBlock = importLines.join('\\n')\n\n const lastImportEnd = findLastImportEnd(code)\n if (lastImportEnd > 0) {\n return `${code.slice(0, lastImportEnd)}\\n${importBlock}${code.slice(lastImportEnd)}`\n }\n return `${importBlock}\\n\\n${code}`\n}\n\nfunction migrateVisitNode(ctx: MigrateContext, node: ts.Node): void {\n if (ts.isImportDeclaration(node)) migrateImportDeclaration(ctx, node)\n if (isCallToHook(node, 'useState')) migrateUseState(ctx, node)\n if (isCallToEffectHook(node)) migrateUseEffect(ctx, node)\n if (isCallToHook(node, 'useMemo')) migrateUseMemo(ctx, node)\n if (isCallToHook(node, 'useCallback')) migrateUseCallback(ctx, node)\n if (isCallToHook(node, 'useRef')) migrateUseRef(ctx, node)\n if (ts.isCallExpression(node)) migrateMemoWrapper(ctx, node)\n if (ts.isCallExpression(node)) migrateForwardRef(ctx, node)\n if (ts.isJsxAttribute(node) && ts.isIdentifier(node.name)) migrateJsxAttributes(ctx, node)\n}\n\nfunction migrateVisit(ctx: MigrateContext, node: ts.Node): void {\n ts.forEachChild(node, (child) => {\n migrateVisitNode(ctx, child)\n migrateVisit(ctx, child)\n })\n}\n\nexport function migrateReactCode(code: string, filename = 'input.tsx'): MigrationResult {\n const sf = ts.createSourceFile(filename, code, ts.ScriptTarget.ESNext, true, ts.ScriptKind.TSX)\n const diagnostics = detectReactPatterns(code, filename)\n\n const ctx: MigrateContext = {\n sf,\n code,\n replacements: [],\n changes: [],\n pyreonImports: new Map(),\n importsToRemove: new Set(),\n specifierRewrites: new Map(),\n }\n\n migrateVisit(ctx, sf)\n\n let result = applyReplacements(code, ctx)\n result = insertPyreonImports(result, ctx.pyreonImports)\n\n // Clean up empty lines from removed imports\n result = result.replace(/\\n{3,}/g, '\\n\\n')\n\n return { code: result, diagnostics, changes: ctx.changes }\n}\n\n// ═══════════════════════════════════════════════════════════════════════════════\n// Helpers\n// ═══════════════════════════════════════════════════════════════════════════════\n\nfunction findParentJsxElement(\n node: ts.Node,\n): ts.JsxOpeningElement | ts.JsxSelfClosingElement | null {\n let current = node.parent\n while (current) {\n if (ts.isJsxOpeningElement(current) || ts.isJsxSelfClosingElement(current)) {\n return current\n }\n // Don't cross component boundaries\n if (ts.isJsxElement(current)) {\n return current.openingElement\n }\n if (ts.isArrowFunction(current) || ts.isFunctionExpression(current)) {\n return null\n }\n current = current.parent\n }\n return null\n}\n\nfunction getJsxTagName(node: ts.JsxOpeningElement | ts.JsxSelfClosingElement): string {\n const tagName = node.tagName\n if (ts.isIdentifier(tagName)) {\n return tagName.text\n }\n return ''\n}\n\nfunction findLastImportEnd(code: string): number {\n const importRe = /^import\\s.+$/gm\n let lastEnd = 0\n let match: RegExpExecArray | null\n while (true) {\n match = importRe.exec(code)\n if (!match) break\n lastEnd = match.index + match[0].length\n }\n return lastEnd\n}\n\n// ═══════════════════════════════════════════════════════════════════════════════\n// Quick scan (regex-based, for fast pre-filtering)\n// ═══════════════════════════════════════════════════════════════════════════════\n\n/** Fast regex check — returns true if code likely contains React patterns worth analyzing */\nexport function hasReactPatterns(code: string): boolean {\n return (\n /\\bfrom\\s+['\"]react/.test(code) ||\n /\\bfrom\\s+['\"]react-dom/.test(code) ||\n /\\bfrom\\s+['\"]react-router/.test(code) ||\n /\\buseState\\s*[<(]/.test(code) ||\n /\\buseEffect\\s*\\(/.test(code) ||\n /\\buseMemo\\s*\\(/.test(code) ||\n /\\buseCallback\\s*\\(/.test(code) ||\n /\\buseRef\\s*[<(]/.test(code) ||\n /\\buseReducer\\s*[<(]/.test(code) ||\n /\\bReact\\.memo\\b/.test(code) ||\n /\\bforwardRef\\s*[<(]/.test(code) ||\n /\\bclassName[=\\s]/.test(code) ||\n /\\bhtmlFor[=\\s]/.test(code) ||\n /\\.value\\s*=/.test(code)\n )\n}\n\n// ═══════════════════════════════════════════════════════════════════════════════\n// Error pattern database (for MCP diagnose tool)\n// ═══════════════════════════════════════════════════════════════════════════════\n\nexport interface ErrorDiagnosis {\n cause: string\n fix: string\n fixCode?: string | undefined\n related?: string | undefined\n}\n\ninterface ErrorPattern {\n pattern: RegExp\n diagnose: (match: RegExpMatchArray) => ErrorDiagnosis\n}\n\nconst ERROR_PATTERNS: ErrorPattern[] = [\n {\n pattern: /Cannot read properties of undefined \\(reading '(set|update|peek|subscribe)'\\)/,\n diagnose: (m) => ({\n cause: `Calling .${m[1]}() on undefined. The signal variable is likely out of scope, misspelled, or not yet initialized.`,\n fix: 'Check that the signal is defined and in scope. Signals must be created with signal() before use.',\n fixCode: `const mySignal = signal(initialValue)\\nmySignal.${m[1]}(newValue)`,\n }),\n },\n {\n pattern: /(\\w+) is not a function/,\n diagnose: (m) => ({\n cause: `'${m[1]}' is not callable. If this is a signal, you need to call it: ${m[1]}()`,\n fix: 'Pyreon signals are callable functions. Read: signal(), Write: signal.set(value)',\n fixCode: `// Read value:\\nconst value = ${m[1]}()\\n// Set value:\\n${m[1]}.set(newValue)`,\n }),\n },\n {\n pattern: /Cannot find module '(@pyreon\\/\\w[\\w-]*)'/,\n diagnose: (m) => ({\n cause: `Package ${m[1]} is not installed.`,\n fix: `Run: bun add ${m[1]}`,\n fixCode: `bun add ${m[1]}`,\n }),\n },\n {\n pattern: /Cannot find module 'react'/,\n diagnose: () => ({\n cause: \"Importing from 'react' in a Pyreon project.\",\n fix: 'Replace React imports with Pyreon equivalents.',\n fixCode:\n '// Instead of:\\nimport { useState } from \"react\"\\n// Use:\\nimport { signal } from \"@pyreon/reactivity\"',\n }),\n },\n {\n pattern: /Property '(\\w+)' does not exist on type 'Signal<\\w+>'/,\n diagnose: (m) => ({\n cause: `Accessing .${m[1]} on a signal. Pyreon signals don't have a .${m[1]} property.`,\n fix:\n m[1] === 'value'\n ? 'Pyreon signals are callable functions, not .value getters. Call signal() to read, signal.set() to write.'\n : `Signals have these methods: .set(), .update(), .peek(), .subscribe(). '${m[1]}' is not one of them.`,\n fixCode:\n m[1] === 'value' ? '// Read: mySignal()\\n// Write: mySignal.set(newValue)' : undefined,\n }),\n },\n {\n pattern: /Type '(\\w+)' is not assignable to type 'VNode'/,\n diagnose: (m) => ({\n cause: `Component returned ${m[1]} instead of VNode. Components must return JSX, null, or a string.`,\n fix: 'Make sure your component returns a JSX element, null, or a string.',\n fixCode: 'const MyComponent = (props) => {\\n return <div>{props.children}</div>\\n}',\n }),\n },\n {\n pattern: /onMount callback must return/,\n diagnose: () => ({\n cause: 'onMount expects a callback that optionally returns a CleanupFn.',\n fix: 'Return a cleanup function, or return nothing.',\n fixCode: 'onMount(() => {\\n // setup code\\n})',\n }),\n },\n {\n pattern: /Expected 'by' prop on <For>/,\n diagnose: () => ({\n cause: \"<For> requires a 'by' prop for efficient keyed reconciliation.\",\n fix: 'Add a by prop that returns a unique key for each item.',\n fixCode:\n '<For each={items()} by={item => item.id}>\\n {item => <li>{item.name}</li>}\\n</For>',\n }),\n },\n {\n pattern: /useHook.*outside.*component/i,\n diagnose: () => ({\n cause:\n 'Hook called outside a component function. Pyreon hooks must be called during component setup.',\n fix: 'Move the hook call inside a component function body.',\n }),\n },\n {\n pattern: /Hydration mismatch/,\n diagnose: () => ({\n cause: \"Server-rendered HTML doesn't match client-rendered output.\",\n fix: 'Ensure SSR and client render the same initial content. Check for browser-only APIs (window, document) in SSR code.',\n related: \"Use typeof window !== 'undefined' checks or onMount() for client-only code.\",\n }),\n },\n]\n\n/** Diagnose an error message and return structured fix information */\nexport function diagnoseError(error: string): ErrorDiagnosis | null {\n for (const { pattern, diagnose } of ERROR_PATTERNS) {\n const match = error.match(pattern)\n if (match) {\n return diagnose(match)\n }\n }\n return null\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0DA,MAAM,aAAa,IAAI,IAAI,CAAC,OAAO,MAAM,CAAC;AAE1C,MAAM,WAAW;AAEjB,MAAM,mBAAmB,IAAI,IAAI;CAC/B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAC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AAM,QAAQ,MAAM,MAAM,QAAQ;AAClC,MAAI,MACF,QAAO,SAAS,MAAM;;AAG1B,QAAO"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/jsx.ts","../src/project-scanner.ts","../src/react-intercept.ts"],"sourcesContent":["/**\n * JSX transform — wraps dynamic JSX expressions in `() =>` so the Pyreon runtime\n * receives reactive getters instead of eagerly-evaluated snapshot values.\n *\n * Rules:\n * - `<div>{expr}</div>` → `<div>{() => expr}</div>` (child)\n * - `<div class={expr}>` → `<div class={() => expr}>` (prop)\n * - `<button onClick={fn}>` → unchanged (event handler)\n * - `<div>{() => expr}</div>` → unchanged (already wrapped)\n * - `<div>{\"literal\"}</div>` → unchanged (static)\n *\n * Static VNode hoisting:\n * - Fully static JSX in expression containers is hoisted to module scope:\n * `{<span>Hello</span>}` → `const _$h0 = <span>Hello</span>` + `{_$h0}`\n * - Hoisted nodes are created ONCE at module initialisation, not per-instance.\n * - A JSX node is static if: all props are string literals / booleans / static\n * values, and all children are text nodes or other static JSX nodes.\n *\n * Template emission:\n * - JSX element trees with ≥ 2 DOM elements (no components, no spread attrs)\n * are compiled to `_tpl(html, bindFn)` calls instead of nested `h()` calls.\n * - The HTML string is parsed once via <template>.innerHTML, then cloneNode(true)\n * for each instance (~5-10x faster than sequential createElement calls).\n * - Static attributes are baked into the HTML string; dynamic attributes and\n * text content use renderEffect in the bind function.\n *\n * Implementation: TypeScript parser for positions + magic-string replacements.\n * No extra runtime dependencies — `typescript` is already in devDependencies.\n *\n * Known limitation (v0): expressions inside *nested* JSX within a child\n * expression container are not individually wrapped. They are still reactive\n * because the outer wrapper re-evaluates the whole subtree, just at a coarser\n * granularity. Fine-grained nested wrapping is planned for a future pass.\n */\n\nimport ts from 'typescript'\n\nexport interface CompilerWarning {\n /** Warning message */\n message: string\n /** Source file line number (1-based) */\n line: number\n /** Source file column number (0-based) */\n column: number\n /** Warning code for filtering */\n code: 'signal-call-in-jsx' | 'missing-key-on-for' | 'signal-in-static-prop'\n}\n\nexport interface TransformResult {\n /** Transformed source code (JSX preserved, only expression containers modified) */\n code: string\n /** Whether the output uses _tpl/_re template helpers (needs auto-import) */\n usesTemplates?: boolean\n /** Compiler warnings for common mistakes */\n warnings: CompilerWarning[]\n}\n\n// Props that should never be wrapped in a reactive getter\nconst SKIP_PROPS = new Set(['key', 'ref'])\n// Event handler pattern: onClick, onInput, onMouseEnter, …\nconst EVENT_RE = /^on[A-Z]/\n// Events delegated to the container — must match runtime DELEGATED_EVENTS set\nconst DELEGATED_EVENTS = new Set([\n 'click',\n 'dblclick',\n 'contextmenu',\n 'focusin',\n 'focusout',\n 'input',\n 'change',\n 'keydown',\n 'keyup',\n 'mousedown',\n 'mouseup',\n 'mousemove',\n 'mouseover',\n 'mouseout',\n 'pointerdown',\n 'pointerup',\n 'pointermove',\n 'pointerover',\n 'pointerout',\n 'touchstart',\n 'touchend',\n 'touchmove',\n 'submit',\n])\n\nexport function transformJSX(code: string, filename = 'input.tsx'): TransformResult {\n const scriptKind =\n filename.endsWith('.tsx') || filename.endsWith('.jsx') ? ts.ScriptKind.TSX : ts.ScriptKind.TSX // default to TSX so JSX is always parsed\n\n const sf = ts.createSourceFile(\n filename,\n code,\n ts.ScriptTarget.ESNext,\n /* setParentNodes */ true,\n scriptKind,\n )\n\n type Replacement = { start: number; end: number; text: string }\n const replacements: Replacement[] = []\n const warnings: CompilerWarning[] = []\n\n function warn(node: ts.Node, message: string, warnCode: CompilerWarning['code']): void {\n const { line, character } = sf.getLineAndCharacterOfPosition(node.getStart(sf))\n warnings.push({ message, line: line + 1, column: character, code: warnCode })\n }\n\n // ── Static hoisting state ─────────────────────────────────────────────────\n type Hoist = { name: string; text: string }\n const hoists: Hoist[] = []\n let hoistIdx = 0\n let needsTplImport = false\n let needsRpImport = false\n let needsBindTextImportGlobal = false\n let needsBindDirectImportGlobal = false\n let needsBindImportGlobal = false\n let needsApplyPropsImportGlobal = false\n\n /**\n * If `node` is a fully-static JSX element/fragment, register a module-scope\n * hoist for it and return the generated variable name. Otherwise return null.\n */\n function maybeHoist(node: ts.Node): string | null {\n if (\n (ts.isJsxElement(node) || ts.isJsxSelfClosingElement(node) || ts.isJsxFragment(node)) &&\n isStaticJSXNode(node as ts.JsxElement | ts.JsxSelfClosingElement | ts.JsxFragment)\n ) {\n const name = `_$h${hoistIdx++}`\n const text = code.slice(node.getStart(sf), node.getEnd())\n hoists.push({ name, text })\n return name\n }\n return null\n }\n\n function wrap(expr: ts.Expression): void {\n const start = expr.getStart(sf)\n const end = expr.getEnd()\n replacements.push({ start, end, text: `() => ${code.slice(start, end)}` })\n }\n\n /** Try to hoist or wrap an expression, pushing a replacement if needed. */\n function hoistOrWrap(expr: ts.Expression): void {\n const hoistName = maybeHoist(expr)\n if (hoistName) {\n replacements.push({ start: expr.getStart(sf), end: expr.getEnd(), text: hoistName })\n } else if (shouldWrap(expr)) {\n wrap(expr)\n }\n }\n\n // ── walk sub-handlers ───────────────────────────────────────────────────────\n\n /** Try to emit a template for a JsxElement. Returns true if handled. */\n function tryTemplateEmit(node: ts.JsxElement): boolean {\n const elemCount = templateElementCount(node, /* isRoot */ true)\n if (elemCount < 1) return false\n const tplCall = buildTemplateCall(node)\n if (!tplCall) return false\n const start = node.getStart(sf)\n const end = node.getEnd()\n const parent = node.parent\n const needsBraces = parent && (ts.isJsxElement(parent) || ts.isJsxFragment(parent))\n replacements.push({ start, end, text: needsBraces ? `{${tplCall}}` : tplCall })\n needsTplImport = true\n return true\n }\n\n /** Emit warnings for common JSX mistakes (e.g. <For> without by). */\n function checkForWarnings(node: ts.JsxElement | ts.JsxSelfClosingElement): void {\n const opening = ts.isJsxElement(node) ? node.openingElement : node\n const tagName = ts.isIdentifier(opening.tagName) ? opening.tagName.text : ''\n if (tagName !== 'For') return\n const hasBy = opening.attributes.properties.some(\n (p) => ts.isJsxAttribute(p) && ts.isIdentifier(p.name) && p.name.text === 'by',\n )\n if (!hasBy) {\n warn(\n opening.tagName,\n `<For> without a \"by\" prop will use index-based diffing, which is slower and may cause bugs with stateful children. Add by={(item) => item.id} for efficient keyed reconciliation.`,\n 'missing-key-on-for',\n )\n }\n }\n\n /** Handle a JSX attribute node — wrap or hoist its value if needed.\n *\n * Both DOM and component props are processed:\n * - DOM props: () => expr — applyProp creates renderEffect\n * - Component props: _rp(() => expr) — makeReactiveProps converts to getters\n *\n * The _rp() brand distinguishes compiler wrappers from user-written accessor\n * props (like Show's when, For's each) so makeReactiveProps only converts\n * compiler-emitted wrappers.\n */\n function handleJsxAttribute(node: ts.JsxAttribute): void {\n const name = ts.isIdentifier(node.name) ? node.name.text : ''\n if (SKIP_PROPS.has(name) || EVENT_RE.test(name)) return\n if (!node.initializer || !ts.isJsxExpression(node.initializer)) return\n const expr = node.initializer.expression\n if (!expr) return\n\n const openingEl = node.parent.parent as ts.JsxOpeningElement | ts.JsxSelfClosingElement\n const tagName = ts.isIdentifier(openingEl.tagName) ? openingEl.tagName.text : ''\n const isComponent = tagName.length > 0 && tagName.charAt(0) !== tagName.charAt(0).toLowerCase()\n\n if (isComponent) {\n // Component prop: wrap with _rp() brand so makeReactiveProps recognizes it.\n //\n // EXCEPTION: If the expression is a single JSX element (not a conditional),\n // do NOT wrap the outer expression. The JSX element is created once (stable VNode).\n // Its own inner props will be wrapped individually via recursive walk().\n // This prevents remounting: <Icon name={x()} /> stays one Icon instance,\n // only its name prop updates reactively.\n const isSingleJsx = ts.isJsxElement(expr) || ts.isJsxSelfClosingElement(expr)\n if (isSingleJsx) {\n // Don't wrap — recurse into the JSX element's attributes instead\n ts.forEachChild(expr, walk)\n return\n }\n\n const hoistName = maybeHoist(expr)\n if (hoistName) {\n replacements.push({ start: expr.getStart(sf), end: expr.getEnd(), text: hoistName })\n } else if (shouldWrap(expr)) {\n const start = expr.getStart(sf)\n const end = expr.getEnd()\n replacements.push({ start, end, text: `_rp(() => ${code.slice(start, end)})` })\n needsRpImport = true\n }\n } else {\n // DOM prop: standard () => expr wrapping\n hoistOrWrap(expr)\n }\n }\n\n /** Handle a JSX expression in child position — wrap, hoist, or recurse. */\n function handleJsxExpression(node: ts.JsxExpression): void {\n const expr = node.expression\n if (!expr) return\n const hoistName = maybeHoist(expr)\n if (hoistName) {\n replacements.push({ start: expr.getStart(sf), end: expr.getEnd(), text: hoistName })\n return\n }\n if (shouldWrap(expr)) {\n wrap(expr)\n return\n }\n // Not hoisted, not wrapped (e.g., arrow function in For callback).\n // Recurse into the expression body to find nested JSX elements\n // that should be compiled to _tpl() calls.\n ts.forEachChild(expr, walk)\n }\n\n function walk(node: ts.Node): void {\n if (ts.isJsxElement(node) && tryTemplateEmit(node)) return\n if (ts.isJsxSelfClosingElement(node) || ts.isJsxElement(node)) checkForWarnings(node)\n if (ts.isJsxAttribute(node)) {\n handleJsxAttribute(node)\n return\n }\n if (ts.isJsxExpression(node)) {\n handleJsxExpression(node)\n return\n }\n ts.forEachChild(node, walk)\n }\n\n walk(sf)\n\n if (replacements.length === 0 && hoists.length === 0) return { code, warnings }\n\n // Apply replacements left-to-right via string builder — O(n) single join\n replacements.sort((a, b) => a.start - b.start)\n\n const parts: string[] = []\n let lastPos = 0\n for (const r of replacements) {\n parts.push(code.slice(lastPos, r.start))\n parts.push(r.text)\n lastPos = r.end\n }\n parts.push(code.slice(lastPos))\n let result = parts.join('')\n\n // Prepend module-scope hoisted static VNode declarations\n if (hoists.length > 0) {\n const preamble = hoists.map((h) => `const ${h.name} = /*@__PURE__*/ ${h.text}\\n`).join('')\n result = preamble + result\n }\n\n // Prepend template imports if _tpl() was emitted\n if (needsTplImport) {\n const runtimeDomImports = ['_tpl']\n if (needsBindDirectImportGlobal) runtimeDomImports.push('_bindDirect')\n if (needsBindTextImportGlobal) runtimeDomImports.push('_bindText')\n if (needsApplyPropsImportGlobal) runtimeDomImports.push('_applyProps')\n const reactivityImports = needsBindImportGlobal\n ? `\\nimport { _bind } from \"@pyreon/reactivity\";`\n : ''\n result =\n `import { ${runtimeDomImports.join(', ')} } from \"@pyreon/runtime-dom\";${reactivityImports}\\n` +\n result\n }\n\n // Prepend _rp import if reactive component props were emitted\n if (needsRpImport) {\n result = `import { _rp } from \"@pyreon/core\";\\n` + result\n }\n\n return { code: result, usesTemplates: needsTplImport, warnings }\n\n // ── Template emission helpers (closures over sf, code) ──────────────────────\n\n /**\n * Check if attributes prevent template emission.\n * - `key` always bails (VNode reconciliation prop)\n * - Spread on inner elements bails (too complex to merge in _bind)\n * - Spread on root element is allowed — applied via applyProps in _bind\n */\n function hasBailAttr(node: ts.JsxElement | ts.JsxSelfClosingElement, isRoot = false): boolean {\n for (const attr of jsxAttrs(node)) {\n if (ts.isJsxSpreadAttribute(attr)) {\n // Allow spread on root element — handled in buildTemplateCall\n if (isRoot) continue\n return true\n }\n if (ts.isJsxAttribute(attr) && ts.isIdentifier(attr.name) && attr.name.text === 'key')\n return true\n }\n return false\n }\n\n /**\n * Count template-eligible elements for a single JSX child.\n * Returns 0 for skippable children, -1 for bail, positive for element count.\n */\n function countChildForTemplate(child: ts.JsxChild): number {\n if (ts.isJsxText(child)) return 0\n if (ts.isJsxElement(child) || ts.isJsxSelfClosingElement(child))\n return templateElementCount(child)\n if (ts.isJsxExpression(child)) {\n if (!child.expression) return 0\n return containsJSXInExpr(child.expression) ? -1 : 0\n }\n if (ts.isJsxFragment(child)) return templateFragmentCount(child)\n return -1\n }\n\n /**\n * Count DOM elements in a JSX subtree. Returns -1 if the tree is not\n * eligible for template emission.\n */\n function templateElementCount(\n node: ts.JsxElement | ts.JsxSelfClosingElement,\n isRoot = false,\n ): number {\n const tag = jsxTagName(node)\n if (!tag || !isLowerCase(tag)) return -1\n if (hasBailAttr(node, isRoot)) return -1\n if (!ts.isJsxElement(node)) return 1\n\n let count = 1\n for (const child of node.children) {\n const c = countChildForTemplate(child)\n if (c === -1) return -1\n count += c\n }\n return count\n }\n\n /** Count template-eligible elements inside a fragment. */\n function templateFragmentCount(frag: ts.JsxFragment): number {\n let count = 0\n for (const child of frag.children) {\n const c = countChildForTemplate(child)\n if (c === -1) return -1\n count += c\n }\n return count\n }\n\n /**\n * Build the complete `_tpl(\"html\", (__root) => { ... })` call string\n * for a template-eligible JSX element tree. Returns null if codegen fails.\n */\n function buildTemplateCall(node: ts.JsxElement | ts.JsxSelfClosingElement): string | null {\n const bindLines: string[] = []\n const disposerNames: string[] = []\n let varIdx = 0\n let dispIdx = 0\n // Reactive expressions that will be combined into a single _bind call\n const reactiveBindExprs: string[] = []\n let needsBindTextImport = false\n let needsBindDirectImport = false\n let needsApplyPropsImport = false\n\n function nextVar(): string {\n return `__e${varIdx++}`\n }\n function nextDisp(): string {\n const name = `__d${dispIdx++}`\n disposerNames.push(name)\n return name\n }\n function nextTextVar(): string {\n return `__t${varIdx++}`\n }\n\n /** Resolve the variable name for an element given its accessor path. */\n function resolveElementVar(accessor: string, hasDynamic: boolean): string {\n if (accessor === '__root') return '__root'\n if (hasDynamic) {\n const v = nextVar()\n bindLines.push(`const ${v} = ${accessor}`)\n return v\n }\n return accessor\n }\n\n /** Emit bind line for a ref attribute. */\n function emitRef(attr: ts.JsxAttribute, varName: string): void {\n if (!attr.initializer || !ts.isJsxExpression(attr.initializer)) return\n if (!attr.initializer.expression) return\n bindLines.push(`${sliceExpr(attr.initializer.expression)}.current = ${varName}`)\n }\n\n /** Emit event handler bind line — delegated (expando) or addEventListener. */\n function emitEventListener(attr: ts.JsxAttribute, attrName: string, varName: string): void {\n const eventName = (attrName[2] ?? '').toLowerCase() + attrName.slice(3)\n if (!attr.initializer || !ts.isJsxExpression(attr.initializer)) return\n if (!attr.initializer.expression) return\n const handler = sliceExpr(attr.initializer.expression)\n if (DELEGATED_EVENTS.has(eventName)) {\n // Delegated: store handler as expando property — container listener picks it up\n bindLines.push(`${varName}.__ev_${eventName} = ${handler}`)\n } else {\n bindLines.push(`${varName}.addEventListener(\"${eventName}\", ${handler})`)\n }\n }\n\n /** Return HTML string for a static attribute expression, or null if not static. */\n function staticAttrToHtml(exprNode: ts.Expression, htmlAttrName: string): string | null {\n if (!isStatic(exprNode)) return null\n if (ts.isStringLiteral(exprNode)) return ` ${htmlAttrName}=\"${escapeHtmlAttr(exprNode.text)}\"`\n if (ts.isNumericLiteral(exprNode)) return ` ${htmlAttrName}=\"${exprNode.text}\"`\n if (exprNode.kind === ts.SyntaxKind.TrueKeyword) return ` ${htmlAttrName}`\n return '' // false/null/undefined → omit\n }\n\n /**\n * Try to extract a direct signal reference from an expression.\n * Returns the callee text (e.g. \"count\" or \"row.label\") if the expression\n * is a single call with no arguments, otherwise null.\n */\n function tryDirectSignalRef(exprNode: ts.Expression): string | null {\n let inner = exprNode\n // Unwrap concise arrow: () => expr\n if (ts.isArrowFunction(inner) && !ts.isBlock(inner.body)) {\n inner = inner.body as ts.Expression\n }\n if (!ts.isCallExpression(inner)) return null\n if (inner.arguments.length > 0) return null\n const callee = inner.expression\n // Only match simple identifiers: count() → _bindText(count, node)\n // Property access like obj.method() is NOT safe — detaching the method\n // loses `this` context (e.g. value.toLocaleString becomes unbound).\n if (ts.isIdentifier(callee)) {\n return sliceExpr(callee)\n }\n return null\n }\n\n /** Unwrap a reactive accessor expression for use inside _bind(). */\n function unwrapAccessor(exprNode: ts.Expression): { expr: string; isReactive: boolean } {\n // Concise arrow: () => value() → unwrap to \"value()\"\n if (ts.isArrowFunction(exprNode) && !ts.isBlock(exprNode.body)) {\n return { expr: sliceExpr(exprNode.body as ts.Expression), isReactive: true }\n }\n // Block-body arrow/function: invoke it\n if (ts.isArrowFunction(exprNode) || ts.isFunctionExpression(exprNode)) {\n return { expr: `(${sliceExpr(exprNode)})()`, isReactive: true }\n }\n return { expr: sliceExpr(exprNode), isReactive: containsCall(exprNode) }\n }\n\n /** Build a setter expression for an attribute. */\n function attrSetter(htmlAttrName: string, varName: string, expr: string): string {\n if (htmlAttrName === 'class') return `${varName}.className = ${expr}`\n if (htmlAttrName === 'style') return `${varName}.style.cssText = ${expr}`\n return `${varName}.setAttribute(\"${htmlAttrName}\", ${expr})`\n }\n\n /** Emit bind line for a dynamic (non-static) attribute. */\n function emitDynamicAttr(\n _expr: string,\n exprNode: ts.Expression,\n htmlAttrName: string,\n varName: string,\n ): void {\n const { expr, isReactive } = unwrapAccessor(exprNode)\n\n if (!isReactive) {\n bindLines.push(attrSetter(htmlAttrName, varName, expr))\n return\n }\n\n // Direct signal binding for bare signal calls (e.g. class={() => active()})\n const directRef = tryDirectSignalRef(exprNode)\n if (directRef) {\n needsBindDirectImport = true\n const d = nextDisp()\n const updater =\n htmlAttrName === 'class'\n ? `(v) => { ${varName}.className = v == null ? \"\" : String(v) }`\n : htmlAttrName === 'style'\n ? `(v) => { if (typeof v === \"string\") ${varName}.style.cssText = v; else if (v) Object.assign(${varName}.style, v) }`\n : `(v) => { ${varName}.setAttribute(\"${htmlAttrName}\", v == null ? \"\" : String(v)) }`\n bindLines.push(`const ${d} = _bindDirect(${directRef}, ${updater})`)\n return\n }\n\n reactiveBindExprs.push(attrSetter(htmlAttrName, varName, expr))\n }\n\n /** Emit bind line or HTML for an expression attribute value. */\n function emitAttrExpression(\n exprNode: ts.Expression,\n htmlAttrName: string,\n varName: string,\n ): string {\n const staticHtml = staticAttrToHtml(exprNode, htmlAttrName)\n if (staticHtml !== null) return staticHtml\n\n // style={{...}} → Object.assign(el.style, {...}) for object expressions\n if (htmlAttrName === 'style' && ts.isObjectLiteralExpression(exprNode)) {\n bindLines.push(`Object.assign(${varName}.style, ${sliceExpr(exprNode)})`)\n return ''\n }\n\n emitDynamicAttr(sliceExpr(exprNode), exprNode, htmlAttrName, varName)\n return ''\n }\n\n /** Emit side-effects for special attrs (ref, event). Returns true if handled. */\n function tryEmitSpecialAttr(attr: ts.JsxAttribute, attrName: string, varName: string): boolean {\n if (attrName === 'ref') {\n emitRef(attr, varName)\n return true\n }\n if (EVENT_RE.test(attrName)) {\n emitEventListener(attr, attrName, varName)\n return true\n }\n return false\n }\n\n /** Convert an attribute initializer to HTML. Returns empty string for side-effect-only attrs. */\n function attrInitializerToHtml(\n attr: ts.JsxAttribute,\n htmlAttrName: string,\n varName: string,\n ): string {\n if (!attr.initializer) return ` ${htmlAttrName}`\n if (ts.isStringLiteral(attr.initializer))\n return ` ${htmlAttrName}=\"${escapeHtmlAttr(attr.initializer.text)}\"`\n if (ts.isJsxExpression(attr.initializer) && attr.initializer.expression)\n return emitAttrExpression(attr.initializer.expression, htmlAttrName, varName)\n return ''\n }\n\n /** Process a single attribute, returning HTML to append. */\n function processOneAttr(attr: ts.JsxAttributeLike, varName: string): string {\n // Spread attribute: apply all props at runtime\n if (ts.isJsxSpreadAttribute(attr)) {\n const expr = sliceExpr(attr.expression)\n // Use runtime-dom's applyProps which handles class, style, events, etc.\n needsApplyPropsImport = true\n if (containsCall(attr.expression)) {\n reactiveBindExprs.push(`_applyProps(${varName}, ${expr})`)\n } else {\n bindLines.push(`_applyProps(${varName}, ${expr})`)\n }\n return ''\n }\n if (!ts.isJsxAttribute(attr)) return ''\n const attrName = ts.isIdentifier(attr.name) ? attr.name.text : ''\n if (attrName === 'key') return ''\n if (tryEmitSpecialAttr(attr, attrName, varName)) return ''\n return attrInitializerToHtml(attr, JSX_TO_HTML_ATTR[attrName] ?? attrName, varName)\n }\n\n /** Process all attributes on an element, returning the HTML attribute string. */\n function processAttrs(el: ts.JsxElement | ts.JsxSelfClosingElement, varName: string): string {\n let htmlAttrs = ''\n for (const attr of jsxAttrs(el)) htmlAttrs += processOneAttr(attr, varName)\n return htmlAttrs\n }\n\n /** Emit bind lines for a reactive text expression child. */\n function emitReactiveTextChild(\n expr: string,\n exprNode: ts.Expression,\n varName: string,\n parentRef: string,\n childNodeIdx: number,\n needsPlaceholder: boolean,\n ): string {\n const tVar = nextTextVar()\n bindLines.push(`const ${tVar} = document.createTextNode(\"\")`)\n if (needsPlaceholder) {\n bindLines.push(\n `${parentRef}.replaceChild(${tVar}, ${parentRef}.childNodes[${childNodeIdx}])`,\n )\n } else {\n bindLines.push(`${varName}.appendChild(${tVar})`)\n }\n // Direct signal binding: bypass effect system entirely\n const directRef = tryDirectSignalRef(exprNode)\n if (directRef) {\n needsBindTextImport = true\n const d = nextDisp()\n bindLines.push(`const ${d} = _bindText(${directRef}, ${tVar})`)\n } else {\n // Each reactive text child gets its own _bind — independent tracking.\n // When r.name() changes, r.email()'s _bind doesn't re-run.\n needsBindImportGlobal = true\n const d = nextDisp()\n bindLines.push(`const ${d} = _bind(() => { ${tVar}.data = ${expr} })`)\n }\n return needsPlaceholder ? '<!>' : ''\n }\n\n /** Emit bind lines for a static text expression child. */\n function emitStaticTextChild(\n expr: string,\n varName: string,\n parentRef: string,\n childNodeIdx: number,\n needsPlaceholder: boolean,\n ): string {\n if (needsPlaceholder) {\n const tVar = nextTextVar()\n bindLines.push(`const ${tVar} = document.createTextNode(${expr})`)\n bindLines.push(\n `${parentRef}.replaceChild(${tVar}, ${parentRef}.childNodes[${childNodeIdx}])`,\n )\n return '<!>'\n }\n bindLines.push(`${varName}.textContent = ${expr}`)\n return ''\n }\n\n /** Process a single flat child, returning the HTML contribution or null on failure. */\n function processOneChild(\n child: FlatChild,\n varName: string,\n parentRef: string,\n useMixed: boolean,\n useMultiExpr: boolean,\n childNodeIdx: number,\n ): string | null {\n if (child.kind === 'text') return escapeHtmlText(child.text)\n if (child.kind === 'element') {\n const childAccessor = useMixed\n ? `${parentRef}.childNodes[${childNodeIdx}]`\n : `${parentRef}.children[${child.elemIdx}]`\n return processElement(child.node, childAccessor)\n }\n // expression\n const needsPlaceholder = useMixed || useMultiExpr\n const { expr, isReactive } = unwrapAccessor(child.expression)\n if (isReactive) {\n return emitReactiveTextChild(\n expr,\n child.expression,\n varName,\n parentRef,\n childNodeIdx,\n needsPlaceholder,\n )\n }\n return emitStaticTextChild(expr, varName, parentRef, childNodeIdx, needsPlaceholder)\n }\n\n /** Process children of a JsxElement, returning the children HTML. */\n function processChildren(el: ts.JsxElement, varName: string, accessor: string): string | null {\n const flatChildren = flattenChildren(el.children)\n const { useMixed, useMultiExpr } = analyzeChildren(flatChildren)\n const parentRef = accessor === '__root' ? '__root' : varName\n\n let html = ''\n let childNodeIdx = 0\n\n for (const child of flatChildren) {\n const childHtml = processOneChild(\n child,\n varName,\n parentRef,\n useMixed,\n useMultiExpr,\n childNodeIdx,\n )\n if (childHtml === null) return null\n html += childHtml\n childNodeIdx++\n }\n\n return html\n }\n\n /** Process a single DOM element for template emission. Returns the HTML string or null. */\n function processElement(\n el: ts.JsxElement | ts.JsxSelfClosingElement,\n accessor: string,\n ): string | null {\n const tag = jsxTagName(el)\n if (!tag) return null\n\n const varName = resolveElementVar(accessor, elementHasDynamic(el))\n const htmlAttrs = processAttrs(el, varName)\n let html = `<${tag}${htmlAttrs}>`\n\n if (ts.isJsxElement(el)) {\n const childHtml = processChildren(el, varName, accessor)\n if (childHtml === null) return null\n html += childHtml\n }\n\n if (!VOID_ELEMENTS.has(tag)) html += `</${tag}>`\n return html\n }\n\n const html = processElement(node, '__root')\n if (html === null) return null\n\n if (needsBindTextImport) needsBindTextImportGlobal = true\n if (needsBindDirectImport) needsBindDirectImportGlobal = true\n if (needsApplyPropsImport) needsApplyPropsImportGlobal = true\n\n // Build bind function body\n const escaped = html.replace(/\\\\/g, '\\\\\\\\').replace(/\"/g, '\\\\\"')\n\n // Emit combined _bind for reactive attribute/text expressions that\n // weren't handled by _bindText. This merges N separate _bind calls into\n // one — saving N-1 closures + deps arrays per template instance.\n // Emit a single combined _bind for all reactive attribute/text expressions\n // that weren't handled by _bindText. Merges N separate _bind calls into one —\n // saving N-1 closures + deps arrays per template instance.\n if (reactiveBindExprs.length > 0) {\n needsBindImportGlobal = true\n const combinedName = nextDisp()\n const combinedBody = reactiveBindExprs.join('; ')\n bindLines.push(`const ${combinedName} = _bind(() => { ${combinedBody} })`)\n }\n\n if (bindLines.length === 0 && disposerNames.length === 0) {\n return `_tpl(\"${escaped}\", () => null)`\n }\n\n let body = bindLines.map((l) => ` ${l}`).join('\\n')\n if (disposerNames.length > 0) {\n body += `\\n return () => { ${disposerNames.map((d) => `${d}()`).join('; ')} }`\n } else {\n body += '\\n return null'\n }\n\n return `_tpl(\"${escaped}\", (__root) => {\\n${body}\\n})`\n }\n\n /** Flat child descriptor for template children processing */\n type FlatChild =\n | { kind: 'text'; text: string }\n | { kind: 'element'; node: ts.JsxElement | ts.JsxSelfClosingElement; elemIdx: number }\n | { kind: 'expression'; expression: ts.Expression }\n\n /** Classify a single JSX child into a FlatChild descriptor. */\n function classifyJsxChild(\n child: ts.JsxChild,\n out: FlatChild[],\n elemIdxRef: { value: number },\n recurse: (kids: ts.NodeArray<ts.JsxChild>) => void,\n ): void {\n if (ts.isJsxText(child)) {\n const trimmed = child.text.replace(/\\n\\s*/g, '').trim()\n if (trimmed) out.push({ kind: 'text', text: trimmed })\n return\n }\n if (ts.isJsxElement(child) || ts.isJsxSelfClosingElement(child)) {\n out.push({ kind: 'element', node: child, elemIdx: elemIdxRef.value++ })\n return\n }\n if (ts.isJsxExpression(child)) {\n if (child.expression) out.push({ kind: 'expression', expression: child.expression })\n return\n }\n if (ts.isJsxFragment(child)) recurse(child.children)\n }\n\n /**\n * Flatten JSX children, inlining fragment children and stripping whitespace-only text.\n * Returns a flat array of child descriptors with element indices pre-computed.\n */\n function flattenChildren(children: ts.NodeArray<ts.JsxChild>): FlatChild[] {\n const flatList: FlatChild[] = []\n const elemIdxRef = { value: 0 }\n\n function addChildren(kids: ts.NodeArray<ts.JsxChild>): void {\n for (const child of kids) classifyJsxChild(child, flatList, elemIdxRef, addChildren)\n }\n\n addChildren(children)\n return flatList\n }\n\n /** Analyze flat children to determine indexing strategy. */\n function analyzeChildren(flatChildren: FlatChild[]): {\n useMixed: boolean\n useMultiExpr: boolean\n } {\n const hasElem = flatChildren.some((c) => c.kind === 'element')\n const hasNonElem = flatChildren.some((c) => c.kind !== 'element')\n const exprCount = flatChildren.filter((c) => c.kind === 'expression').length\n return { useMixed: hasElem && hasNonElem, useMultiExpr: exprCount > 1 }\n }\n\n /** Check if a single attribute is dynamic (has ref, event, or non-static expression). */\n function attrIsDynamic(attr: ts.JsxAttributeLike): boolean {\n if (!ts.isJsxAttribute(attr)) return false\n const name = ts.isIdentifier(attr.name) ? attr.name.text : ''\n if (name === 'ref') return true\n if (EVENT_RE.test(name)) return true\n if (!attr.initializer || !ts.isJsxExpression(attr.initializer)) return false\n const expr = attr.initializer.expression\n return expr ? !isStatic(expr) : false\n }\n\n /** Check if an element has any dynamic attributes, events, ref, or expression children */\n function elementHasDynamic(node: ts.JsxElement | ts.JsxSelfClosingElement): boolean {\n if (jsxAttrs(node).some(attrIsDynamic)) return true\n if (ts.isJsxElement(node)) {\n return node.children.some((c) => ts.isJsxExpression(c) && c.expression !== undefined)\n }\n return false\n }\n\n /** Slice expression source from the original code */\n function sliceExpr(expr: ts.Expression): string {\n return code.slice(expr.getStart(sf), expr.getEnd())\n }\n\n /** Get tag name string */\n function jsxTagName(node: ts.JsxElement | ts.JsxSelfClosingElement): string {\n const tag = ts.isJsxElement(node) ? node.openingElement.tagName : node.tagName\n return ts.isIdentifier(tag) ? tag.text : ''\n }\n\n /** Get attribute list */\n function jsxAttrs(\n node: ts.JsxElement | ts.JsxSelfClosingElement,\n ): ts.NodeArray<ts.JsxAttributeLike> {\n return ts.isJsxElement(node)\n ? node.openingElement.attributes.properties\n : node.attributes.properties\n }\n}\n\n// ─── Template constants ──────────────────────────────────────────────────────\n\nconst VOID_ELEMENTS = new Set([\n 'area',\n 'base',\n 'br',\n 'col',\n 'embed',\n 'hr',\n 'img',\n 'input',\n 'link',\n 'meta',\n 'param',\n 'source',\n 'track',\n 'wbr',\n])\n\nconst JSX_TO_HTML_ATTR: Record<string, string> = {\n className: 'class',\n htmlFor: 'for',\n}\n\nfunction isLowerCase(s: string): boolean {\n return s.length > 0 && s[0] === s[0]?.toLowerCase()\n}\n\n/** Check if an expression subtree contains JSX nodes */\nfunction containsJSXInExpr(node: ts.Node): boolean {\n if (ts.isJsxElement(node) || ts.isJsxSelfClosingElement(node) || ts.isJsxFragment(node))\n return true\n return ts.forEachChild(node, containsJSXInExpr) ?? false\n}\n\nfunction escapeHtmlAttr(s: string): string {\n return s.replace(/&/g, '&').replace(/\"/g, '"')\n}\n\nfunction escapeHtmlText(s: string): string {\n return s.replace(/&/g, '&').replace(/</g, '<')\n}\n\n// ─── Static JSX analysis ──────────────────────────────────────────────────────\n\ntype StaticJSXNode = ts.JsxElement | ts.JsxSelfClosingElement | ts.JsxFragment\n\nfunction isStaticJSXNode(node: StaticJSXNode): boolean {\n if (ts.isJsxSelfClosingElement(node)) {\n return isStaticAttrs(node.attributes)\n }\n if (ts.isJsxFragment(node)) {\n return node.children.every(isStaticChild)\n }\n // JsxElement\n return isStaticAttrs(node.openingElement.attributes) && node.children.every(isStaticChild)\n}\n\nfunction isStaticAttrs(attrs: ts.JsxAttributes): boolean {\n return attrs.properties.every((prop) => {\n // Spread attribute — always dynamic\n if (!ts.isJsxAttribute(prop)) return false\n // Boolean shorthand: <input disabled />\n if (!prop.initializer) return true\n // String literal: class=\"foo\"\n if (ts.isStringLiteral(prop.initializer)) return true\n // Must be JsxExpression — the only remaining JsxAttributeValue type\n const expr = (prop.initializer as ts.JsxExpression).expression\n return expr ? isStatic(expr) : true\n })\n}\n\nfunction isStaticChild(child: ts.JsxChild): boolean {\n // Plain text content\n if (ts.isJsxText(child)) return true\n // Nested JSX elements\n if (ts.isJsxSelfClosingElement(child)) return isStaticJSXNode(child)\n if (ts.isJsxElement(child)) return isStaticJSXNode(child)\n if (ts.isJsxFragment(child)) return isStaticJSXNode(child)\n // Must be JsxExpression — the only remaining JsxChild type\n const expr = (child as ts.JsxExpression).expression\n return expr ? isStatic(expr) : true\n}\n\n// ─── General helpers ──────────────────────────────────────────────────────────\n\nfunction isStatic(node: ts.Expression): boolean {\n return (\n ts.isStringLiteral(node) ||\n ts.isNumericLiteral(node) ||\n ts.isNoSubstitutionTemplateLiteral(node) ||\n node.kind === ts.SyntaxKind.TrueKeyword ||\n node.kind === ts.SyntaxKind.FalseKeyword ||\n node.kind === ts.SyntaxKind.NullKeyword ||\n node.kind === ts.SyntaxKind.UndefinedKeyword\n )\n // Note: object/array literals are NOT static — they need runtime application\n // (e.g., style={{ color: \"red\" }} requires Object.assign at runtime).\n}\n\n/** Known pure global functions that don't read signals. */\nconst PURE_CALLS = new Set([\n 'Math.max', 'Math.min', 'Math.abs', 'Math.floor', 'Math.ceil', 'Math.round',\n 'Math.pow', 'Math.sqrt', 'Math.random', 'Math.trunc', 'Math.sign',\n 'Number.parseInt', 'Number.parseFloat', 'Number.isNaN', 'Number.isFinite',\n 'parseInt', 'parseFloat', 'isNaN', 'isFinite',\n 'String.fromCharCode', 'String.fromCodePoint',\n 'Object.keys', 'Object.values', 'Object.entries', 'Object.assign',\n 'Object.freeze', 'Object.create',\n 'Array.from', 'Array.isArray', 'Array.of',\n 'JSON.stringify', 'JSON.parse',\n 'encodeURIComponent', 'decodeURIComponent', 'encodeURI', 'decodeURI',\n 'Date.now',\n])\n\n/** Check if a call expression calls a known pure function with static args. */\nfunction isPureStaticCall(node: ts.CallExpression): boolean {\n const callee = node.expression\n let name = ''\n\n if (ts.isIdentifier(callee)) {\n name = callee.text\n } else if (ts.isPropertyAccessExpression(callee) && ts.isIdentifier(callee.expression)) {\n name = `${callee.expression.text}.${callee.name.text}`\n }\n\n if (!PURE_CALLS.has(name)) return false\n // Pure call with all static arguments → result is static\n return node.arguments.every((arg) => !ts.isSpreadElement(arg) && isStatic(arg))\n}\n\nfunction shouldWrap(node: ts.Expression): boolean {\n // Already a function — user explicitly wrapped or it's a callback\n if (ts.isArrowFunction(node) || ts.isFunctionExpression(node)) return false\n // Static literal — no signals involved\n if (isStatic(node)) return false\n // Pure call with static args — result is constant\n if (ts.isCallExpression(node) && isPureStaticCall(node)) return false\n // Only wrap if the expression tree contains a call — signal reads are always\n // function calls (e.g. `count()`, `name()`). Plain identifiers, object literals\n // like `style={{ color: \"red\" }}`, array literals, and member accesses are\n // left as-is to avoid unnecessary reactive wrappers.\n return containsCall(node)\n}\n\nfunction containsCall(node: ts.Node): boolean {\n if (ts.isCallExpression(node)) {\n // Skip pure calls with static args\n if (isPureStaticCall(node as ts.CallExpression)) return false\n return true\n }\n if (ts.isTaggedTemplateExpression(node)) return true\n // Don't recurse into nested functions — they're self-contained\n if (ts.isArrowFunction(node) || ts.isFunctionExpression(node)) return false\n return ts.forEachChild(node, containsCall) ?? false\n}\n","/**\n * Project scanner — extracts route, component, and island information from source files.\n */\n\nimport * as fs from 'node:fs'\nimport * as path from 'node:path'\n\nexport interface RouteInfo {\n path: string\n name?: string | undefined\n component?: string | undefined\n hasLoader: boolean\n hasGuard: boolean\n params: string[]\n}\n\nexport interface ComponentInfo {\n name: string\n file: string\n hasSignals: boolean\n signalNames: string[]\n props: string[]\n}\n\nexport interface IslandInfo {\n name: string\n file: string\n hydrate: string\n}\n\nexport interface ProjectContext {\n framework: 'pyreon'\n version: string\n generatedAt: string\n routes: RouteInfo[]\n components: ComponentInfo[]\n islands: IslandInfo[]\n}\n\nexport function generateContext(cwd: string): ProjectContext {\n const files = collectSourceFiles(cwd)\n const version = readVersion(cwd)\n\n return {\n framework: 'pyreon',\n version,\n generatedAt: new Date().toISOString(),\n routes: extractRoutes(files, cwd),\n components: extractComponents(files, cwd),\n islands: extractIslands(files, cwd),\n }\n}\n\nfunction collectSourceFiles(cwd: string): string[] {\n const results: string[] = []\n const extensions = new Set(['.tsx', '.jsx', '.ts', '.js'])\n const ignoreDirs = new Set(['node_modules', 'dist', 'lib', '.pyreon', '.git', 'build'])\n\n function walk(dir: string): void {\n let entries: fs.Dirent[]\n try {\n entries = fs.readdirSync(dir, { withFileTypes: true })\n } catch {\n return\n }\n for (const entry of entries) {\n if (entry.name.startsWith('.') && entry.isDirectory()) continue\n if (ignoreDirs.has(entry.name) && entry.isDirectory()) continue\n const fullPath = path.join(dir, entry.name)\n if (entry.isDirectory()) {\n walk(fullPath)\n } else if (entry.isFile() && extensions.has(path.extname(entry.name))) {\n results.push(fullPath)\n }\n }\n }\n\n walk(cwd)\n return results\n}\n\nfunction extractRoutes(files: string[], _cwd: string): RouteInfo[] {\n const routes: RouteInfo[] = []\n\n for (const file of files) {\n let code: string\n try {\n code = fs.readFileSync(file, 'utf-8')\n } catch {\n continue\n }\n\n const routeArrayRe =\n /(?:createRouter\\s*\\(\\s*\\[|(?:const|let)\\s+routes\\s*(?::\\s*RouteRecord\\[\\])?\\s*=\\s*\\[)([\\s\\S]*?)\\]/g\n let match: RegExpExecArray | null\n for (match = routeArrayRe.exec(code); match; match = routeArrayRe.exec(code)) {\n const block = match[1] ?? ''\n const routeObjRe = /path\\s*:\\s*[\"']([^\"']+)[\"']/g\n let routeMatch: RegExpExecArray | null\n for (routeMatch = routeObjRe.exec(block); routeMatch; routeMatch = routeObjRe.exec(block)) {\n const routePath = routeMatch[1] ?? ''\n const surroundingStart = Math.max(0, routeMatch.index - 50)\n const surroundingEnd = Math.min(block.length, routeMatch.index + 200)\n const surrounding = block.slice(surroundingStart, surroundingEnd)\n\n routes.push({\n path: routePath,\n name: surrounding.match(/name\\s*:\\s*[\"']([^\"']+)[\"']/)?.[1],\n hasLoader: /loader\\s*:/.test(surrounding),\n hasGuard: /beforeEnter\\s*:|beforeLeave\\s*:/.test(surrounding),\n params: extractParams(routePath),\n })\n }\n }\n }\n\n return routes\n}\n\nfunction extractComponents(files: string[], cwd: string): ComponentInfo[] {\n const components: ComponentInfo[] = []\n\n for (const file of files) {\n let code: string\n try {\n code = fs.readFileSync(file, 'utf-8')\n } catch {\n continue\n }\n\n const componentRe =\n /(?:export\\s+)?(?:const|function)\\s+([A-Z]\\w*)\\s*(?::\\s*ComponentFn<[^>]+>\\s*)?=?\\s*\\(?(?:\\s*\\{?\\s*([^)]*?)\\s*\\}?\\s*)?\\)?\\s*(?:=>|{)/g\n let match: RegExpExecArray | null\n\n for (match = componentRe.exec(code); match; match = componentRe.exec(code)) {\n const name = match[1] ?? 'Unknown'\n const propsStr = match[2] ?? ''\n const props = propsStr\n .split(/[,;]/)\n .map((p) => p.trim().replace(/[{}]/g, '').trim().split(':')[0]?.split('=')[0]?.trim() ?? '')\n .filter((p) => p && p !== 'props')\n\n const bodyStart = match.index + match[0].length\n const body = code.slice(bodyStart, Math.min(code.length, bodyStart + 2000))\n const signalNames: string[] = []\n const signalRe = /(?:const|let)\\s+(\\w+)\\s*=\\s*signal\\s*[<(]/g\n let sigMatch: RegExpExecArray | null\n for (sigMatch = signalRe.exec(body); sigMatch; sigMatch = signalRe.exec(body)) {\n if (sigMatch[1]) signalNames.push(sigMatch[1])\n }\n\n components.push({\n name,\n file: path.relative(cwd, file),\n hasSignals: signalNames.length > 0,\n signalNames,\n props,\n })\n }\n }\n\n return components\n}\n\nfunction extractIslands(files: string[], cwd: string): IslandInfo[] {\n const islands: IslandInfo[] = []\n\n for (const file of files) {\n let code: string\n try {\n code = fs.readFileSync(file, 'utf-8')\n } catch {\n continue\n }\n\n const islandRe =\n /island\\s*\\(\\s*\\(\\)\\s*=>\\s*import\\(.+?\\)\\s*,\\s*\\{[^}]*name\\s*:\\s*[\"']([^\"']+)[\"'][^}]*?(?:hydrate\\s*:\\s*[\"']([^\"']+)[\"'])?[^}]*\\}/g\n let match: RegExpExecArray | null\n for (match = islandRe.exec(code); match; match = islandRe.exec(code)) {\n if (match[1]) {\n islands.push({\n name: match[1],\n file: path.relative(cwd, file),\n hydrate: match[2] ?? 'load',\n })\n }\n }\n }\n\n return islands\n}\n\nfunction extractParams(routePath: string): string[] {\n const params: string[] = []\n const paramRe = /:(\\w+)\\??/g\n let match: RegExpExecArray | null\n for (match = paramRe.exec(routePath); match; match = paramRe.exec(routePath)) {\n if (match[1]) params.push(match[1])\n }\n return params\n}\n\nfunction readVersion(cwd: string): string {\n try {\n const pkg = JSON.parse(fs.readFileSync(path.join(cwd, 'package.json'), 'utf-8'))\n const deps: Record<string, unknown> = { ...pkg.dependencies, ...pkg.devDependencies }\n for (const [name, ver] of Object.entries(deps)) {\n if (name.startsWith('@pyreon/') && typeof ver === 'string') return ver.replace(/^[\\^~]/, '')\n }\n return (pkg.version as string) || 'unknown'\n } catch {\n return 'unknown'\n }\n}\n","/**\n * React Pattern Interceptor — detects React/Vue patterns in code and provides\n * structured diagnostics with exact fix suggestions for AI-assisted migration.\n *\n * Two modes:\n * - `detectReactPatterns(code)` — returns diagnostics only (non-destructive)\n * - `migrateReactCode(code)` — applies auto-fixes and returns transformed code\n *\n * Designed for three consumers:\n * 1. Compiler pre-pass (warnings during build)\n * 2. CLI `pyreon doctor` (project-wide scanning)\n * 3. MCP server `migrate_react` / `validate` tools (AI agent integration)\n */\n\nimport ts from 'typescript'\n\n// ═══════════════════════════════════════════════════════════════════════════════\n// Types\n// ═══════════════════════════════════════════════════════════════════════════════\n\nexport type ReactDiagnosticCode =\n | 'react-import'\n | 'react-dom-import'\n | 'react-router-import'\n | 'use-state'\n | 'use-effect-mount'\n | 'use-effect-deps'\n | 'use-effect-no-deps'\n | 'use-memo'\n | 'use-callback'\n | 'use-ref-dom'\n | 'use-ref-box'\n | 'use-reducer'\n | 'use-layout-effect'\n | 'memo-wrapper'\n | 'forward-ref'\n | 'class-name-prop'\n | 'html-for-prop'\n | 'on-change-input'\n | 'dangerously-set-inner-html'\n | 'dot-value-signal'\n | 'array-map-jsx'\n | 'key-on-for-child'\n | 'create-context-import'\n | 'use-context-import'\n\nexport interface ReactDiagnostic {\n /** Machine-readable code for filtering and programmatic handling */\n code: ReactDiagnosticCode\n /** Human-readable message explaining the issue */\n message: string\n /** 1-based line number */\n line: number\n /** 0-based column */\n column: number\n /** The code as written */\n current: string\n /** The suggested Pyreon equivalent */\n suggested: string\n /** Whether migrateReactCode can auto-fix this */\n fixable: boolean\n}\n\nexport interface MigrationChange {\n type: 'replace' | 'remove' | 'add'\n line: number\n description: string\n}\n\nexport interface MigrationResult {\n /** Transformed source code */\n code: string\n /** All detected patterns (including unfixable ones) */\n diagnostics: ReactDiagnostic[]\n /** Description of changes applied */\n changes: MigrationChange[]\n}\n\n// ═══════════════════════════════════════════════════════════════════════════════\n// React Hook → Pyreon mapping\n// ═══════════════════════════════════════════════════════════════════════════════\n\ninterface HookMapping {\n pyreonFn: string\n pyreonImport: string\n description: string\n example: string\n}\n\nconst _REACT_HOOK_MAP: Record<string, HookMapping> = {\n useState: {\n pyreonFn: 'signal',\n pyreonImport: '@pyreon/reactivity',\n description: 'Signals are callable functions — read: count(), write: count.set(5)',\n example:\n 'const count = signal(0)\\n// Read: count() Write: count.set(5) Update: count.update(n => n + 1)',\n },\n useEffect: {\n pyreonFn: 'effect',\n pyreonImport: '@pyreon/reactivity',\n description: 'Effects auto-track signal dependencies — no dependency array needed',\n example: 'effect(() => {\\n console.log(count()) // auto-subscribes to count\\n})',\n },\n useLayoutEffect: {\n pyreonFn: 'effect',\n pyreonImport: '@pyreon/reactivity',\n description: 'Pyreon effects run synchronously after signal updates',\n example: 'effect(() => {\\n // runs sync after signal changes\\n})',\n },\n useMemo: {\n pyreonFn: 'computed',\n pyreonImport: '@pyreon/reactivity',\n description: 'Computed values auto-track dependencies and memoize',\n example: 'const doubled = computed(() => count() * 2)',\n },\n useCallback: {\n pyreonFn: '(plain function)',\n pyreonImport: '',\n description:\n 'Not needed — Pyreon components run once, so closures never go stale. Use a plain function',\n example: 'const handleClick = () => doSomething(count())',\n },\n useReducer: {\n pyreonFn: 'signal',\n pyreonImport: '@pyreon/reactivity',\n description: 'Use signal with update() for reducer-like patterns',\n example:\n 'const state = signal(initialState)\\nconst dispatch = (action) => state.update(s => reducer(s, action))',\n },\n}\n\n/** React import sources → Pyreon equivalents */\nconst IMPORT_REWRITES: Record<string, string | null> = {\n react: '@pyreon/core',\n 'react-dom': '@pyreon/runtime-dom',\n 'react-dom/client': '@pyreon/runtime-dom',\n 'react-dom/server': '@pyreon/runtime-server',\n 'react-router': '@pyreon/router',\n 'react-router-dom': '@pyreon/router',\n}\n\n/** React specifiers that map to specific Pyreon imports */\nconst SPECIFIER_REWRITES: Record<string, { name: string; from: string }> = {\n useState: { name: 'signal', from: '@pyreon/reactivity' },\n useEffect: { name: 'effect', from: '@pyreon/reactivity' },\n useLayoutEffect: { name: 'effect', from: '@pyreon/reactivity' },\n useMemo: { name: 'computed', from: '@pyreon/reactivity' },\n useReducer: { name: 'signal', from: '@pyreon/reactivity' },\n useRef: { name: 'signal', from: '@pyreon/reactivity' },\n createContext: { name: 'createContext', from: '@pyreon/core' },\n useContext: { name: 'useContext', from: '@pyreon/core' },\n Fragment: { name: 'Fragment', from: '@pyreon/core' },\n Suspense: { name: 'Suspense', from: '@pyreon/core' },\n lazy: { name: 'lazy', from: '@pyreon/core' },\n memo: { name: '', from: '' }, // removed, not needed\n forwardRef: { name: '', from: '' }, // removed, not needed\n createRoot: { name: 'mount', from: '@pyreon/runtime-dom' },\n hydrateRoot: { name: 'hydrateRoot', from: '@pyreon/runtime-dom' },\n // React Router\n useNavigate: { name: 'useRouter', from: '@pyreon/router' },\n useParams: { name: 'useRoute', from: '@pyreon/router' },\n useLocation: { name: 'useRoute', from: '@pyreon/router' },\n Link: { name: 'RouterLink', from: '@pyreon/router' },\n NavLink: { name: 'RouterLink', from: '@pyreon/router' },\n Outlet: { name: 'RouterView', from: '@pyreon/router' },\n useSearchParams: { name: 'useSearchParams', from: '@pyreon/router' },\n}\n\n/** JSX attribute rewrites (React → standard HTML) */\nconst JSX_ATTR_REWRITES: Record<string, string> = {\n className: 'class',\n htmlFor: 'for',\n}\n\n// ═══════════════════════════════════════════════════════════════════════════════\n// Detection (diagnostic-only, no modifications)\n// ═══════════════════════════════════════════════════════════════════════════════\n\ninterface DetectContext {\n sf: ts.SourceFile\n code: string\n diagnostics: ReactDiagnostic[]\n reactImportedHooks: Set<string>\n}\n\nfunction detectGetNodeText(ctx: DetectContext, node: ts.Node): string {\n return ctx.code.slice(node.getStart(ctx.sf), node.getEnd())\n}\n\nfunction detectDiag(\n ctx: DetectContext,\n node: ts.Node,\n diagCode: ReactDiagnosticCode,\n message: string,\n current: string,\n suggested: string,\n fixable: boolean,\n): void {\n const { line, character } = ctx.sf.getLineAndCharacterOfPosition(node.getStart(ctx.sf))\n ctx.diagnostics.push({\n code: diagCode,\n message,\n line: line + 1,\n column: character,\n current: current.trim(),\n suggested: suggested.trim(),\n fixable,\n })\n}\n\nfunction detectImportDeclaration(ctx: DetectContext, node: ts.ImportDeclaration): void {\n if (!node.moduleSpecifier) return\n const source = (node.moduleSpecifier as ts.StringLiteral).text\n const pyreonSource = IMPORT_REWRITES[source]\n\n if (pyreonSource !== undefined) {\n if (node.importClause?.namedBindings && ts.isNamedImports(node.importClause.namedBindings)) {\n for (const spec of node.importClause.namedBindings.elements) {\n ctx.reactImportedHooks.add(spec.name.text)\n }\n }\n\n const diagCode = source.startsWith('react-router')\n ? 'react-router-import'\n : source.startsWith('react-dom')\n ? 'react-dom-import'\n : 'react-import'\n\n detectDiag(\n ctx,\n node,\n diagCode,\n `Import from '${source}' is a React package. Use Pyreon equivalent.`,\n detectGetNodeText(ctx, node),\n pyreonSource\n ? `import { ... } from \"${pyreonSource}\"`\n : 'Remove this import — not needed in Pyreon',\n true,\n )\n }\n}\n\nfunction detectUseState(ctx: DetectContext, node: ts.CallExpression): void {\n const parent = node.parent\n if (\n ts.isVariableDeclaration(parent) &&\n parent.name &&\n ts.isArrayBindingPattern(parent.name) &&\n parent.name.elements.length >= 1\n ) {\n const firstEl = parent.name.elements[0]\n const valueName =\n firstEl && ts.isBindingElement(firstEl) ? (firstEl.name as ts.Identifier).text : 'value'\n const initArg = node.arguments[0] ? detectGetNodeText(ctx, node.arguments[0]) : 'undefined'\n\n detectDiag(\n ctx,\n node,\n 'use-state',\n `useState is a React API. In Pyreon, use signal(). Read: ${valueName}(), Write: ${valueName}.set(x)`,\n detectGetNodeText(ctx, parent),\n `${valueName} = signal(${initArg})`,\n true,\n )\n } else {\n detectDiag(\n ctx,\n node,\n 'use-state',\n 'useState is a React API. In Pyreon, use signal().',\n detectGetNodeText(ctx, node),\n 'signal(initialValue)',\n true,\n )\n }\n}\n\nfunction callbackHasCleanup(callbackArg: ts.Expression): boolean {\n if (!ts.isArrowFunction(callbackArg) && !ts.isFunctionExpression(callbackArg)) return false\n const body = callbackArg.body\n if (!ts.isBlock(body)) return false\n for (const stmt of body.statements) {\n if (ts.isReturnStatement(stmt) && stmt.expression) return true\n }\n return false\n}\n\nfunction detectUseEffect(ctx: DetectContext, node: ts.CallExpression): void {\n const hookName = (node.expression as ts.Identifier).text\n const depsArg = node.arguments[1]\n const callbackArg = node.arguments[0]\n\n if (depsArg && ts.isArrayLiteralExpression(depsArg) && depsArg.elements.length === 0) {\n const hasCleanup = callbackArg ? callbackHasCleanup(callbackArg) : false\n\n detectDiag(\n ctx,\n node,\n 'use-effect-mount',\n `${hookName} with empty deps [] means \"run once on mount\". Use onMount() in Pyreon.`,\n detectGetNodeText(ctx, node),\n hasCleanup\n ? 'onMount(() => {\\n // setup...\\n return () => { /* cleanup */ }\\n})'\n : 'onMount(() => {\\n // setup...\\n})',\n true,\n )\n } else if (depsArg && ts.isArrayLiteralExpression(depsArg)) {\n detectDiag(\n ctx,\n node,\n 'use-effect-deps',\n `${hookName} with dependency array. In Pyreon, effect() auto-tracks dependencies — no array needed.`,\n detectGetNodeText(ctx, node),\n 'effect(() => {\\n // reads are auto-tracked\\n})',\n true,\n )\n } else if (!depsArg) {\n detectDiag(\n ctx,\n node,\n 'use-effect-no-deps',\n `${hookName} with no dependency array. In Pyreon, use effect() — it auto-tracks signal reads.`,\n detectGetNodeText(ctx, node),\n 'effect(() => {\\n // runs when accessed signals change\\n})',\n true,\n )\n }\n}\n\nfunction detectUseMemo(ctx: DetectContext, node: ts.CallExpression): void {\n const computeFn = node.arguments[0]\n const computeText = computeFn ? detectGetNodeText(ctx, computeFn) : '() => value'\n\n detectDiag(\n ctx,\n node,\n 'use-memo',\n 'useMemo is a React API. In Pyreon, use computed() — dependencies auto-tracked.',\n detectGetNodeText(ctx, node),\n `computed(${computeText})`,\n true,\n )\n}\n\nfunction detectUseCallback(ctx: DetectContext, node: ts.CallExpression): void {\n const callbackFn = node.arguments[0]\n const callbackText = callbackFn ? detectGetNodeText(ctx, callbackFn) : '() => {}'\n\n detectDiag(\n ctx,\n node,\n 'use-callback',\n 'useCallback is not needed in Pyreon. Components run once, so closures never go stale. Use a plain function.',\n detectGetNodeText(ctx, node),\n callbackText,\n true,\n )\n}\n\nfunction detectUseRef(ctx: DetectContext, node: ts.CallExpression): void {\n const arg = node.arguments[0]\n const isNullInit =\n arg &&\n (arg.kind === ts.SyntaxKind.NullKeyword || (ts.isIdentifier(arg) && arg.text === 'undefined'))\n\n if (isNullInit) {\n detectDiag(\n ctx,\n node,\n 'use-ref-dom',\n 'useRef(null) for DOM refs. In Pyreon, use createRef() from @pyreon/core.',\n detectGetNodeText(ctx, node),\n 'createRef()',\n true,\n )\n } else {\n const initText = arg ? detectGetNodeText(ctx, arg) : 'undefined'\n detectDiag(\n ctx,\n node,\n 'use-ref-box',\n 'useRef for mutable values. In Pyreon, use signal() — it works the same way but is reactive.',\n detectGetNodeText(ctx, node),\n `signal(${initText})`,\n true,\n )\n }\n}\n\nfunction detectUseReducer(ctx: DetectContext, node: ts.CallExpression): void {\n detectDiag(\n ctx,\n node,\n 'use-reducer',\n 'useReducer is a React API. In Pyreon, use signal() with update() for reducer patterns.',\n detectGetNodeText(ctx, node),\n 'const state = signal(initialState)\\nconst dispatch = (action) => state.update(s => reducer(s, action))',\n false,\n )\n}\n\nfunction isCallToReactDot(callee: ts.Expression, methodName: string): boolean {\n return (\n ts.isPropertyAccessExpression(callee) &&\n ts.isIdentifier(callee.expression) &&\n callee.expression.text === 'React' &&\n callee.name.text === methodName\n )\n}\n\nfunction detectMemoWrapper(ctx: DetectContext, node: ts.CallExpression): void {\n const callee = node.expression\n const isMemo =\n (ts.isIdentifier(callee) && callee.text === 'memo') || isCallToReactDot(callee, 'memo')\n\n if (isMemo) {\n const inner = node.arguments[0]\n const innerText = inner ? detectGetNodeText(ctx, inner) : 'Component'\n\n detectDiag(\n ctx,\n node,\n 'memo-wrapper',\n 'memo() is not needed in Pyreon. Components run once — only signals trigger updates, not re-renders.',\n detectGetNodeText(ctx, node),\n innerText,\n true,\n )\n }\n}\n\nfunction detectForwardRef(ctx: DetectContext, node: ts.CallExpression): void {\n const callee = node.expression\n const isForwardRef =\n (ts.isIdentifier(callee) && callee.text === 'forwardRef') ||\n isCallToReactDot(callee, 'forwardRef')\n\n if (isForwardRef) {\n detectDiag(\n ctx,\n node,\n 'forward-ref',\n 'forwardRef is not needed in Pyreon. Pass ref as a regular prop.',\n detectGetNodeText(ctx, node),\n '// Just pass ref as a prop:\\nconst MyInput = (props) => <input ref={props.ref} />',\n true,\n )\n }\n}\n\nfunction detectJsxAttributes(ctx: DetectContext, node: ts.JsxAttribute): void {\n const attrName = (node.name as ts.Identifier).text\n\n if (attrName in JSX_ATTR_REWRITES) {\n const htmlAttr = JSX_ATTR_REWRITES[attrName] as string\n detectDiag(\n ctx,\n node,\n attrName === 'className' ? 'class-name-prop' : 'html-for-prop',\n `'${attrName}' is a React JSX attribute. Use '${htmlAttr}' in Pyreon (standard HTML).`,\n detectGetNodeText(ctx, node),\n detectGetNodeText(ctx, node).replace(attrName, htmlAttr),\n true,\n )\n }\n\n if (attrName === 'onChange') {\n const jsxElement = findParentJsxElement(node)\n if (jsxElement) {\n const tagName = getJsxTagName(jsxElement)\n if (tagName === 'input' || tagName === 'textarea' || tagName === 'select') {\n detectDiag(\n ctx,\n node,\n 'on-change-input',\n `onChange on <${tagName}> fires on blur in Pyreon (native DOM behavior). For keypress-by-keypress updates, use onInput.`,\n detectGetNodeText(ctx, node),\n detectGetNodeText(ctx, node).replace('onChange', 'onInput'),\n true,\n )\n }\n }\n }\n\n if (attrName === 'dangerouslySetInnerHTML') {\n detectDiag(\n ctx,\n node,\n 'dangerously-set-inner-html',\n 'dangerouslySetInnerHTML is React-specific. Use innerHTML prop in Pyreon.',\n detectGetNodeText(ctx, node),\n 'innerHTML={htmlString}',\n true,\n )\n }\n}\n\nfunction detectDotValueSignal(ctx: DetectContext, node: ts.PropertyAccessExpression): void {\n const varName = (node.expression as ts.Identifier).text\n const parent = node.parent\n if (ts.isBinaryExpression(parent) && parent.left === node) {\n detectDiag(\n ctx,\n node,\n 'dot-value-signal',\n `'${varName}.value' looks like a Vue ref pattern. Pyreon signals are callable functions. Use ${varName}.set(x) to write.`,\n detectGetNodeText(ctx, parent),\n `${varName}.set(${detectGetNodeText(ctx, parent.right)})`,\n false,\n )\n }\n}\n\nfunction detectArrayMapJsx(ctx: DetectContext, node: ts.CallExpression): void {\n const parent = node.parent\n if (ts.isJsxExpression(parent)) {\n const arrayExpr = detectGetNodeText(\n ctx,\n (node.expression as ts.PropertyAccessExpression).expression,\n )\n const mapCallback = node.arguments[0]\n const mapCallbackText = mapCallback\n ? detectGetNodeText(ctx, mapCallback)\n : 'item => <li>{item}</li>'\n\n detectDiag(\n ctx,\n node,\n 'array-map-jsx',\n 'Array.map() in JSX is not reactive in Pyreon. Use <For> for efficient keyed list rendering.',\n detectGetNodeText(ctx, node),\n `<For each={${arrayExpr}} by={item => item.id}>\\n {${mapCallbackText}}\\n</For>`,\n false,\n )\n }\n}\n\nfunction isCallToHook(node: ts.Node, hookName: string): node is ts.CallExpression {\n return (\n ts.isCallExpression(node) &&\n ts.isIdentifier(node.expression) &&\n node.expression.text === hookName\n )\n}\n\nfunction isCallToEffectHook(node: ts.Node): node is ts.CallExpression {\n return (\n ts.isCallExpression(node) &&\n ts.isIdentifier(node.expression) &&\n (node.expression.text === 'useEffect' || node.expression.text === 'useLayoutEffect')\n )\n}\n\nfunction isMapCallExpression(node: ts.Node): node is ts.CallExpression {\n return (\n ts.isCallExpression(node) &&\n ts.isPropertyAccessExpression(node.expression) &&\n ts.isIdentifier(node.expression.name) &&\n node.expression.name.text === 'map'\n )\n}\n\nfunction isDotValueAccess(node: ts.Node): node is ts.PropertyAccessExpression {\n return (\n ts.isPropertyAccessExpression(node) &&\n ts.isIdentifier(node.name) &&\n node.name.text === 'value' &&\n ts.isIdentifier(node.expression)\n )\n}\n\nfunction detectVisitNode(ctx: DetectContext, node: ts.Node): void {\n if (ts.isImportDeclaration(node)) detectImportDeclaration(ctx, node)\n if (isCallToHook(node, 'useState')) detectUseState(ctx, node)\n if (isCallToEffectHook(node)) detectUseEffect(ctx, node)\n if (isCallToHook(node, 'useMemo')) detectUseMemo(ctx, node)\n if (isCallToHook(node, 'useCallback')) detectUseCallback(ctx, node)\n if (isCallToHook(node, 'useRef')) detectUseRef(ctx, node)\n if (isCallToHook(node, 'useReducer')) detectUseReducer(ctx, node)\n if (ts.isCallExpression(node)) detectMemoWrapper(ctx, node)\n if (ts.isCallExpression(node)) detectForwardRef(ctx, node)\n if (ts.isJsxAttribute(node) && ts.isIdentifier(node.name)) detectJsxAttributes(ctx, node)\n if (isDotValueAccess(node)) detectDotValueSignal(ctx, node)\n if (isMapCallExpression(node)) detectArrayMapJsx(ctx, node)\n}\n\nfunction detectVisit(ctx: DetectContext, node: ts.Node): void {\n ts.forEachChild(node, (child) => {\n detectVisitNode(ctx, child)\n detectVisit(ctx, child)\n })\n}\n\nexport function detectReactPatterns(code: string, filename = 'input.tsx'): ReactDiagnostic[] {\n const sf = ts.createSourceFile(filename, code, ts.ScriptTarget.ESNext, true, ts.ScriptKind.TSX)\n const ctx: DetectContext = {\n sf,\n code,\n diagnostics: [],\n reactImportedHooks: new Set<string>(),\n }\n\n detectVisit(ctx, sf)\n return ctx.diagnostics\n}\n\n// ═══════════════════════════════════════════════════════════════════════════════\n// Migration (detection + auto-fix)\n// ═══════════════════════════════════════════════════════════════════════════════\n\ntype Replacement = { start: number; end: number; text: string }\n\ninterface MigrateContext {\n sf: ts.SourceFile\n code: string\n replacements: Replacement[]\n changes: MigrationChange[]\n pyreonImports: Map<string, Set<string>>\n importsToRemove: Set<ts.ImportDeclaration>\n specifierRewrites: Map<ts.ImportSpecifier, { name: string; from: string }>\n}\n\nfunction migrateAddImport(ctx: MigrateContext, source: string, specifier: string): void {\n if (!source || !specifier) return\n let specs = ctx.pyreonImports.get(source)\n if (!specs) {\n specs = new Set()\n ctx.pyreonImports.set(source, specs)\n }\n specs.add(specifier)\n}\n\nfunction migrateReplace(ctx: MigrateContext, node: ts.Node, text: string): void {\n ctx.replacements.push({ start: node.getStart(ctx.sf), end: node.getEnd(), text })\n}\n\nfunction migrateGetNodeText(ctx: MigrateContext, node: ts.Node): string {\n return ctx.code.slice(node.getStart(ctx.sf), node.getEnd())\n}\n\nfunction migrateGetLine(ctx: MigrateContext, node: ts.Node): number {\n return ctx.sf.getLineAndCharacterOfPosition(node.getStart(ctx.sf)).line + 1\n}\n\nfunction migrateImportDeclaration(ctx: MigrateContext, node: ts.ImportDeclaration): void {\n if (!node.moduleSpecifier) return\n const source = (node.moduleSpecifier as ts.StringLiteral).text\n if (!(source in IMPORT_REWRITES)) return\n\n if (node.importClause?.namedBindings && ts.isNamedImports(node.importClause.namedBindings)) {\n for (const spec of node.importClause.namedBindings.elements) {\n const name = spec.name.text\n const rewrite = SPECIFIER_REWRITES[name]\n if (rewrite) {\n if (rewrite.name) {\n migrateAddImport(ctx, rewrite.from, rewrite.name)\n }\n ctx.specifierRewrites.set(spec, rewrite)\n }\n }\n }\n ctx.importsToRemove.add(node)\n}\n\nfunction migrateUseState(ctx: MigrateContext, node: ts.CallExpression): void {\n const parent = node.parent\n if (\n ts.isVariableDeclaration(parent) &&\n parent.name &&\n ts.isArrayBindingPattern(parent.name) &&\n parent.name.elements.length >= 1\n ) {\n const firstEl = parent.name.elements[0]\n const valueName =\n firstEl && ts.isBindingElement(firstEl) ? (firstEl.name as ts.Identifier).text : 'value'\n const initArg = node.arguments[0] ? migrateGetNodeText(ctx, node.arguments[0]) : 'undefined'\n\n const declStart = parent.getStart(ctx.sf)\n const declEnd = parent.getEnd()\n ctx.replacements.push({\n start: declStart,\n end: declEnd,\n text: `${valueName} = signal(${initArg})`,\n })\n migrateAddImport(ctx, '@pyreon/reactivity', 'signal')\n ctx.changes.push({\n type: 'replace',\n line: migrateGetLine(ctx, node),\n description: `useState → signal: ${valueName}`,\n })\n }\n}\n\nfunction migrateUseEffect(ctx: MigrateContext, node: ts.CallExpression): void {\n const depsArg = node.arguments[1]\n const callbackArg = node.arguments[0]\n const hookName = (node.expression as ts.Identifier).text\n\n if (\n depsArg &&\n ts.isArrayLiteralExpression(depsArg) &&\n depsArg.elements.length === 0 &&\n callbackArg\n ) {\n const callbackText = migrateGetNodeText(ctx, callbackArg)\n migrateReplace(ctx, node, `onMount(${callbackText})`)\n migrateAddImport(ctx, '@pyreon/core', 'onMount')\n ctx.changes.push({\n type: 'replace',\n line: migrateGetLine(ctx, node),\n description: `${hookName}(fn, []) → onMount(fn)`,\n })\n } else if (callbackArg) {\n const callbackText = migrateGetNodeText(ctx, callbackArg)\n migrateReplace(ctx, node, `effect(${callbackText})`)\n migrateAddImport(ctx, '@pyreon/reactivity', 'effect')\n ctx.changes.push({\n type: 'replace',\n line: migrateGetLine(ctx, node),\n description: `${hookName} → effect (auto-tracks deps)`,\n })\n }\n}\n\nfunction migrateUseMemo(ctx: MigrateContext, node: ts.CallExpression): void {\n const computeFn = node.arguments[0]\n if (computeFn) {\n migrateReplace(ctx, node, `computed(${migrateGetNodeText(ctx, computeFn)})`)\n migrateAddImport(ctx, '@pyreon/reactivity', 'computed')\n ctx.changes.push({\n type: 'replace',\n line: migrateGetLine(ctx, node),\n description: 'useMemo → computed (auto-tracks deps)',\n })\n }\n}\n\nfunction migrateUseCallback(ctx: MigrateContext, node: ts.CallExpression): void {\n const callbackFn = node.arguments[0]\n if (callbackFn) {\n migrateReplace(ctx, node, migrateGetNodeText(ctx, callbackFn))\n ctx.changes.push({\n type: 'replace',\n line: migrateGetLine(ctx, node),\n description: 'useCallback → plain function (not needed in Pyreon)',\n })\n }\n}\n\nfunction migrateUseRef(ctx: MigrateContext, node: ts.CallExpression): void {\n const arg = node.arguments[0]\n const isNullInit =\n arg &&\n (arg.kind === ts.SyntaxKind.NullKeyword || (ts.isIdentifier(arg) && arg.text === 'undefined'))\n\n if (isNullInit || !arg) {\n migrateReplace(ctx, node, 'createRef()')\n migrateAddImport(ctx, '@pyreon/core', 'createRef')\n ctx.changes.push({\n type: 'replace',\n line: migrateGetLine(ctx, node),\n description: 'useRef(null) → createRef()',\n })\n } else {\n migrateReplace(ctx, node, `signal(${migrateGetNodeText(ctx, arg)})`)\n migrateAddImport(ctx, '@pyreon/reactivity', 'signal')\n ctx.changes.push({\n type: 'replace',\n line: migrateGetLine(ctx, node),\n description: 'useRef(value) → signal(value)',\n })\n }\n}\n\nfunction migrateMemoWrapper(ctx: MigrateContext, node: ts.CallExpression): void {\n const callee = node.expression\n const isMemo =\n (ts.isIdentifier(callee) && callee.text === 'memo') || isCallToReactDot(callee, 'memo')\n\n if (isMemo && node.arguments[0]) {\n migrateReplace(ctx, node, migrateGetNodeText(ctx, node.arguments[0]))\n ctx.changes.push({\n type: 'remove',\n line: migrateGetLine(ctx, node),\n description: 'Removed memo() wrapper (not needed in Pyreon)',\n })\n }\n}\n\nfunction migrateForwardRef(ctx: MigrateContext, node: ts.CallExpression): void {\n const callee = node.expression\n const isForwardRef =\n (ts.isIdentifier(callee) && callee.text === 'forwardRef') ||\n isCallToReactDot(callee, 'forwardRef')\n\n if (isForwardRef && node.arguments[0]) {\n migrateReplace(ctx, node, migrateGetNodeText(ctx, node.arguments[0]))\n ctx.changes.push({\n type: 'remove',\n line: migrateGetLine(ctx, node),\n description: 'Removed forwardRef wrapper (pass ref as normal prop in Pyreon)',\n })\n }\n}\n\nfunction migrateJsxAttributes(ctx: MigrateContext, node: ts.JsxAttribute): void {\n const attrName = (node.name as ts.Identifier).text\n\n if (attrName in JSX_ATTR_REWRITES) {\n const htmlAttr = JSX_ATTR_REWRITES[attrName] as string\n ctx.replacements.push({\n start: node.name.getStart(ctx.sf),\n end: node.name.getEnd(),\n text: htmlAttr,\n })\n ctx.changes.push({\n type: 'replace',\n line: migrateGetLine(ctx, node),\n description: `${attrName} → ${htmlAttr}`,\n })\n }\n\n if (attrName === 'onChange') {\n const jsxElement = findParentJsxElement(node)\n if (jsxElement) {\n const tagName = getJsxTagName(jsxElement)\n if (tagName === 'input' || tagName === 'textarea' || tagName === 'select') {\n ctx.replacements.push({\n start: node.name.getStart(ctx.sf),\n end: node.name.getEnd(),\n text: 'onInput',\n })\n ctx.changes.push({\n type: 'replace',\n line: migrateGetLine(ctx, node),\n description: `onChange on <${tagName}> → onInput (native DOM events)`,\n })\n }\n }\n }\n\n if (attrName === 'dangerouslySetInnerHTML') {\n migrateDangerouslySetInnerHTML(ctx, node)\n }\n}\n\nfunction migrateDangerouslySetInnerHTML(ctx: MigrateContext, node: ts.JsxAttribute): void {\n if (!node.initializer || !ts.isJsxExpression(node.initializer) || !node.initializer.expression) {\n return\n }\n const expr = node.initializer.expression\n if (!ts.isObjectLiteralExpression(expr)) return\n\n const htmlProp = expr.properties.find(\n (p) => ts.isPropertyAssignment(p) && ts.isIdentifier(p.name) && p.name.text === '__html',\n ) as ts.PropertyAssignment | undefined\n\n if (htmlProp) {\n const valueText = migrateGetNodeText(ctx, htmlProp.initializer)\n migrateReplace(ctx, node, `innerHTML={${valueText}}`)\n ctx.changes.push({\n type: 'replace',\n line: migrateGetLine(ctx, node),\n description: 'dangerouslySetInnerHTML → innerHTML',\n })\n }\n}\n\nfunction applyReplacements(code: string, ctx: MigrateContext): string {\n // Remove React import declarations\n for (const imp of ctx.importsToRemove) {\n ctx.replacements.push({ start: imp.getStart(ctx.sf), end: imp.getEnd(), text: '' })\n ctx.changes.push({\n type: 'remove',\n line: ctx.sf.getLineAndCharacterOfPosition(imp.getStart(ctx.sf)).line + 1,\n description: 'Removed React import',\n })\n }\n\n // Sort descending for dedup (outermost replacements win over inner overlapping ones)\n ctx.replacements.sort((a, b) => b.start - a.start)\n\n // Deduplicate overlapping replacements (keep the outermost / first added)\n const applied = new Set<string>()\n const deduped: Replacement[] = []\n for (const r of ctx.replacements) {\n const key = `${r.start}:${r.end}`\n let overlaps = false\n for (const d of deduped) {\n if (r.start < d.end && r.end > d.start) {\n overlaps = true\n break\n }\n }\n if (!overlaps && !applied.has(key)) {\n applied.add(key)\n deduped.push(r)\n }\n }\n\n // Re-sort ascending for string builder — O(n) single join\n deduped.sort((a, b) => a.start - b.start)\n const parts: string[] = []\n let lastPos = 0\n for (const r of deduped) {\n parts.push(code.slice(lastPos, r.start))\n parts.push(r.text)\n lastPos = r.end\n }\n parts.push(code.slice(lastPos))\n return parts.join('')\n}\n\nfunction insertPyreonImports(code: string, pyreonImports: Map<string, Set<string>>): string {\n if (pyreonImports.size === 0) return code\n\n const importLines: string[] = []\n const sorted = [...pyreonImports.entries()].sort(([a], [b]) => a.localeCompare(b))\n for (const [source, specs] of sorted) {\n const specList = [...specs].sort().join(', ')\n importLines.push(`import { ${specList} } from \"${source}\"`)\n }\n const importBlock = importLines.join('\\n')\n\n const lastImportEnd = findLastImportEnd(code)\n if (lastImportEnd > 0) {\n return `${code.slice(0, lastImportEnd)}\\n${importBlock}${code.slice(lastImportEnd)}`\n }\n return `${importBlock}\\n\\n${code}`\n}\n\nfunction migrateVisitNode(ctx: MigrateContext, node: ts.Node): void {\n if (ts.isImportDeclaration(node)) migrateImportDeclaration(ctx, node)\n if (isCallToHook(node, 'useState')) migrateUseState(ctx, node)\n if (isCallToEffectHook(node)) migrateUseEffect(ctx, node)\n if (isCallToHook(node, 'useMemo')) migrateUseMemo(ctx, node)\n if (isCallToHook(node, 'useCallback')) migrateUseCallback(ctx, node)\n if (isCallToHook(node, 'useRef')) migrateUseRef(ctx, node)\n if (ts.isCallExpression(node)) migrateMemoWrapper(ctx, node)\n if (ts.isCallExpression(node)) migrateForwardRef(ctx, node)\n if (ts.isJsxAttribute(node) && ts.isIdentifier(node.name)) migrateJsxAttributes(ctx, node)\n}\n\nfunction migrateVisit(ctx: MigrateContext, node: ts.Node): void {\n ts.forEachChild(node, (child) => {\n migrateVisitNode(ctx, child)\n migrateVisit(ctx, child)\n })\n}\n\nexport function migrateReactCode(code: string, filename = 'input.tsx'): MigrationResult {\n const sf = ts.createSourceFile(filename, code, ts.ScriptTarget.ESNext, true, ts.ScriptKind.TSX)\n const diagnostics = detectReactPatterns(code, filename)\n\n const ctx: MigrateContext = {\n sf,\n code,\n replacements: [],\n changes: [],\n pyreonImports: new Map(),\n importsToRemove: new Set(),\n specifierRewrites: new Map(),\n }\n\n migrateVisit(ctx, sf)\n\n let result = applyReplacements(code, ctx)\n result = insertPyreonImports(result, ctx.pyreonImports)\n\n // Clean up empty lines from removed imports\n result = result.replace(/\\n{3,}/g, '\\n\\n')\n\n return { code: result, diagnostics, changes: ctx.changes }\n}\n\n// ═══════════════════════════════════════════════════════════════════════════════\n// Helpers\n// ═══════════════════════════════════════════════════════════════════════════════\n\nfunction findParentJsxElement(\n node: ts.Node,\n): ts.JsxOpeningElement | ts.JsxSelfClosingElement | null {\n let current = node.parent\n while (current) {\n if (ts.isJsxOpeningElement(current) || ts.isJsxSelfClosingElement(current)) {\n return current\n }\n // Don't cross component boundaries\n if (ts.isJsxElement(current)) {\n return current.openingElement\n }\n if (ts.isArrowFunction(current) || ts.isFunctionExpression(current)) {\n return null\n }\n current = current.parent\n }\n return null\n}\n\nfunction getJsxTagName(node: ts.JsxOpeningElement | ts.JsxSelfClosingElement): string {\n const tagName = node.tagName\n if (ts.isIdentifier(tagName)) {\n return tagName.text\n }\n return ''\n}\n\nfunction findLastImportEnd(code: string): number {\n const importRe = /^import\\s.+$/gm\n let lastEnd = 0\n let match: RegExpExecArray | null\n while (true) {\n match = importRe.exec(code)\n if (!match) break\n lastEnd = match.index + match[0].length\n }\n return lastEnd\n}\n\n// ═══════════════════════════════════════════════════════════════════════════════\n// Quick scan (regex-based, for fast pre-filtering)\n// ═══════════════════════════════════════════════════════════════════════════════\n\n/** Fast regex check — returns true if code likely contains React patterns worth analyzing */\nexport function hasReactPatterns(code: string): boolean {\n return (\n /\\bfrom\\s+['\"]react/.test(code) ||\n /\\bfrom\\s+['\"]react-dom/.test(code) ||\n /\\bfrom\\s+['\"]react-router/.test(code) ||\n /\\buseState\\s*[<(]/.test(code) ||\n /\\buseEffect\\s*\\(/.test(code) ||\n /\\buseMemo\\s*\\(/.test(code) ||\n /\\buseCallback\\s*\\(/.test(code) ||\n /\\buseRef\\s*[<(]/.test(code) ||\n /\\buseReducer\\s*[<(]/.test(code) ||\n /\\bReact\\.memo\\b/.test(code) ||\n /\\bforwardRef\\s*[<(]/.test(code) ||\n /\\bclassName[=\\s]/.test(code) ||\n /\\bhtmlFor[=\\s]/.test(code) ||\n /\\.value\\s*=/.test(code)\n )\n}\n\n// ═══════════════════════════════════════════════════════════════════════════════\n// Error pattern database (for MCP diagnose tool)\n// ═══════════════════════════════════════════════════════════════════════════════\n\nexport interface ErrorDiagnosis {\n cause: string\n fix: string\n fixCode?: string | undefined\n related?: string | undefined\n}\n\ninterface ErrorPattern {\n pattern: RegExp\n diagnose: (match: RegExpMatchArray) => ErrorDiagnosis\n}\n\nconst ERROR_PATTERNS: ErrorPattern[] = [\n {\n pattern: /Cannot read properties of undefined \\(reading '(set|update|peek|subscribe)'\\)/,\n diagnose: (m) => ({\n cause: `Calling .${m[1]}() on undefined. The signal variable is likely out of scope, misspelled, or not yet initialized.`,\n fix: 'Check that the signal is defined and in scope. Signals must be created with signal() before use.',\n fixCode: `const mySignal = signal(initialValue)\\nmySignal.${m[1]}(newValue)`,\n }),\n },\n {\n pattern: /(\\w+) is not a function/,\n diagnose: (m) => ({\n cause: `'${m[1]}' is not callable. If this is a signal, you need to call it: ${m[1]}()`,\n fix: 'Pyreon signals are callable functions. Read: signal(), Write: signal.set(value)',\n fixCode: `// Read value:\\nconst value = ${m[1]}()\\n// Set value:\\n${m[1]}.set(newValue)`,\n }),\n },\n {\n pattern: /Cannot find module '(@pyreon\\/\\w[\\w-]*)'/,\n diagnose: (m) => ({\n cause: `Package ${m[1]} is not installed.`,\n fix: `Run: bun add ${m[1]}`,\n fixCode: `bun add ${m[1]}`,\n }),\n },\n {\n pattern: /Cannot find module 'react'/,\n diagnose: () => ({\n cause: \"Importing from 'react' in a Pyreon project.\",\n fix: 'Replace React imports with Pyreon equivalents.',\n fixCode:\n '// Instead of:\\nimport { useState } from \"react\"\\n// Use:\\nimport { signal } from \"@pyreon/reactivity\"',\n }),\n },\n {\n pattern: /Property '(\\w+)' does not exist on type 'Signal<\\w+>'/,\n diagnose: (m) => ({\n cause: `Accessing .${m[1]} on a signal. Pyreon signals don't have a .${m[1]} property.`,\n fix:\n m[1] === 'value'\n ? 'Pyreon signals are callable functions, not .value getters. Call signal() to read, signal.set() to write.'\n : `Signals have these methods: .set(), .update(), .peek(), .subscribe(). '${m[1]}' is not one of them.`,\n fixCode:\n m[1] === 'value' ? '// Read: mySignal()\\n// Write: mySignal.set(newValue)' : undefined,\n }),\n },\n {\n pattern: /Type '(\\w+)' is not assignable to type 'VNode'/,\n diagnose: (m) => ({\n cause: `Component returned ${m[1]} instead of VNode. Components must return JSX, null, or a string.`,\n fix: 'Make sure your component returns a JSX element, null, or a string.',\n fixCode: 'const MyComponent = (props) => {\\n return <div>{props.children}</div>\\n}',\n }),\n },\n {\n pattern: /onMount callback must return/,\n diagnose: () => ({\n cause: 'onMount expects a callback that optionally returns a CleanupFn.',\n fix: 'Return a cleanup function, or return nothing.',\n fixCode: 'onMount(() => {\\n // setup code\\n})',\n }),\n },\n {\n pattern: /Expected 'by' prop on <For>/,\n diagnose: () => ({\n cause: \"<For> requires a 'by' prop for efficient keyed reconciliation.\",\n fix: 'Add a by prop that returns a unique key for each item.',\n fixCode:\n '<For each={items()} by={item => item.id}>\\n {item => <li>{item.name}</li>}\\n</For>',\n }),\n },\n {\n pattern: /useHook.*outside.*component/i,\n diagnose: () => ({\n cause:\n 'Hook called outside a component function. Pyreon hooks must be called during component setup.',\n fix: 'Move the hook call inside a component function body.',\n }),\n },\n {\n pattern: /Hydration mismatch/,\n diagnose: () => ({\n cause: \"Server-rendered HTML doesn't match client-rendered output.\",\n fix: 'Ensure SSR and client render the same initial content. Check for browser-only APIs (window, document) in SSR code.',\n related: \"Use typeof window !== 'undefined' checks or onMount() for client-only code.\",\n }),\n },\n]\n\n/** Diagnose an error message and return structured fix information */\nexport function diagnoseError(error: string): ErrorDiagnosis | null {\n for (const { pattern, diagnose } of ERROR_PATTERNS) {\n const match = error.match(pattern)\n if (match) {\n return diagnose(match)\n }\n }\n return null\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0DA,MAAM,aAAa,IAAI,IAAI,CAAC,OAAO,MAAM,CAAC;AAE1C,MAAM,WAAW;AAEjB,MAAM,mBAAmB,IAAI,IAAI;CAC/B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;AAEF,SAAgB,aAAa,MAAc,WAAW,aAA8B;CAClF,MAAM,aACJ,SAAS,SAAS,OAAO,IAAI,SAAS,SAAS,OAAO,GAAG,GAAG,WAAW,MAAM,GAAG,WAAW;CAE7F,MAAM,KAAK,GAAG,iBACZ,UACA,MACA,GAAG,aAAa,QACK,MACrB,WACD;CAGD,MAAM,eAA8B,EAAE;CACtC,MAAM,WAA8B,EAAE;CAEtC,SAAS,KAAK,MAAe,SAAiB,UAAyC;EACrF,MAAM,EAAE,MAAM,cAAc,GAAG,8BAA8B,KAAK,SAAS,GAAG,CAAC;AAC/E,WAAS,KAAK;GAAE;GAAS,MAAM,OAAO;GAAG,QAAQ;GAAW,MAAM;GAAU,CAAC;;CAK/E,MAAM,SAAkB,EAAE;CAC1B,IAAI,WAAW;CACf,IAAI,iBAAiB;CACrB,IAAI,gBAAgB;CACpB,IAAI,4BAA4B;CAChC,IAAI,8BAA8B;CAClC,IAAI,wBAAwB;CAC5B,IAAI,8BAA8B;;;;;CAMlC,SAAS,WAAW,MAA8B;AAChD,OACG,GAAG,aAAa,KAAK,IAAI,GAAG,wBAAwB,KAAK,IAAI,GAAG,cAAc,KAAK,KACpF,gBAAgB,KAAkE,EAClF;GACA,MAAM,OAAO,MAAM;GACn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ACE,SAAS;EACT,WAAW,OAAO;GAChB,OAAO,sBAAsB,EAAE,GAAG;GAClC,KAAK;GACL,SAAS;GACV;EACF;CACD;EACE,SAAS;EACT,iBAAiB;GACf,OAAO;GACP,KAAK;GACL,SAAS;GACV;EACF;CACD;EACE,SAAS;EACT,iBAAiB;GACf,OAAO;GACP,KAAK;GACL,SACE;GACH;EACF;CACD;EACE,SAAS;EACT,iBAAiB;GACf,OACE;GACF,KAAK;GACN;EACF;CACD;EACE,SAAS;EACT,iBAAiB;GACf,OAAO;GACP,KAAK;GACL,SAAS;GACV;EACF;CACF;;AAGD,SAAgB,cAAc,OAAsC;AAClE,MAAK,MAAM,EAAE,SAAS,cAAc,gBAAgB;EAClD,MAAM,QAAQ,MAAM,MAAM,QAAQ;AAClC,MAAI,MACF,QAAO,SAAS,MAAM;;AAG1B,QAAO"}
|
package/package.json
CHANGED
package/src/jsx.ts
CHANGED
|
@@ -116,6 +116,7 @@ export function transformJSX(code: string, filename = 'input.tsx'): TransformRes
|
|
|
116
116
|
let needsBindTextImportGlobal = false
|
|
117
117
|
let needsBindDirectImportGlobal = false
|
|
118
118
|
let needsBindImportGlobal = false
|
|
119
|
+
let needsApplyPropsImportGlobal = false
|
|
119
120
|
|
|
120
121
|
/**
|
|
121
122
|
* If `node` is a fully-static JSX element/fragment, register a module-scope
|
|
@@ -154,7 +155,7 @@ export function transformJSX(code: string, filename = 'input.tsx'): TransformRes
|
|
|
154
155
|
|
|
155
156
|
/** Try to emit a template for a JsxElement. Returns true if handled. */
|
|
156
157
|
function tryTemplateEmit(node: ts.JsxElement): boolean {
|
|
157
|
-
const elemCount = templateElementCount(node)
|
|
158
|
+
const elemCount = templateElementCount(node, /* isRoot */ true)
|
|
158
159
|
if (elemCount < 1) return false
|
|
159
160
|
const tplCall = buildTemplateCall(node)
|
|
160
161
|
if (!tplCall) return false
|
|
@@ -296,6 +297,7 @@ export function transformJSX(code: string, filename = 'input.tsx'): TransformRes
|
|
|
296
297
|
const runtimeDomImports = ['_tpl']
|
|
297
298
|
if (needsBindDirectImportGlobal) runtimeDomImports.push('_bindDirect')
|
|
298
299
|
if (needsBindTextImportGlobal) runtimeDomImports.push('_bindText')
|
|
300
|
+
if (needsApplyPropsImportGlobal) runtimeDomImports.push('_applyProps')
|
|
299
301
|
const reactivityImports = needsBindImportGlobal
|
|
300
302
|
? `\nimport { _bind } from "@pyreon/reactivity";`
|
|
301
303
|
: ''
|
|
@@ -313,10 +315,19 @@ export function transformJSX(code: string, filename = 'input.tsx'): TransformRes
|
|
|
313
315
|
|
|
314
316
|
// ── Template emission helpers (closures over sf, code) ──────────────────────
|
|
315
317
|
|
|
316
|
-
/**
|
|
317
|
-
|
|
318
|
+
/**
|
|
319
|
+
* Check if attributes prevent template emission.
|
|
320
|
+
* - `key` always bails (VNode reconciliation prop)
|
|
321
|
+
* - Spread on inner elements bails (too complex to merge in _bind)
|
|
322
|
+
* - Spread on root element is allowed — applied via applyProps in _bind
|
|
323
|
+
*/
|
|
324
|
+
function hasBailAttr(node: ts.JsxElement | ts.JsxSelfClosingElement, isRoot = false): boolean {
|
|
318
325
|
for (const attr of jsxAttrs(node)) {
|
|
319
|
-
if (ts.isJsxSpreadAttribute(attr))
|
|
326
|
+
if (ts.isJsxSpreadAttribute(attr)) {
|
|
327
|
+
// Allow spread on root element — handled in buildTemplateCall
|
|
328
|
+
if (isRoot) continue
|
|
329
|
+
return true
|
|
330
|
+
}
|
|
320
331
|
if (ts.isJsxAttribute(attr) && ts.isIdentifier(attr.name) && attr.name.text === 'key')
|
|
321
332
|
return true
|
|
322
333
|
}
|
|
@@ -343,10 +354,13 @@ export function transformJSX(code: string, filename = 'input.tsx'): TransformRes
|
|
|
343
354
|
* Count DOM elements in a JSX subtree. Returns -1 if the tree is not
|
|
344
355
|
* eligible for template emission.
|
|
345
356
|
*/
|
|
346
|
-
function templateElementCount(
|
|
357
|
+
function templateElementCount(
|
|
358
|
+
node: ts.JsxElement | ts.JsxSelfClosingElement,
|
|
359
|
+
isRoot = false,
|
|
360
|
+
): number {
|
|
347
361
|
const tag = jsxTagName(node)
|
|
348
362
|
if (!tag || !isLowerCase(tag)) return -1
|
|
349
|
-
if (hasBailAttr(node)) return -1
|
|
363
|
+
if (hasBailAttr(node, isRoot)) return -1
|
|
350
364
|
if (!ts.isJsxElement(node)) return 1
|
|
351
365
|
|
|
352
366
|
let count = 1
|
|
@@ -382,6 +396,7 @@ export function transformJSX(code: string, filename = 'input.tsx'): TransformRes
|
|
|
382
396
|
const reactiveBindExprs: string[] = []
|
|
383
397
|
let needsBindTextImport = false
|
|
384
398
|
let needsBindDirectImport = false
|
|
399
|
+
let needsApplyPropsImport = false
|
|
385
400
|
|
|
386
401
|
function nextVar(): string {
|
|
387
402
|
return `__e${varIdx++}`
|
|
@@ -559,6 +574,18 @@ export function transformJSX(code: string, filename = 'input.tsx'): TransformRes
|
|
|
559
574
|
|
|
560
575
|
/** Process a single attribute, returning HTML to append. */
|
|
561
576
|
function processOneAttr(attr: ts.JsxAttributeLike, varName: string): string {
|
|
577
|
+
// Spread attribute: apply all props at runtime
|
|
578
|
+
if (ts.isJsxSpreadAttribute(attr)) {
|
|
579
|
+
const expr = sliceExpr(attr.expression)
|
|
580
|
+
// Use runtime-dom's applyProps which handles class, style, events, etc.
|
|
581
|
+
needsApplyPropsImport = true
|
|
582
|
+
if (containsCall(attr.expression)) {
|
|
583
|
+
reactiveBindExprs.push(`_applyProps(${varName}, ${expr})`)
|
|
584
|
+
} else {
|
|
585
|
+
bindLines.push(`_applyProps(${varName}, ${expr})`)
|
|
586
|
+
}
|
|
587
|
+
return ''
|
|
588
|
+
}
|
|
562
589
|
if (!ts.isJsxAttribute(attr)) return ''
|
|
563
590
|
const attrName = ts.isIdentifier(attr.name) ? attr.name.text : ''
|
|
564
591
|
if (attrName === 'key') return ''
|
|
@@ -598,8 +625,11 @@ export function transformJSX(code: string, filename = 'input.tsx'): TransformRes
|
|
|
598
625
|
const d = nextDisp()
|
|
599
626
|
bindLines.push(`const ${d} = _bindText(${directRef}, ${tVar})`)
|
|
600
627
|
} else {
|
|
601
|
-
//
|
|
602
|
-
|
|
628
|
+
// Each reactive text child gets its own _bind — independent tracking.
|
|
629
|
+
// When r.name() changes, r.email()'s _bind doesn't re-run.
|
|
630
|
+
needsBindImportGlobal = true
|
|
631
|
+
const d = nextDisp()
|
|
632
|
+
bindLines.push(`const ${d} = _bind(() => { ${tVar}.data = ${expr} })`)
|
|
603
633
|
}
|
|
604
634
|
return needsPlaceholder ? '<!>' : ''
|
|
605
635
|
}
|
|
@@ -709,6 +739,7 @@ export function transformJSX(code: string, filename = 'input.tsx'): TransformRes
|
|
|
709
739
|
|
|
710
740
|
if (needsBindTextImport) needsBindTextImportGlobal = true
|
|
711
741
|
if (needsBindDirectImport) needsBindDirectImportGlobal = true
|
|
742
|
+
if (needsApplyPropsImport) needsApplyPropsImportGlobal = true
|
|
712
743
|
|
|
713
744
|
// Build bind function body
|
|
714
745
|
const escaped = html.replace(/\\/g, '\\\\').replace(/"/g, '\\"')
|
|
@@ -933,6 +964,39 @@ function isStatic(node: ts.Expression): boolean {
|
|
|
933
964
|
node.kind === ts.SyntaxKind.NullKeyword ||
|
|
934
965
|
node.kind === ts.SyntaxKind.UndefinedKeyword
|
|
935
966
|
)
|
|
967
|
+
// Note: object/array literals are NOT static — they need runtime application
|
|
968
|
+
// (e.g., style={{ color: "red" }} requires Object.assign at runtime).
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
/** Known pure global functions that don't read signals. */
|
|
972
|
+
const PURE_CALLS = new Set([
|
|
973
|
+
'Math.max', 'Math.min', 'Math.abs', 'Math.floor', 'Math.ceil', 'Math.round',
|
|
974
|
+
'Math.pow', 'Math.sqrt', 'Math.random', 'Math.trunc', 'Math.sign',
|
|
975
|
+
'Number.parseInt', 'Number.parseFloat', 'Number.isNaN', 'Number.isFinite',
|
|
976
|
+
'parseInt', 'parseFloat', 'isNaN', 'isFinite',
|
|
977
|
+
'String.fromCharCode', 'String.fromCodePoint',
|
|
978
|
+
'Object.keys', 'Object.values', 'Object.entries', 'Object.assign',
|
|
979
|
+
'Object.freeze', 'Object.create',
|
|
980
|
+
'Array.from', 'Array.isArray', 'Array.of',
|
|
981
|
+
'JSON.stringify', 'JSON.parse',
|
|
982
|
+
'encodeURIComponent', 'decodeURIComponent', 'encodeURI', 'decodeURI',
|
|
983
|
+
'Date.now',
|
|
984
|
+
])
|
|
985
|
+
|
|
986
|
+
/** Check if a call expression calls a known pure function with static args. */
|
|
987
|
+
function isPureStaticCall(node: ts.CallExpression): boolean {
|
|
988
|
+
const callee = node.expression
|
|
989
|
+
let name = ''
|
|
990
|
+
|
|
991
|
+
if (ts.isIdentifier(callee)) {
|
|
992
|
+
name = callee.text
|
|
993
|
+
} else if (ts.isPropertyAccessExpression(callee) && ts.isIdentifier(callee.expression)) {
|
|
994
|
+
name = `${callee.expression.text}.${callee.name.text}`
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
if (!PURE_CALLS.has(name)) return false
|
|
998
|
+
// Pure call with all static arguments → result is static
|
|
999
|
+
return node.arguments.every((arg) => !ts.isSpreadElement(arg) && isStatic(arg))
|
|
936
1000
|
}
|
|
937
1001
|
|
|
938
1002
|
function shouldWrap(node: ts.Expression): boolean {
|
|
@@ -940,6 +1004,8 @@ function shouldWrap(node: ts.Expression): boolean {
|
|
|
940
1004
|
if (ts.isArrowFunction(node) || ts.isFunctionExpression(node)) return false
|
|
941
1005
|
// Static literal — no signals involved
|
|
942
1006
|
if (isStatic(node)) return false
|
|
1007
|
+
// Pure call with static args — result is constant
|
|
1008
|
+
if (ts.isCallExpression(node) && isPureStaticCall(node)) return false
|
|
943
1009
|
// Only wrap if the expression tree contains a call — signal reads are always
|
|
944
1010
|
// function calls (e.g. `count()`, `name()`). Plain identifiers, object literals
|
|
945
1011
|
// like `style={{ color: "red" }}`, array literals, and member accesses are
|
|
@@ -948,7 +1014,11 @@ function shouldWrap(node: ts.Expression): boolean {
|
|
|
948
1014
|
}
|
|
949
1015
|
|
|
950
1016
|
function containsCall(node: ts.Node): boolean {
|
|
951
|
-
if (ts.isCallExpression(node))
|
|
1017
|
+
if (ts.isCallExpression(node)) {
|
|
1018
|
+
// Skip pure calls with static args
|
|
1019
|
+
if (isPureStaticCall(node as ts.CallExpression)) return false
|
|
1020
|
+
return true
|
|
1021
|
+
}
|
|
952
1022
|
if (ts.isTaggedTemplateExpression(node)) return true
|
|
953
1023
|
// Don't recurse into nested functions — they're self-contained
|
|
954
1024
|
if (ts.isArrowFunction(node) || ts.isFunctionExpression(node)) return false
|
package/src/tests/jsx.test.ts
CHANGED
|
@@ -528,8 +528,14 @@ describe('JSX transform — template emission', () => {
|
|
|
528
528
|
expect(result).not.toContain('_tpl(')
|
|
529
529
|
})
|
|
530
530
|
|
|
531
|
-
test('
|
|
531
|
+
test('emits _tpl for root spread with _applyProps in bind', () => {
|
|
532
532
|
const result = t('<div {...props}><span /></div>')
|
|
533
|
+
expect(result).toContain('_tpl(')
|
|
534
|
+
expect(result).toContain('_applyProps(__root, props)')
|
|
535
|
+
})
|
|
536
|
+
|
|
537
|
+
test('does NOT emit _tpl for spread on inner elements', () => {
|
|
538
|
+
const result = t('<div><span {...innerProps} /></div>')
|
|
533
539
|
expect(result).not.toContain('_tpl(')
|
|
534
540
|
})
|
|
535
541
|
|
|
@@ -1174,3 +1180,69 @@ describe('JSX transform — style attribute in templates', () => {
|
|
|
1174
1180
|
expect(result).toContain('style.cssText')
|
|
1175
1181
|
})
|
|
1176
1182
|
})
|
|
1183
|
+
|
|
1184
|
+
// ─── Pure call detection ────────────────────────────────────────────────────
|
|
1185
|
+
|
|
1186
|
+
describe('JSX transform — pure call detection', () => {
|
|
1187
|
+
test('Math.max with static args is not wrapped', () => {
|
|
1188
|
+
const result = t('<div>{Math.max(5, 10)}</div>')
|
|
1189
|
+
expect(result).not.toContain('() =>')
|
|
1190
|
+
})
|
|
1191
|
+
|
|
1192
|
+
test('JSON.stringify with string arg is not wrapped', () => {
|
|
1193
|
+
const result = t('<div>{JSON.stringify("hello")}</div>')
|
|
1194
|
+
expect(result).not.toContain('() =>')
|
|
1195
|
+
})
|
|
1196
|
+
|
|
1197
|
+
test('JSON.stringify with object arg IS wrapped (object not static)', () => {
|
|
1198
|
+
const result = t('<div>{JSON.stringify({a: 1})}</div>')
|
|
1199
|
+
// Object literals are not considered static by the compiler
|
|
1200
|
+
expect(result).toContain('.data =')
|
|
1201
|
+
})
|
|
1202
|
+
|
|
1203
|
+
test('Math.max with dynamic arg (signal call) IS wrapped', () => {
|
|
1204
|
+
const result = t('<div>{Math.max(count(), 10)}</div>')
|
|
1205
|
+
// Dynamic argument means the result depends on a signal
|
|
1206
|
+
expect(result).toContain('Math.max(count(), 10)')
|
|
1207
|
+
expect(result).toContain('.data =')
|
|
1208
|
+
})
|
|
1209
|
+
|
|
1210
|
+
test('unknown function call IS wrapped', () => {
|
|
1211
|
+
const result = t('<div>{unknownFn(5)}</div>')
|
|
1212
|
+
// Unknown function is not in PURE_CALLS, so it gets wrapped
|
|
1213
|
+
expect(result).toContain('.data =')
|
|
1214
|
+
})
|
|
1215
|
+
|
|
1216
|
+
test('Math.floor with static arg is not wrapped', () => {
|
|
1217
|
+
const result = t('<div>{Math.floor(3.14)}</div>')
|
|
1218
|
+
expect(result).not.toContain('() =>')
|
|
1219
|
+
})
|
|
1220
|
+
|
|
1221
|
+
test('Number.parseInt with static arg is not wrapped', () => {
|
|
1222
|
+
const result = t('<div>{Number.parseInt("42", 10)}</div>')
|
|
1223
|
+
expect(result).not.toContain('() =>')
|
|
1224
|
+
})
|
|
1225
|
+
})
|
|
1226
|
+
|
|
1227
|
+
// ─── Per-text-node bind (separate bindings) ─────────────────────────────────
|
|
1228
|
+
|
|
1229
|
+
describe('JSX transform — per-text-node bind', () => {
|
|
1230
|
+
test('two adjacent signal calls produce two separate _bindText calls', () => {
|
|
1231
|
+
const result = t('<div>{a()}{b()}</div>')
|
|
1232
|
+
expect(result).toContain('_bindText(a,')
|
|
1233
|
+
expect(result).toContain('_bindText(b,')
|
|
1234
|
+
})
|
|
1235
|
+
|
|
1236
|
+
test('two signal expressions with text between produce separate bindings', () => {
|
|
1237
|
+
const result = t('<div>{a()} and {b()}</div>')
|
|
1238
|
+
expect(result).toContain('_bindText(a,')
|
|
1239
|
+
expect(result).toContain('_bindText(b,')
|
|
1240
|
+
})
|
|
1241
|
+
|
|
1242
|
+
test('three signal calls produce three separate _bindText calls', () => {
|
|
1243
|
+
const result = t('<div>{a()}{b()}{c()}</div>')
|
|
1244
|
+
expect(result).toContain('_bindText(a,')
|
|
1245
|
+
expect(result).toContain('_bindText(b,')
|
|
1246
|
+
expect(result).toContain('_bindText(c,')
|
|
1247
|
+
})
|
|
1248
|
+
})
|