@barefootjs/jsx 0.39.9 → 0.40.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (164) hide show
  1. package/dist/adapters/ambiguous-nil-arithmetic.d.ts +41 -0
  2. package/dist/adapters/ambiguous-nil-arithmetic.d.ts.map +1 -0
  3. package/dist/adapters/attr-plan.d.ts +1 -20
  4. package/dist/adapters/attr-plan.d.ts.map +1 -1
  5. package/dist/adapters/boolean-carrier.d.ts +31 -0
  6. package/dist/adapters/boolean-carrier.d.ts.map +1 -0
  7. package/dist/adapters/component-props.d.ts +22 -7
  8. package/dist/adapters/component-props.d.ts.map +1 -1
  9. package/dist/adapters/computed-const.d.ts +17 -0
  10. package/dist/adapters/computed-const.d.ts.map +1 -1
  11. package/dist/adapters/dsl-template-adapter.d.ts +95 -2
  12. package/dist/adapters/dsl-template-adapter.d.ts.map +1 -1
  13. package/dist/adapters/loop-plan.d.ts +41 -1
  14. package/dist/adapters/loop-plan.d.ts.map +1 -1
  15. package/dist/adapters/number-value.d.ts +43 -0
  16. package/dist/adapters/number-value.d.ts.map +1 -0
  17. package/dist/analyzer-context.d.ts +7 -0
  18. package/dist/analyzer-context.d.ts.map +1 -1
  19. package/dist/analyzer.d.ts +34 -0
  20. package/dist/analyzer.d.ts.map +1 -1
  21. package/dist/augment-inherited-props.d.ts.map +1 -1
  22. package/dist/css-layer-prefixer.d.ts.map +1 -1
  23. package/dist/debug.d.ts.map +1 -1
  24. package/dist/expression-parser.d.ts.map +1 -1
  25. package/dist/index.d.ts +10 -7
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js +2102 -1344
  28. package/dist/ir-to-client-js/collect-elements.d.ts.map +1 -1
  29. package/dist/ir-to-client-js/control-flow/plan/build-component-loop.d.ts.map +1 -1
  30. package/dist/ir-to-client-js/control-flow/plan/build-inner-loop.d.ts +29 -0
  31. package/dist/ir-to-client-js/control-flow/plan/build-inner-loop.d.ts.map +1 -1
  32. package/dist/ir-to-client-js/control-flow/plan/build-lazy-row.d.ts +2 -0
  33. package/dist/ir-to-client-js/control-flow/plan/build-lazy-row.d.ts.map +1 -1
  34. package/dist/ir-to-client-js/control-flow/plan/build-loop-child-arm.d.ts.map +1 -1
  35. package/dist/ir-to-client-js/control-flow/plan/build-reactive-effects.d.ts.map +1 -1
  36. package/dist/ir-to-client-js/control-flow/plan/inner-loop.d.ts +5 -4
  37. package/dist/ir-to-client-js/control-flow/plan/inner-loop.d.ts.map +1 -1
  38. package/dist/ir-to-client-js/control-flow/plan/loop-child-arm.d.ts +2 -0
  39. package/dist/ir-to-client-js/control-flow/plan/loop-child-arm.d.ts.map +1 -1
  40. package/dist/ir-to-client-js/control-flow/plan/loop.d.ts +15 -0
  41. package/dist/ir-to-client-js/control-flow/plan/loop.d.ts.map +1 -1
  42. package/dist/ir-to-client-js/control-flow/plan/reactive-effects.d.ts +2 -0
  43. package/dist/ir-to-client-js/control-flow/plan/reactive-effects.d.ts.map +1 -1
  44. package/dist/ir-to-client-js/control-flow/shared.d.ts.map +1 -1
  45. package/dist/ir-to-client-js/control-flow/stringify/claim-plan.d.ts +20 -0
  46. package/dist/ir-to-client-js/control-flow/stringify/claim-plan.d.ts.map +1 -1
  47. package/dist/ir-to-client-js/control-flow/stringify/component-loop.d.ts.map +1 -1
  48. package/dist/ir-to-client-js/control-flow/stringify/event-listener.d.ts +1 -1
  49. package/dist/ir-to-client-js/control-flow/stringify/event-listener.d.ts.map +1 -1
  50. package/dist/ir-to-client-js/control-flow/stringify/lazy-row.d.ts.map +1 -1
  51. package/dist/ir-to-client-js/html-template.d.ts +3 -2
  52. package/dist/ir-to-client-js/html-template.d.ts.map +1 -1
  53. package/dist/ir-to-client-js/plan/build-static-array-child-init.d.ts.map +1 -1
  54. package/dist/ir-to-client-js/plan/static-array-child-init.d.ts +7 -1
  55. package/dist/ir-to-client-js/plan/static-array-child-init.d.ts.map +1 -1
  56. package/dist/ir-to-client-js/reactivity.d.ts.map +1 -1
  57. package/dist/ir-to-client-js/safe-html.d.ts +9 -3
  58. package/dist/ir-to-client-js/safe-html.d.ts.map +1 -1
  59. package/dist/ir-to-client-js/stringify/static-array-child-init.d.ts.map +1 -1
  60. package/dist/ir-to-client-js/types.d.ts +30 -0
  61. package/dist/ir-to-client-js/types.d.ts.map +1 -1
  62. package/dist/ir-to-client-js/utils.d.ts +9 -1
  63. package/dist/ir-to-client-js/utils.d.ts.map +1 -1
  64. package/dist/jsx-to-ir.d.ts.map +1 -1
  65. package/dist/module-exports.d.ts.map +1 -1
  66. package/dist/nullable-signal-attr.d.ts +29 -3
  67. package/dist/nullable-signal-attr.d.ts.map +1 -1
  68. package/dist/props-binding.d.ts +27 -3
  69. package/dist/props-binding.d.ts.map +1 -1
  70. package/dist/scope/binding-scope.d.ts +24 -1
  71. package/dist/scope/binding-scope.d.ts.map +1 -1
  72. package/dist/scope/root-prop-alias.d.ts +14 -1
  73. package/dist/scope/root-prop-alias.d.ts.map +1 -1
  74. package/dist/signal-prop-name-collision.d.ts.map +1 -1
  75. package/dist/ssr-defaults.d.ts +4 -2
  76. package/dist/ssr-defaults.d.ts.map +1 -1
  77. package/dist/ssr-seed-plan.d.ts +14 -0
  78. package/dist/ssr-seed-plan.d.ts.map +1 -1
  79. package/dist/template-parts.d.ts +1 -1
  80. package/dist/template-parts.d.ts.map +1 -1
  81. package/dist/types.d.ts +35 -1
  82. package/dist/types.d.ts.map +1 -1
  83. package/package.json +2 -2
  84. package/src/__tests__/attr-plan.test.ts +1 -14
  85. package/src/__tests__/binding-scope-ratchet.test.ts +12 -2
  86. package/src/__tests__/boolean-carrier.test.ts +74 -0
  87. package/src/__tests__/client-template-escape-soundness.test.ts +17 -4
  88. package/src/__tests__/client-template-static-delimiters.test.ts +57 -0
  89. package/src/__tests__/component-props.test.ts +14 -0
  90. package/src/__tests__/computed-const.test.ts +85 -0
  91. package/src/__tests__/dsl-template-adapter.test.ts +70 -0
  92. package/src/__tests__/expression-parser.test.ts +24 -0
  93. package/src/__tests__/extract-function-params.test.ts +37 -0
  94. package/src/__tests__/issue-2960-multi-root-cond-same-tag.test.ts +18 -0
  95. package/src/__tests__/issue-3688-props-spread-child-csr.test.ts +142 -0
  96. package/src/__tests__/jsx-text-linebreak-whitespace.test.ts +11 -0
  97. package/src/__tests__/loop-plan.test.ts +66 -1
  98. package/src/__tests__/loop-row-prop-read.test.ts +111 -0
  99. package/src/__tests__/memo-body-expr.test.ts +137 -0
  100. package/src/__tests__/nullable-signal-attr.test.ts +97 -2
  101. package/src/__tests__/profile-binding-ids.test.ts +14 -0
  102. package/src/__tests__/root-prop-alias.test.ts +34 -1
  103. package/src/__tests__/signal-prop-name-collision.test.ts +102 -2
  104. package/src/__tests__/source-file-cache.test.ts +105 -0
  105. package/src/__tests__/ssr-seed-plan.test.ts +43 -0
  106. package/src/__tests__/template-parts-literal-boundary.test.ts +41 -0
  107. package/src/adapters/ambiguous-nil-arithmetic.ts +94 -0
  108. package/src/adapters/attr-plan.ts +8 -56
  109. package/src/adapters/boolean-carrier.ts +76 -0
  110. package/src/adapters/component-props.ts +28 -8
  111. package/src/adapters/computed-const.ts +206 -7
  112. package/src/adapters/dsl-template-adapter.ts +183 -2
  113. package/src/adapters/loop-plan.ts +67 -2
  114. package/src/adapters/number-value.ts +95 -0
  115. package/src/analyzer-context.ts +8 -0
  116. package/src/analyzer.ts +187 -66
  117. package/src/augment-inherited-props.ts +5 -9
  118. package/src/css-layer-prefixer.ts +4 -5
  119. package/src/debug.ts +1 -0
  120. package/src/expression-parser.ts +4 -1
  121. package/src/index.ts +23 -5
  122. package/src/ir-to-client-js/collect-elements.ts +104 -46
  123. package/src/ir-to-client-js/compute-inlinability.ts +2 -2
  124. package/src/ir-to-client-js/control-flow/plan/build-component-loop.ts +15 -1
  125. package/src/ir-to-client-js/control-flow/plan/build-inner-loop.ts +79 -4
  126. package/src/ir-to-client-js/control-flow/plan/build-lazy-row.ts +3 -0
  127. package/src/ir-to-client-js/control-flow/plan/build-loop-child-arm.ts +1 -0
  128. package/src/ir-to-client-js/control-flow/plan/build-reactive-effects.ts +1 -0
  129. package/src/ir-to-client-js/control-flow/plan/inner-loop.ts +5 -4
  130. package/src/ir-to-client-js/control-flow/plan/loop-child-arm.ts +2 -0
  131. package/src/ir-to-client-js/control-flow/plan/loop.ts +12 -0
  132. package/src/ir-to-client-js/control-flow/plan/reactive-effects.ts +2 -0
  133. package/src/ir-to-client-js/control-flow/shared.ts +3 -2
  134. package/src/ir-to-client-js/control-flow/stringify/claim-plan.ts +27 -0
  135. package/src/ir-to-client-js/control-flow/stringify/component-loop.ts +8 -2
  136. package/src/ir-to-client-js/control-flow/stringify/event-listener.ts +8 -1
  137. package/src/ir-to-client-js/control-flow/stringify/inner-loop.ts +8 -7
  138. package/src/ir-to-client-js/control-flow/stringify/lazy-row.ts +8 -7
  139. package/src/ir-to-client-js/control-flow/stringify/loop-child-arm.ts +4 -4
  140. package/src/ir-to-client-js/control-flow/stringify/loop.ts +3 -3
  141. package/src/ir-to-client-js/control-flow/stringify/reactive-effects.ts +6 -6
  142. package/src/ir-to-client-js/emit-reactive.ts +1 -1
  143. package/src/ir-to-client-js/html-template.ts +122 -75
  144. package/src/ir-to-client-js/plan/build-static-array-child-init.ts +11 -1
  145. package/src/ir-to-client-js/plan/static-array-child-init.ts +7 -1
  146. package/src/ir-to-client-js/reactivity.ts +14 -0
  147. package/src/ir-to-client-js/safe-html.ts +11 -4
  148. package/src/ir-to-client-js/stringify/static-array-child-init.ts +6 -4
  149. package/src/ir-to-client-js/types.ts +23 -0
  150. package/src/ir-to-client-js/utils.ts +16 -2
  151. package/src/jsx-to-ir.ts +112 -55
  152. package/src/loop-destructure.ts +4 -1
  153. package/src/module-exports.ts +13 -21
  154. package/src/nullable-signal-attr.ts +134 -13
  155. package/src/props-binding.ts +54 -3
  156. package/src/rich-type-refusal.ts +3 -1
  157. package/src/scope/binding-scope.ts +35 -2
  158. package/src/scope/root-prop-alias.ts +17 -1
  159. package/src/signal-prop-name-collision.ts +113 -22
  160. package/src/ssr-defaults.ts +10 -4
  161. package/src/ssr-seed-plan.ts +82 -17
  162. package/src/template-parts.ts +25 -3
  163. package/src/template-position-walk.ts +3 -1
  164. package/src/types.ts +32 -1
@@ -20,6 +20,14 @@ import { markupSlotIdsOf } from './markup-slots.ts'
20
20
  import { isEventHandlerName } from '../event-handler-name.ts'
21
21
  import { writesAnyBinding } from '../props-binding.ts'
22
22
 
23
+ /** Static HTML is embedded in a JS template literal; dynamic expressions use interp(). */
24
+ function escapeStaticTemplateHtml(text: string): string {
25
+ return escapeHtml(text)
26
+ .replace(/\\/g, '\\\\')
27
+ .replace(/`/g, '\\`')
28
+ .replace(/\$\{/g, '\\${')
29
+ }
30
+
23
31
  /**
24
32
  * Split a template literal body into static segments and `${...}` interpolations,
25
33
  * correctly handling nested braces (e.g. object literals inside interpolations).
@@ -230,11 +238,13 @@ function maybeHoistedScopeAttr(
230
238
  }
231
239
 
232
240
  /**
233
- * Sentinel returned by the CSR template's `transformExpr` when the expression
234
- * references an init-body-only name (#1128). Equality with this sentinel is
235
- * how downstream emit sites decide to drop a renderChild prop, swap a loop
236
- * array for an empty array literal, or short-circuit a text expression to
237
- * an empty string. Module-internal — never appears in test fixtures.
241
+ * Spelling the CSR template's `transformExpr` emits when the expression
242
+ * references an init-body-only name (#1128), so a position that just
243
+ * evaluates it reads `undefined`. Sites that drop a renderChild prop, swap a
244
+ * loop array for an empty array literal, or short-circuit a text expression
245
+ * to an empty string decide that from `transformExprOrUnsafe`'s `null`, not
246
+ * from equality with this string: a source written as the literal
247
+ * `undefined` spells the same (#3752). Module-internal.
238
248
  */
239
249
  const UNSAFE_TEMPLATE_EXPR = 'undefined'
240
250
 
@@ -359,7 +369,7 @@ function renderTemplateAttrPart(
359
369
  case 'boolean-attr':
360
370
  return attrName
361
371
  case 'literal':
362
- return `${attrName}="${escapeHtml(v.value)}"`
372
+ return `${attrName}="${escapeStaticTemplateHtml(v.value)}"`
363
373
  case 'expression': {
364
374
  const valExpr = wrap(v.expr)
365
375
  return templateAttrExpr(attrName, valExpr, v.presenceOrUndefined)
@@ -385,6 +395,26 @@ function renderTemplateAttrPart(
385
395
  }
386
396
  }
387
397
 
398
+ /**
399
+ * Whether a child-component call's prop reaches the CSR `renderChild(...)`
400
+ * props object. Explicit props do (`key` is the call's own identity, not a
401
+ * prop). A spread does when it is the component's own props object
402
+ * (`SpreadAttr.propsObject`, decided in Phase 1): kept in source order next
403
+ * to the explicit props, the object literal merges like the JSX call does
404
+ * (#3688) — a later key overrides an earlier one, and the spread overrides
405
+ * only the keys the caller passed. Any other spread stays out.
406
+ */
407
+ function keepsTemplateComponentProp(p: IRProp): boolean {
408
+ if (p.name === 'key') return false
409
+ if (p.name === '...' || p.name.startsWith('...')) return p.value.kind === 'spread' && p.value.propsObject === true
410
+ return true
411
+ }
412
+
413
+ /** One `renderChild(...)` props-object entry: `name: value`, or `...value` for a spread. */
414
+ function templatePropEntry(p: IRProp, valueExpr: string): string {
415
+ return p.name === '...' || p.name.startsWith('...') ? `...${valueExpr}` : `${quotePropName(p.name)}: ${valueExpr}`
416
+ }
417
+
388
418
  /**
389
419
  * Source-of-truth predicates for the collision-safe spread-attrs merge
390
420
  * shared by all three CSR-side emit paths (`irToHtmlTemplate`,
@@ -793,7 +823,7 @@ export function irToHtmlTemplate(node: IRNode, restSpreadNames?: ReadonlySet<str
793
823
  case 'text':
794
824
  // IRText carries the entity-DECODED value; this string is parsed
795
825
  // as HTML (template.innerHTML), so re-escape for the HTML parser.
796
- return escapeHtml(node.value)
826
+ return escapeStaticTemplateHtml(node.value)
797
827
 
798
828
  case 'expression': {
799
829
  if (node.expr === 'null' || node.expr === 'undefined') return ''
@@ -865,7 +895,7 @@ export function irToHtmlTemplate(node: IRNode, restSpreadNames?: ReadonlySet<str
865
895
  // This allows stateless components in conditional branches to render their content
866
896
  // instead of emitting empty placeholders (#435).
867
897
  const propsEntries = node.props
868
- .filter(p => p.name !== '...' && !p.name.startsWith('...') && p.name !== 'key')
898
+ .filter(keepsTemplateComponentProp)
869
899
  // `ref` joins the `on*` handlers here: a function prop cannot run
870
900
  // during module-scope string rendering, and a ref closing over an
871
901
  // init-scope setter would leak it into the template (#2468). The
@@ -919,7 +949,7 @@ export function irToHtmlTemplate(node: IRNode, restSpreadNames?: ReadonlySet<str
919
949
  // previously masked by the post-hoc `wrapLoopParamAsAccessor`
920
950
  // pass over the whole branch string, which #2868 removed.
921
951
  const expr = wrapExpr(attrValueToString(p.value, { useTemplate: true }) ?? 'undefined')
922
- return `${quotePropName(p.name)}: ${expr}`
952
+ return templatePropEntry(p, expr)
923
953
  }
924
954
  }
925
955
  })
@@ -928,7 +958,9 @@ export function irToHtmlTemplate(node: IRNode, restSpreadNames?: ReadonlySet<str
928
958
  if (childrenEntry) propsEntries.push(childrenEntry)
929
959
  const propsExpr = propsEntries.length > 0 ? `{${propsEntries.join(', ')}}` : '{}'
930
960
  const keyProp = node.props.find(p => p.name === 'key')
931
- const keyArg = keyProp ? `, ${attrValueToString(keyProp.value) ?? 'undefined'}` : ''
961
+ const keyArg = keyProp
962
+ ? `, ${transformKeyValue(keyProp.value, (expr, templateExpr) => wrapExpr(templateExpr ?? expr))}`
963
+ : ''
932
964
  // Pass slotId as suffix so $c() can find the child component by slot
933
965
  // after branch swap. A loop-item-root component owns a separate scope
934
966
  // per iteration (identified by `data-key`) rather than deriving from
@@ -1072,7 +1104,7 @@ export function buildLoopSkeletonTemplate(node: IRNode, safe: LoopSkeletonSafeSl
1072
1104
  const v = a.value
1073
1105
  switch (v.kind) {
1074
1106
  case 'literal':
1075
- attrParts.push(`${toHtmlAttrName(a.name)}="${escapeHtml(v.value)}"`)
1107
+ attrParts.push(`${toHtmlAttrName(a.name)}="${escapeStaticTemplateHtml(v.value)}"`)
1076
1108
  break
1077
1109
  case 'boolean-attr':
1078
1110
  attrParts.push(toHtmlAttrName(a.name))
@@ -1128,7 +1160,7 @@ export function buildLoopSkeletonTemplate(node: IRNode, safe: LoopSkeletonSafeSl
1128
1160
  case 'text':
1129
1161
  // IRText carries the entity-DECODED value; this string is parsed
1130
1162
  // as HTML (template.innerHTML), so re-escape for the HTML parser.
1131
- return escapeHtml(node.value)
1163
+ return escapeStaticTemplateHtml(node.value)
1132
1164
 
1133
1165
  case 'expression':
1134
1166
  if (node.expr === 'null' || node.expr === 'undefined') return ''
@@ -1402,7 +1434,7 @@ export function irToPlaceholderTemplate(node: IRNode, restSpreadNames?: Readonly
1402
1434
  case 'text':
1403
1435
  // IRText carries the entity-DECODED value; this string is parsed
1404
1436
  // as HTML (template.innerHTML), so re-escape for the HTML parser.
1405
- return escapeHtml(node.value)
1437
+ return escapeStaticTemplateHtml(node.value)
1406
1438
 
1407
1439
  case 'expression': {
1408
1440
  if (node.expr === 'null' || node.expr === 'undefined') return ''
@@ -1571,7 +1603,15 @@ function irNodeToJsExprs(node: IRNode, brandMarkup = false): string[] {
1571
1603
  }
1572
1604
 
1573
1605
  const propsExpr = propsEntries.length > 0 ? `{ ${propsEntries.join(', ')} }` : '{}'
1574
- return [`createComponent('${nameForRegistryRef(node.name)}', ${propsExpr})`]
1606
+ // A slotted child gets the same slot identity SSR stamps on it
1607
+ // (`bf-h` = the authoring component, `bf-m` = its slot), so a
1608
+ // client-built tree matches the server's and a lookup of content
1609
+ // forwarded through it can tell it is a receiver (#3695). A loop row
1610
+ // root never takes a slot (`createComponent`'s own contract).
1611
+ const slotArg = node.slotId && !node.loopItemRoot
1612
+ ? `, undefined, { parent: __scopeId, mount: '${node.slotId}' }`
1613
+ : ''
1614
+ return [`createComponent('${nameForRegistryRef(node.name)}', ${propsExpr}${slotArg})`]
1575
1615
  }
1576
1616
 
1577
1617
  case 'expression':
@@ -1627,6 +1667,33 @@ export function addCondAttrToTemplate(html: string, condId: string): string {
1627
1667
  return `<!--bf-cond-start:${condId}-->${html}<!--bf-cond-end:${condId}-->`
1628
1668
  }
1629
1669
 
1670
+ function* templateHtmlTags(html: string): Generator<{ raw: string; end: number }> {
1671
+ let cursor = 0
1672
+ let noCommentEnd = false
1673
+ while (cursor < html.length) {
1674
+ const start = html.indexOf('<', cursor)
1675
+ if (start < 0) break
1676
+ cursor = start + 1
1677
+ if (html.startsWith('<!--', start) && !noCommentEnd) {
1678
+ const commentEnd = html.indexOf('-->', start + 4)
1679
+ if (commentEnd >= 0) {
1680
+ cursor = commentEnd + 3
1681
+ continue
1682
+ }
1683
+ // A failed search covers the entire remaining suffix, not just this opener.
1684
+ noCommentEnd = true
1685
+ }
1686
+ const nameStart = html[start + 1] === '/' ? start + 2 : start + 1
1687
+ if (nameStart >= html.length || /[\s/>]/.test(html[nameStart])) continue
1688
+ const end = html.indexOf('>', nameStart + 1)
1689
+ if (end < 0) break
1690
+ cursor = end + 1
1691
+ const raw = html.slice(start, cursor)
1692
+ if (raw.startsWith('<!--')) continue
1693
+ yield { raw, end: cursor }
1694
+ }
1695
+ }
1696
+
1630
1697
  /**
1631
1698
  * Check if HTML string has a single root element (not multiple siblings).
1632
1699
  *
@@ -1654,44 +1721,14 @@ function isSingleRootElement(html: string): boolean {
1654
1721
  // BOTH the `bf-c` stamp and the comment-wrap fallback for those roots.
1655
1722
  const match = trimmed.match(/^<(\w+)[\s>]/)
1656
1723
  if (!match) return false
1657
- // Self-closing tags like <br/>, <input/> with nothing else.
1658
- if (/^<\w+[^>]*\/>$/.test(trimmed)) return true
1659
-
1660
- // Walk top-level tags tracking nesting depth — see the docstring above
1661
- // for why (#2960). The comment alternative must come first so it wins at a `<!--`
1662
- // position — without it, a BarefootJS marker comment like
1663
- // `<!--bf:s1-->`/`<!--/-->` (a reactive text slot nested inside a
1664
- // genuine single root) matches the generic tag alternative too (its
1665
- // body has no `\s`, `/` or `>` before the closing `-->`) and gets
1666
- // miscounted as an opening tag, throwing off the depth count for
1667
- // perfectly ordinary single-root branches.
1668
- const tagPattern = /<!--[\s\S]*?-->|<\/?[^\s/>]+[^>]*>/g
1669
1724
  let depth = 0
1670
- let tagMatch: RegExpExecArray | null
1671
- while ((tagMatch = tagPattern.exec(trimmed))) {
1672
- const raw = tagMatch[0]
1673
- if (raw.startsWith('<!--')) continue // HTML comment, not a tag: depth unchanged
1725
+ for (const { raw, end } of templateHtmlTags(trimmed)) {
1674
1726
  if (raw.endsWith('/>')) {
1675
- // Self-closing/void tag (e.g. `<input .../>`). The whole-string
1676
- // check above only catches a self-closing tag with NOTHING else in
1677
- // the string — a self-closing root FOLLOWED by more content (e.g.
1678
- // `<input .../><label>...</label>`, a genuine two-root branch) still
1679
- // reaches here with the guard above already satisfied (it only
1680
- // looks at the tag name and the very next character, not whether
1681
- // the tag turns out to self-close). At depth 0 this tag completes a
1682
- // whole top-level unit by itself, so treat it exactly like any
1683
- // other tag's closing point: single root only if nothing follows.
1684
- // Nested inside another element (depth > 0) it's just an ordinary
1685
- // child and doesn't affect depth.
1686
- if (depth === 0) return tagPattern.lastIndex === trimmed.length
1727
+ if (depth === 0) return end === trimmed.length
1687
1728
  continue
1688
1729
  }
1689
1730
  depth += raw.startsWith('</') ? -1 : 1
1690
- if (depth === 0) {
1691
- // Back to depth 0: the root element's own closing tag. Single root
1692
- // only if nothing else follows it.
1693
- return tagPattern.lastIndex === trimmed.length
1694
- }
1731
+ if (depth === 0) return end === trimmed.length
1695
1732
  }
1696
1733
  return false
1697
1734
  }
@@ -1729,8 +1766,9 @@ export interface TemplateOptions {
1729
1766
  * (the literal token `'undefined'`) whenever the resulting expression
1730
1767
  * still references one of these names. The init function's
1731
1768
  * `createEffect` / `initChild` bindings populate the real value once
1732
- * init runs. Per-context guards (loop array, text expression) translate
1733
- * the sentinel into something safe for that AST position.
1769
+ * init runs. Per-context guards (loop array, text expression, child
1770
+ * prop) test `transformExprOrUnsafe`'s `null` instead and translate it
1771
+ * into something safe for that AST position.
1734
1772
  */
1735
1773
  unsafeLocalNames?: Set<string>
1736
1774
  /**
@@ -1934,7 +1972,7 @@ function irToComponentTemplateWithOpts(node: IRNode, opts: TemplateOptions): str
1934
1972
  return templateAttrExpr(keyName, transformExpr(tmplStr))
1935
1973
  }
1936
1974
  case 'literal':
1937
- return `${keyName}="${escapeHtml(v.value)}"`
1975
+ return `${keyName}="${escapeStaticTemplateHtml(v.value)}"`
1938
1976
  default:
1939
1977
  return ''
1940
1978
  }
@@ -1944,7 +1982,7 @@ function irToComponentTemplateWithOpts(node: IRNode, opts: TemplateOptions): str
1944
1982
  case 'boolean-attr':
1945
1983
  return attrName
1946
1984
  case 'literal':
1947
- return `${attrName}="${escapeHtml(v.value)}"`
1985
+ return `${attrName}="${escapeStaticTemplateHtml(v.value)}"`
1948
1986
  case 'expression':
1949
1987
  return templateAttrExpr(attrName, transformExpr(v.expr, v.templateExpr), v.presenceOrUndefined)
1950
1988
  case 'template': {
@@ -1977,7 +2015,7 @@ function irToComponentTemplateWithOpts(node: IRNode, opts: TemplateOptions): str
1977
2015
  case 'text':
1978
2016
  // IRText carries the entity-DECODED value; this string is parsed
1979
2017
  // as HTML (template.innerHTML), so re-escape for the HTML parser.
1980
- return escapeHtml(node.value)
2018
+ return escapeStaticTemplateHtml(node.value)
1981
2019
 
1982
2020
  case 'expression': {
1983
2021
  if (node.expr === 'null' || node.expr === 'undefined') return ''
@@ -2024,7 +2062,7 @@ function irToComponentTemplateWithOpts(node: IRNode, opts: TemplateOptions): str
2024
2062
 
2025
2063
  // Use renderChild() to render child component's template at runtime (#435)
2026
2064
  const propsEntries = node.props
2027
- .filter(p => p.name !== '...' && !p.name.startsWith('...') && p.name !== 'key')
2065
+ .filter(keepsTemplateComponentProp)
2028
2066
  // `ref` joins the `on*` handlers here: a function prop cannot run
2029
2067
  // during module-scope string rendering, and a ref closing over an
2030
2068
  // init-scope setter would leak it into the template (#2468). The
@@ -2052,7 +2090,7 @@ function irToComponentTemplateWithOpts(node: IRNode, opts: TemplateOptions): str
2052
2090
  case 'expression':
2053
2091
  return `${quotePropName(p.name)}: ${transformExpr(p.value.expr, p.value.templateExpr)}`
2054
2092
  case 'spread':
2055
- return `${quotePropName(p.name)}: ${transformExpr(p.value.expr, p.value.templateExpr)}`
2093
+ return templatePropEntry(p, transformExpr(p.value.expr, p.value.templateExpr))
2056
2094
  case 'template': {
2057
2095
  const valueStr = attrValueToString(p.value, { useTemplate: true })!
2058
2096
  return `${quotePropName(p.name)}: ${transformExpr(valueStr)}`
@@ -2464,7 +2502,14 @@ export function computeDeferredChildSlots(
2464
2502
  function generateCsrTemplateWithOpts(node: IRNode, opts: TemplateOptions): string {
2465
2503
  const { restSpreadNames, propsObjectName, restPropsName, csrEnv, unsafeLocalNames, loopDepth = 0 } = opts
2466
2504
  const env: CsrEnv = csrEnv ?? { substitutions: new Map(), propsObjectName: propsObjectName ?? null }
2467
- const transformExpr = (expr: JsSourceText, templateExpr?: JsSourceText): string => {
2505
+ // `null` when the expression cannot run in the module-scope template
2506
+ // (it writes a binding or reads an init-only name). Call sites that drop
2507
+ // or replace such an expression test this, not `transformExpr`'s
2508
+ // `UNSAFE_TEMPLATE_EXPR` spelling: that sentinel is also what a source
2509
+ // written as the literal `undefined` transforms to, and a child prop
2510
+ // `label={undefined}` must keep its key (it overrides an earlier
2511
+ // spread value, #3752).
2512
+ const transformExprOrUnsafe = (expr: JsSourceText, templateExpr?: JsSourceText): string | null => {
2468
2513
  // Single AST substitution pass: replaces signal getter calls
2469
2514
  // (`count()` → `(initialValue)`), memo calls (`bars()` → `(body)`),
2470
2515
  // and inlinable-const refs (`label` → `(rewrittenValue)`) in one
@@ -2479,7 +2524,7 @@ function generateCsrTemplateWithOpts(node: IRNode, opts: TemplateOptions): strin
2479
2524
  // An expression that writes a binding (`{++nextId}`, a child prop
2480
2525
  // `() => ++start`) cannot run here: the template has no binding to
2481
2526
  // write, and the write belongs to init's run of the component.
2482
- if (writes.size > 0) return UNSAFE_TEMPLATE_EXPR
2527
+ if (writes.size > 0) return null
2483
2528
 
2484
2529
  // The CSR template runs at module scope, so any post-substitution
2485
2530
  // free identifier that lands in `unsafeLocalNames` (init-body-only
@@ -2494,7 +2539,7 @@ function generateCsrTemplateWithOpts(node: IRNode, opts: TemplateOptions): strin
2494
2539
  // (and its `'foo-className'` / `a.className` false-match risk)
2495
2540
  // is gone (#1267 / #1277).
2496
2541
  if (unsafeLocalNames && unsafeLocalNames.size > 0 && setIntersects(freeIdentifiers, unsafeLocalNames)) {
2497
- return UNSAFE_TEMPLATE_EXPR
2542
+ return null
2498
2543
  }
2499
2544
  // Final emit-form: rewrite `propsName.X → _p.X` (and a direct
2500
2545
  // rest-bag read, `restName.X → _p.X` — the rest binding IS `_p` at
@@ -2507,6 +2552,8 @@ function generateCsrTemplateWithOpts(node: IRNode, opts: TemplateOptions): strin
2507
2552
  // gate — #1138).
2508
2553
  return rewritePropsObjectRef(rewritten, propsObjectName ?? null, restPropsName ?? null, { enclosingScope: opts.scope })
2509
2554
  }
2555
+ const transformExpr = (expr: JsSourceText, templateExpr?: JsSourceText): string =>
2556
+ transformExprOrUnsafe(expr, templateExpr) ?? UNSAFE_TEMPLATE_EXPR
2510
2557
 
2511
2558
  // `recurse` preserves `inHoistedChildren` for structural pass-through
2512
2559
  // (fragment / conditional); `childrenRecurse` clears it — a new element
@@ -2566,7 +2613,7 @@ function generateCsrTemplateWithOpts(node: IRNode, opts: TemplateOptions): strin
2566
2613
  case 'boolean-attr':
2567
2614
  return keyName
2568
2615
  case 'literal':
2569
- return `${keyName}="${escapeHtml(v.value)}"`
2616
+ return `${keyName}="${escapeStaticTemplateHtml(v.value)}"`
2570
2617
  case 'expression':
2571
2618
  return templateAttrExpr(keyName, transformExpr(v.expr, v.templateExpr), v.presenceOrUndefined)
2572
2619
  case 'template': {
@@ -2583,7 +2630,7 @@ function generateCsrTemplateWithOpts(node: IRNode, opts: TemplateOptions): strin
2583
2630
  case 'boolean-attr':
2584
2631
  return attrName
2585
2632
  case 'literal':
2586
- return `${attrName}="${escapeHtml(v.value)}"`
2633
+ return `${attrName}="${escapeStaticTemplateHtml(v.value)}"`
2587
2634
  case 'expression':
2588
2635
  return templateAttrExpr(attrName, transformExpr(v.expr, v.templateExpr), v.presenceOrUndefined)
2589
2636
  case 'template': {
@@ -2616,7 +2663,7 @@ function generateCsrTemplateWithOpts(node: IRNode, opts: TemplateOptions): strin
2616
2663
  case 'text':
2617
2664
  // IRText carries the entity-DECODED value; this string is parsed
2618
2665
  // as HTML (template.innerHTML), so re-escape for the HTML parser.
2619
- return escapeHtml(node.value)
2666
+ return escapeStaticTemplateHtml(node.value)
2620
2667
 
2621
2668
  case 'expression':
2622
2669
  if (node.expr === 'null' || node.expr === 'undefined') return ''
@@ -2649,12 +2696,12 @@ function generateCsrTemplateWithOpts(node: IRNode, opts: TemplateOptions): strin
2649
2696
  return `<!--bf:${node.slotId}--><!--/-->`
2650
2697
  }
2651
2698
  {
2652
- const transformed = transformExpr(node.expr, node.templateExpr)
2699
+ const transformed = transformExprOrUnsafe(node.expr, node.templateExpr)
2653
2700
  // Init-body-only refs would render the literal text "undefined"
2654
2701
  // before init's createEffect overwrites the slot (#1128). Emit
2655
2702
  // an empty placeholder instead — a literal, so it bypasses the door.
2656
2703
  const hole = interp(
2657
- transformed === UNSAFE_TEMPLATE_EXPR
2704
+ transformed === null
2658
2705
  ? EMPTY_MARKUP
2659
2706
  : spliceChildValue(node, transformed, { markupSlotIds: opts.markupSlotIds }),
2660
2707
  )
@@ -2699,7 +2746,7 @@ function generateCsrTemplateWithOpts(node: IRNode, opts: TemplateOptions): strin
2699
2746
  }
2700
2747
 
2701
2748
  const propsEntries = node.props
2702
- .filter(p => p.name !== '...' && !p.name.startsWith('...') && p.name !== 'key')
2749
+ .filter(keepsTemplateComponentProp)
2703
2750
  // `ref` joins the `on*` handlers here: a function prop cannot run
2704
2751
  // during module-scope string rendering, and a ref closing over an
2705
2752
  // init-scope setter would leak it into the template (#2468). The
@@ -2730,18 +2777,19 @@ function generateCsrTemplateWithOpts(node: IRNode, opts: TemplateOptions): strin
2730
2777
  return `${quotePropName(p.name)}: true`
2731
2778
  case 'expression':
2732
2779
  case 'spread': {
2733
- const transformed = transformExpr(p.value.expr, p.value.templateExpr)
2734
- // When transformExpr emits the unsafe sentinel for an init-scope-only
2735
- // reference (#1128), drop the prop from renderChild — initChild's
2736
- // getter binding will populate it once init runs.
2737
- if (transformed === UNSAFE_TEMPLATE_EXPR) return null
2738
- return `${quotePropName(p.name)}: ${transformed}`
2780
+ const transformed = transformExprOrUnsafe(p.value.expr, p.value.templateExpr)
2781
+ // An init-scope-only reference (#1128) drops the prop from
2782
+ // renderChild — initChild's getter binding will populate it once
2783
+ // init runs. A prop written as the literal `undefined` is not
2784
+ // unsafe and keeps its key (#3752).
2785
+ if (transformed === null) return null
2786
+ return templatePropEntry(p, transformed)
2739
2787
  }
2740
2788
  case 'template': {
2741
2789
  const valueStr = attrValueToString(p.value, { useTemplate: true })
2742
2790
  if (!valueStr) return null
2743
- const transformed = transformExpr(valueStr)
2744
- if (transformed === UNSAFE_TEMPLATE_EXPR) return null
2791
+ const transformed = transformExprOrUnsafe(valueStr)
2792
+ if (transformed === null) return null
2745
2793
  return `${quotePropName(p.name)}: ${transformed}`
2746
2794
  }
2747
2795
  }
@@ -2782,12 +2830,12 @@ function generateCsrTemplateWithOpts(node: IRNode, opts: TemplateOptions): strin
2782
2830
  const hoistValues: string[] = []
2783
2831
  for (const name of hoisted) {
2784
2832
  const sub = env.substitutions.get(name)!
2785
- const value = transformExpr(sub.kind === 'call' ? `${name}()` : name)
2833
+ const value = transformExprOrUnsafe(sub.kind === 'call' ? `${name}()` : name)
2786
2834
  // An init-only value stays on the resolved substitution, whose free
2787
2835
  // identifiers still name the init-only local, so a row expression
2788
2836
  // reading it is deferred like any other unsafe read rather than
2789
2837
  // handed a bound `undefined` to dereference.
2790
- if (value === UNSAFE_TEMPLATE_EXPR) continue
2838
+ if (value === null) continue
2791
2839
  const param = `__bf_outer_${name}`
2792
2840
  hoistParams.push(param)
2793
2841
  hoistValues.push(value)
@@ -2827,8 +2875,7 @@ function generateCsrTemplateWithOpts(node: IRNode, opts: TemplateOptions): strin
2827
2875
  const chainedTemplateArray = node.sortComparator || node.filterPredicate
2828
2876
  ? applyLoopChain(node, node.templateArray)
2829
2877
  : node.templateArray
2830
- const rawArrayExpr = transformExpr(node.array, chainedTemplateArray)
2831
- const safeRawArrayExpr = rawArrayExpr === UNSAFE_TEMPLATE_EXPR ? '[]' : rawArrayExpr
2878
+ const safeRawArrayExpr = transformExprOrUnsafe(node.array, chainedTemplateArray) ?? '[]'
2832
2879
  const { array: iterArrayExpr, callbackParam } = applyIterationShape(node, safeRawArrayExpr, indexParam)
2833
2880
  const iterMethod = node.method ?? 'map'
2834
2881
  let mapExpr: string
@@ -35,6 +35,7 @@ function staticPreludeStatements(preamble: MapCallbackPreamble | undefined): str
35
35
  : []
36
36
  }
37
37
  import { buildCompSelector, buildStaticChildRefBindings } from '../control-flow/shared.ts'
38
+ import { buildForwardedInnerLoopsPlan } from '../control-flow/plan/build-inner-loop.ts'
38
39
 
39
40
  /** The inline prop shape carried on `IRLoopChildComponent.props`. */
40
41
  type LoopChildCompProp = IRLoopChildComponent['props'][number]
@@ -136,7 +137,16 @@ function buildSingleCompPlan(
136
137
  // handlers on its forwarded children directly.
137
138
  rowEvents: elem.bindings.events
138
139
  .filter(ev => ev.nestedLoops.length === 0)
139
- .map(ev => ({ childSlotId: ev.childSlotId, eventName: ev.eventName, handler: ev.handler })),
140
+ .map(ev => ({ childSlotId: ev.childSlotId, eventName: ev.eventName, handler: ev.handler, receiverSlotIds: ev.receiverSlotIds })),
141
+ // #3694: the static twin of the component-root loop's `innerLoops` —
142
+ // events inside an inner loop of the forwarded children, wired through
143
+ // the composite row's inner-loop emission over each hydrated row. No
144
+ // outer accessor: the forEach binds `param` to the plain item.
145
+ innerLoops: buildForwardedInnerLoopsPlan({
146
+ innerLoops: elem.innerLoops,
147
+ events: elem.bindings.events,
148
+ parentElVar: 'childScope',
149
+ }),
140
150
  }
141
151
  }
142
152
 
@@ -26,7 +26,7 @@
26
26
  */
27
27
 
28
28
  import type { LoopRowEventBinding } from '../control-flow/plan/loop.ts'
29
- import type { PreludeStatements } from '../control-flow/plan/inner-loop.ts'
29
+ import type { InnerLoopsPlan, PreludeStatements } from '../control-flow/plan/inner-loop.ts'
30
30
  import type { LoopChildRefBinding } from '../control-flow/plan/loop.ts'
31
31
  import type { LoopChildReactiveAttr, LoopChildReactiveText } from '../types.ts'
32
32
 
@@ -79,6 +79,12 @@ export interface SingleCompInitPlan {
79
79
  * plain item, as for `propsExpr`.
80
80
  */
81
81
  rowEvents: readonly LoopRowEventBinding[]
82
+ /**
83
+ * Inner loops of the row component's forwarded `children` that carry an
84
+ * event handler (#3694), run over each hydrated row (`childScope`) after
85
+ * `rowEvents`. Empty when no inner loop carries an event.
86
+ */
87
+ innerLoops: InnerLoopsPlan
82
88
  }
83
89
 
84
90
  /** Plan for one depth-0 component inside `loop.nestedComponents`. */
@@ -594,12 +594,16 @@ export function collectLoopChildEventsWithNesting(
594
594
  nestingStack: NestedLoop[]
595
595
  lastElementSlotId: string | null
596
596
  domDepth: number
597
+ /** Slot ids of the components below the row root whose `children`
598
+ * enclose the current node (#3695) — see `LoopChildEvent.receiverSlotIds`. */
599
+ receivers: readonly string[]
597
600
  }
598
601
  const events: LoopChildEvent[] = []
599
602
  const initialScope: Scope = {
600
603
  nestingStack: initialNestingStack,
601
604
  lastElementSlotId: null,
602
605
  domDepth: 0,
606
+ receivers: [],
603
607
  }
604
608
  walkIR(node, initialScope, {
605
609
  element: ({ node: el, scope, descend }) => {
@@ -611,6 +615,7 @@ export function collectLoopChildEventsWithNesting(
611
615
  handler: event.handler,
612
616
  nestedLoops: [...scope.nestingStack],
613
617
  domDepth: scope.domDepth,
618
+ ...(el.slotId.startsWith('^') && scope.receivers.length > 0 && { receiverSlotIds: scope.receivers }),
614
619
  })
615
620
  }
616
621
  }
@@ -620,13 +625,21 @@ export function collectLoopChildEventsWithNesting(
620
625
  domDepth: scope.domDepth + 1,
621
626
  })
622
627
  },
628
+ component: ({ node: c, scope, descend }) => {
629
+ // The row's own root component is the lookup root, never a scope
630
+ // between the element and it; a component nested below it renders the
631
+ // forwarded element inside its own scope (#3695).
632
+ descend(c !== node && c.slotId ? { ...scope, receivers: [...scope.receivers, c.slotId] } : scope)
633
+ },
623
634
  loop: ({ node: l, scope, descend }) => {
624
635
  // Enter nested loop — push nesting info with container element's slotId.
625
636
  // `bindings` is required on every loop variant; populate as empty here
626
637
  // because this NestedLoop sub-record is only used as event-delegation
627
638
  // metadata (nestedLoops chain), not as a structurally-complete loop.
639
+ // An inner row is its own lookup root, so the receivers restart.
628
640
  descend({
629
641
  ...scope,
642
+ receivers: [],
630
643
  nestingStack: [
631
644
  ...scope.nestingStack,
632
645
  {
@@ -791,6 +804,7 @@ export function collectLoopChildReactiveTexts(
791
804
  expression: expanded.expr,
792
805
  insideConditional: insideConditional || undefined,
793
806
  ...(expanded.freeIds !== undefined && { freeIdentifiers: expanded.freeIds }),
807
+ ...(n.loopRowPropRead && { markup: true as const }),
794
808
  })
795
809
  },
796
810
  conditional: ({ node: c, descend }) => {
@@ -213,7 +213,10 @@ export interface ChildSpliceContext {
213
213
  * branch-row builders, whose reactive twin is a `kind: 'text'` writer
214
214
  * (`String(...)` into `nodeValue`) — plain `escapeText` is the consistent
215
215
  * choice there, and it is also the choice that never unwraps a
216
- * `bfMarkup()`-shaped object arriving in JSON-sourced loop data.
216
+ * `bfMarkup()`-shaped object arriving in JSON-sourced loop data. The one
217
+ * exception is a row's read of the component's own prop
218
+ * (`IRExpression.loopRowPropRead`): its row writer is `kind: 'markup'`,
219
+ * so the door unwraps it as it does the same read outside a loop.
217
220
  */
218
221
  readonly markupSlotIds?: ReadonlySet<string>
219
222
  }
@@ -228,7 +231,10 @@ export interface ChildSpliceContext {
228
231
  * Arms, first match wins:
229
232
  * 1. `joinArrayChild` → `joinedMarkup` (array of compiled leaves)
230
233
  * 2. `branchSlotsVar` → `branchSlotValue` (runtime coercion, may be a Node)
231
- * 3. `slotId` ∈ markupSlotIds → `escapedTextOrMarkup`
234
+ * 3. `slotId` ∈ markupSlotIds,→ `escapedTextOrMarkup`
235
+ * or a loop-row prop read
236
+ * (`loopRowPropRead`, whose
237
+ * row writer is 'markup' too)
232
238
  * 4. `slotId` → `escapedText`
233
239
  * 5. `{children}` passthrough → `childrenMarkup` (bare splice only, #2775/#2786)
234
240
  * 6. `children ?? fallback`, → `childrenMarkupOrEscapedFallback` (#3554)
@@ -242,14 +248,15 @@ export interface ChildSpliceContext {
242
248
  * either alone misses one of the two shapes (#2786).
243
249
  */
244
250
  export function spliceChildValue(
245
- node: Pick<IRExpression, 'expr' | 'slotId' | 'joinArrayChild' | 'childrenRead'>,
251
+ node: Pick<IRExpression, 'expr' | 'slotId' | 'joinArrayChild' | 'childrenRead' | 'loopRowPropRead'>,
246
252
  valueExpr: string,
247
253
  cx: ChildSpliceContext,
248
254
  ): SafeHtml {
249
255
  if (node.joinArrayChild) return joinedMarkup(valueExpr)
250
256
  if (cx.branchSlotsVar) return branchSlotValue(valueExpr, cx.branchSlotsVar)
251
257
  if (node.slotId) {
252
- return cx.markupSlotIds?.has(node.slotId) ? escapedTextOrMarkup(valueExpr) : escapedText(valueExpr)
258
+ const markup = cx.markupSlotIds?.has(node.slotId) || node.loopRowPropRead
259
+ return markup ? escapedTextOrMarkup(valueExpr) : escapedText(valueExpr)
253
260
  }
254
261
  if (node.childrenRead === 'bare' || node.childrenRead === 'nullish-empty') {
255
262
  return childrenMarkup(valueExpr)
@@ -61,9 +61,10 @@ import type {
61
61
  import { nameForRegistryRef } from '../component-scope.ts'
62
62
  import { varSlotId } from '../utils.ts'
63
63
  import { emitDedupedAttrUpdate, DEDUP_STORE_DECL } from '../emit-reactive.ts'
64
- import { claimPlanLiteral, claimWriterVarName, type ClaimSlotSpec } from '../control-flow/stringify/claim-plan.ts'
64
+ import { claimPlanLiteral, claimWriterVarName, rowTextSlotKind, rowTextSlotValue, type ClaimSlotSpec } from '../control-flow/stringify/claim-plan.ts'
65
65
  import { emitLoopChildRefs } from '../control-flow/stringify/loop.ts'
66
66
  import { emitRowEventListener } from '../control-flow/shared.ts'
67
+ import { stringifyInnerLoops } from '../control-flow/stringify/inner-loop.ts'
67
68
 
68
69
  export function stringifyStaticArrayChildInits(
69
70
  lines: string[],
@@ -92,7 +93,7 @@ function stringifyOne(lines: string[], plan: StaticArrayChildInitPlan): void {
92
93
  }
93
94
 
94
95
  function emitSingleComp(lines: string[], plan: SingleCompInitPlan): void {
95
- const { containerVar, componentName, childSelector, arrayExpr, param, indexParam, outerPreludeStatements, propsExpr, rowEvents } = plan
96
+ const { containerVar, componentName, childSelector, arrayExpr, param, indexParam, outerPreludeStatements, propsExpr, rowEvents, innerLoops } = plan
96
97
  lines.push(` // Initialize static array children (hydrate skips nested instances)`)
97
98
  lines.push(` if (${containerVar}) {`)
98
99
  lines.push(` const __childScopes = qsaChildScopes(${containerVar}, ${childSelector})`)
@@ -106,6 +107,7 @@ function emitSingleComp(lines: string[], plan: SingleCompInitPlan): void {
106
107
  }
107
108
  lines.push(` initChild('${nameForRegistryRef(componentName)}', childScope, ${propsExpr})`)
108
109
  for (const ev of rowEvents) emitRowEventListener(lines, ' ', 'childScope', ev)
110
+ stringifyInnerLoops(lines, innerLoops, ' ')
109
111
  lines.push(` })`)
110
112
  lines.push(` }`)
111
113
  lines.push('')
@@ -205,11 +207,11 @@ function emitInnerLoopNested(lines: string[], plan: InnerLoopNestedInitPlan): vo
205
207
  lines.push(` }`)
206
208
  }
207
209
  if (texts.length > 0) {
208
- const slots: ClaimSlotSpec[] = texts.map(t => ({ id: t.slotId, kind: 'text', path: [] }))
210
+ const slots: ClaimSlotSpec[] = texts.map(t => ({ id: t.slotId, kind: rowTextSlotKind(t), path: [] }))
209
211
  const writer = claimWriterVarName(slots, varSlotId)
210
212
  lines.push(` const ${writer} = lazySlots(__innerEl, ${claimPlanLiteral(slots)})`)
211
213
  for (const text of texts) {
212
- lines.push(` createEffect(() => { ${writer}('${text.slotId}', String(${text.expression})) })`)
214
+ lines.push(` createEffect(() => { ${writer}('${text.slotId}', ${rowTextSlotValue(text, text.expression, 'String')}) })`)
213
215
  }
214
216
  }
215
217
  // Ref callbacks fire on every forEach iteration — initial mount and any