@barefootjs/jsx 0.39.7 → 0.39.9

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 (192) hide show
  1. package/dist/adapters/callback-method.d.ts +36 -7
  2. package/dist/adapters/callback-method.d.ts.map +1 -1
  3. package/dist/adapters/component-props.d.ts +80 -13
  4. package/dist/adapters/component-props.d.ts.map +1 -1
  5. package/dist/adapters/dsl-template-adapter.d.ts +153 -0
  6. package/dist/adapters/dsl-template-adapter.d.ts.map +1 -0
  7. package/dist/adapters/jsx-adapter.d.ts +4 -0
  8. package/dist/adapters/jsx-adapter.d.ts.map +1 -1
  9. package/dist/adapters/literal-value.d.ts +2 -2
  10. package/dist/adapters/literal-value.d.ts.map +1 -1
  11. package/dist/adapters/loop-plan.d.ts +133 -9
  12. package/dist/adapters/loop-plan.d.ts.map +1 -1
  13. package/dist/adapters/parsed-expr-emitter.d.ts +44 -0
  14. package/dist/adapters/parsed-expr-emitter.d.ts.map +1 -1
  15. package/dist/adapters/style-object.d.ts +33 -0
  16. package/dist/adapters/style-object.d.ts.map +1 -0
  17. package/dist/analyzer.d.ts.map +1 -1
  18. package/dist/assignment-target.d.ts +26 -0
  19. package/dist/assignment-target.d.ts.map +1 -0
  20. package/dist/children-nullish.d.ts +22 -0
  21. package/dist/children-nullish.d.ts.map +1 -0
  22. package/dist/errors.d.ts +2 -0
  23. package/dist/errors.d.ts.map +1 -1
  24. package/dist/expression-parser.d.ts +9 -19
  25. package/dist/expression-parser.d.ts.map +1 -1
  26. package/dist/free-refs.d.ts +6 -0
  27. package/dist/free-refs.d.ts.map +1 -1
  28. package/dist/index.d.ts +17 -14
  29. package/dist/index.d.ts.map +1 -1
  30. package/dist/index.js +15040 -13899
  31. package/dist/ir-to-client-js/compute-inlinability.d.ts.map +1 -1
  32. package/dist/ir-to-client-js/control-flow/plan/build-component-loop.d.ts.map +1 -1
  33. package/dist/ir-to-client-js/control-flow/plan/event-collision.d.ts +2 -1
  34. package/dist/ir-to-client-js/control-flow/plan/event-collision.d.ts.map +1 -1
  35. package/dist/ir-to-client-js/control-flow/plan/insert.d.ts +2 -2
  36. package/dist/ir-to-client-js/control-flow/plan/insert.d.ts.map +1 -1
  37. package/dist/ir-to-client-js/control-flow/plan/loop.d.ts +24 -1
  38. package/dist/ir-to-client-js/control-flow/plan/loop.d.ts.map +1 -1
  39. package/dist/ir-to-client-js/control-flow/shared.d.ts +16 -1
  40. package/dist/ir-to-client-js/control-flow/shared.d.ts.map +1 -1
  41. package/dist/ir-to-client-js/control-flow/stringify/component-loop.d.ts +6 -1
  42. package/dist/ir-to-client-js/control-flow/stringify/component-loop.d.ts.map +1 -1
  43. package/dist/ir-to-client-js/control-flow/stringify/event-delegation.d.ts.map +1 -1
  44. package/dist/ir-to-client-js/control-flow/stringify/event-listener.d.ts +10 -9
  45. package/dist/ir-to-client-js/control-flow/stringify/event-listener.d.ts.map +1 -1
  46. package/dist/ir-to-client-js/csr-substitute.d.ts +13 -2
  47. package/dist/ir-to-client-js/csr-substitute.d.ts.map +1 -1
  48. package/dist/ir-to-client-js/emit-reactive.d.ts +1 -1
  49. package/dist/ir-to-client-js/emit-reactive.d.ts.map +1 -1
  50. package/dist/ir-to-client-js/emit-registration.d.ts +10 -8
  51. package/dist/ir-to-client-js/emit-registration.d.ts.map +1 -1
  52. package/dist/ir-to-client-js/generate-init.d.ts.map +1 -1
  53. package/dist/ir-to-client-js/html-template.d.ts +0 -9
  54. package/dist/ir-to-client-js/html-template.d.ts.map +1 -1
  55. package/dist/ir-to-client-js/identifiers.d.ts +6 -8
  56. package/dist/ir-to-client-js/identifiers.d.ts.map +1 -1
  57. package/dist/ir-to-client-js/imports.d.ts +23 -2
  58. package/dist/ir-to-client-js/imports.d.ts.map +1 -1
  59. package/dist/ir-to-client-js/phases/props-extraction.d.ts +6 -3
  60. package/dist/ir-to-client-js/phases/props-extraction.d.ts.map +1 -1
  61. package/dist/ir-to-client-js/plan/static-array-child-init.d.ts +8 -0
  62. package/dist/ir-to-client-js/plan/static-array-child-init.d.ts.map +1 -1
  63. package/dist/ir-to-client-js/prune-unused-prop-extractions.d.ts +1 -1
  64. package/dist/ir-to-client-js/prune-unused-prop-extractions.d.ts.map +1 -1
  65. package/dist/ir-to-client-js/reactivity.d.ts.map +1 -1
  66. package/dist/ir-to-client-js/rewrite-destructured-props.d.ts +1 -1
  67. package/dist/ir-to-client-js/rewrite-destructured-props.d.ts.map +1 -1
  68. package/dist/ir-to-client-js/rewrite-props-object.d.ts.map +1 -1
  69. package/dist/ir-to-client-js/safe-html.d.ts +20 -2
  70. package/dist/ir-to-client-js/safe-html.d.ts.map +1 -1
  71. package/dist/ir-to-client-js/stringify/static-array-child-init.d.ts +1 -0
  72. package/dist/ir-to-client-js/stringify/static-array-child-init.d.ts.map +1 -1
  73. package/dist/ir-to-client-js/types.d.ts +3 -3
  74. package/dist/ir-to-client-js/types.d.ts.map +1 -1
  75. package/dist/ir-to-client-js/utils.d.ts +2 -11
  76. package/dist/ir-to-client-js/utils.d.ts.map +1 -1
  77. package/dist/jsx-to-ir.d.ts.map +1 -1
  78. package/dist/nullable-signal-attr.d.ts +40 -10
  79. package/dist/nullable-signal-attr.d.ts.map +1 -1
  80. package/dist/prop-rewrite.d.ts +35 -8
  81. package/dist/prop-rewrite.d.ts.map +1 -1
  82. package/dist/props-binding.d.ts +66 -1
  83. package/dist/props-binding.d.ts.map +1 -1
  84. package/dist/scanner/js-scanner.d.ts.map +1 -1
  85. package/dist/scanner/js-scanner.js +30 -2
  86. package/dist/scope/binding-scope.d.ts +30 -2
  87. package/dist/scope/binding-scope.d.ts.map +1 -1
  88. package/dist/scope/lexical-scope-walk.d.ts +26 -0
  89. package/dist/scope/lexical-scope-walk.d.ts.map +1 -0
  90. package/dist/signal-prop-name-collision.d.ts +6 -5
  91. package/dist/signal-prop-name-collision.d.ts.map +1 -1
  92. package/dist/ssr-defaults.d.ts +28 -0
  93. package/dist/ssr-defaults.d.ts.map +1 -1
  94. package/dist/ssr-seed-plan.d.ts +39 -14
  95. package/dist/ssr-seed-plan.d.ts.map +1 -1
  96. package/dist/types.d.ts +133 -19
  97. package/dist/types.d.ts.map +1 -1
  98. package/dist/value-references.d.ts +21 -0
  99. package/dist/value-references.d.ts.map +1 -1
  100. package/package.json +2 -2
  101. package/src/__tests__/__snapshots__/doc-examples.test.ts.snap +18 -18
  102. package/src/__tests__/adapter-output.test.ts +5 -3
  103. package/src/__tests__/analyzer.test.ts +33 -0
  104. package/src/__tests__/arithmetic-lowering.test.ts +48 -0
  105. package/src/__tests__/binding-scope.test.ts +29 -0
  106. package/src/__tests__/children-read.test.ts +226 -0
  107. package/src/__tests__/client-template-escape-soundness.test.ts +31 -1
  108. package/src/__tests__/component-props.test.ts +68 -1
  109. package/src/__tests__/constant-inlining-tree.test.ts +136 -0
  110. package/src/__tests__/create-query.test.ts +1 -1
  111. package/src/__tests__/destructure-default-reads-earlier-param.test.ts +138 -0
  112. package/src/__tests__/dsl-template-adapter.test.ts +173 -0
  113. package/src/__tests__/emit-to-string-call.test.ts +58 -0
  114. package/src/__tests__/event-handler-verbatim.test.ts +73 -0
  115. package/src/__tests__/expression-parser.test.ts +1 -44
  116. package/src/__tests__/loop-param-accessor-key-member-safety.test.ts +90 -31
  117. package/src/__tests__/loop-plan.test.ts +131 -1
  118. package/src/__tests__/loop-row-child-children-handler.test.ts +129 -0
  119. package/src/__tests__/loop-row-child-children-inner-loop-shadow.test.ts +74 -0
  120. package/src/__tests__/loop-row-child-children-ref.test.ts +117 -0
  121. package/src/__tests__/nullable-signal-attr.test.ts +67 -3
  122. package/src/__tests__/props-alias-const.test.ts +60 -1
  123. package/src/__tests__/props-named-callback-param.test.ts +256 -0
  124. package/src/__tests__/reference-graph-identifiers.test.ts +161 -0
  125. package/src/__tests__/renamed-body-destructure-template.test.ts +86 -0
  126. package/src/__tests__/rewrite-props-object.test.ts +90 -0
  127. package/src/__tests__/runtime-import-detection.test.ts +134 -0
  128. package/src/__tests__/signal-prop-name-collision.test.ts +30 -0
  129. package/src/__tests__/ssr-defaults.test.ts +19 -1
  130. package/src/__tests__/ssr-seed-plan.test.ts +119 -0
  131. package/src/__tests__/style-object-plan.test.ts +54 -0
  132. package/src/__tests__/written-binding-substitution.test.ts +430 -0
  133. package/src/__tests__/zero-param-helper-inline.test.ts +57 -0
  134. package/src/adapters/callback-method.ts +48 -10
  135. package/src/adapters/component-props.ts +130 -12
  136. package/src/adapters/dsl-template-adapter.ts +259 -0
  137. package/src/adapters/jsx-adapter.ts +12 -6
  138. package/src/adapters/literal-value.ts +2 -2
  139. package/src/adapters/loop-plan.ts +201 -13
  140. package/src/adapters/parsed-expr-emitter.ts +67 -0
  141. package/src/adapters/style-object.ts +61 -0
  142. package/src/analyzer.ts +396 -16
  143. package/src/assignment-target.ts +79 -0
  144. package/src/children-nullish.ts +33 -0
  145. package/src/debug.ts +2 -2
  146. package/src/errors.ts +23 -0
  147. package/src/expression-parser.ts +56 -53
  148. package/src/free-refs.ts +28 -17
  149. package/src/index.ts +31 -10
  150. package/src/ir-to-client-js/compute-inlinability.ts +35 -5
  151. package/src/ir-to-client-js/control-flow/plan/build-component-loop.ts +21 -5
  152. package/src/ir-to-client-js/control-flow/plan/event-collision.ts +2 -1
  153. package/src/ir-to-client-js/control-flow/plan/insert.ts +2 -2
  154. package/src/ir-to-client-js/control-flow/plan/loop.ts +25 -1
  155. package/src/ir-to-client-js/control-flow/shared.ts +41 -3
  156. package/src/ir-to-client-js/control-flow/stringify/component-loop.ts +23 -3
  157. package/src/ir-to-client-js/control-flow/stringify/event-delegation.ts +3 -2
  158. package/src/ir-to-client-js/control-flow/stringify/event-listener.ts +13 -12
  159. package/src/ir-to-client-js/csr-substitute.ts +82 -24
  160. package/src/ir-to-client-js/emit-reactive.ts +3 -3
  161. package/src/ir-to-client-js/emit-registration.ts +34 -58
  162. package/src/ir-to-client-js/generate-init.ts +17 -1
  163. package/src/ir-to-client-js/html-template.ts +48 -57
  164. package/src/ir-to-client-js/identifiers.ts +75 -24
  165. package/src/ir-to-client-js/imports.ts +56 -19
  166. package/src/ir-to-client-js/index.ts +2 -1
  167. package/src/ir-to-client-js/phases/event-handlers.ts +2 -2
  168. package/src/ir-to-client-js/phases/props-extraction.ts +39 -17
  169. package/src/ir-to-client-js/plan/build-declaration-emit.ts +2 -2
  170. package/src/ir-to-client-js/plan/build-static-array-child-init.ts +7 -0
  171. package/src/ir-to-client-js/plan/static-array-child-init.ts +8 -0
  172. package/src/ir-to-client-js/prune-unused-prop-extractions.ts +7 -4
  173. package/src/ir-to-client-js/reactivity.ts +2 -2
  174. package/src/ir-to-client-js/rewrite-destructured-props.ts +22 -5
  175. package/src/ir-to-client-js/rewrite-props-object.ts +14 -8
  176. package/src/ir-to-client-js/safe-html.ts +29 -35
  177. package/src/ir-to-client-js/stringify/static-array-child-init.ts +4 -1
  178. package/src/ir-to-client-js/types.ts +3 -2
  179. package/src/ir-to-client-js/utils.ts +42 -122
  180. package/src/jsx-to-ir.ts +310 -90
  181. package/src/nullable-signal-attr.ts +149 -33
  182. package/src/prop-rewrite.ts +72 -72
  183. package/src/props-binding.ts +90 -3
  184. package/src/scanner/__tests__/js-scanner.test.ts +37 -0
  185. package/src/scanner/js-scanner.ts +64 -4
  186. package/src/scope/binding-scope.ts +34 -3
  187. package/src/scope/lexical-scope-walk.ts +167 -0
  188. package/src/signal-prop-name-collision.ts +50 -24
  189. package/src/ssr-defaults.ts +47 -20
  190. package/src/ssr-seed-plan.ts +103 -23
  191. package/src/types.ts +140 -20
  192. package/src/value-references.ts +132 -0
package/src/errors.ts CHANGED
@@ -127,6 +127,14 @@ export const ErrorCodes = {
127
127
  // adapter including Hono. See `format-date-refusal.ts`.
128
128
  FORMAT_DATE_AUTHORED_CALL: 'BF056',
129
129
 
130
+ // A module-level declaration or a value import binds the name of a
131
+ // `@barefootjs/client/runtime` helper (`insert`, `hydrate`, `qsa`, …) and
132
+ // the compiled client JS calls that name (#3537). The call may be the
133
+ // compiler's own, which the user's binding would capture. Before import
134
+ // detection resolved scopes, this shape emitted the binding next to a
135
+ // runtime import of the same name: a duplicate-declaration SyntaxError.
136
+ RUNTIME_HELPER_NAME_COLLISION: 'BF057',
137
+
130
138
  // Init statement errors (BF052)
131
139
  UNDECLARED_INIT_STATEMENT_REFERENCE: 'BF052',
132
140
 
@@ -173,6 +181,15 @@ export const ErrorCodes = {
173
181
  // back to its row, so its delegated event handlers would stop running
174
182
  // after hydration (#3318). A keyed top-level row is supported.
175
183
  ROW_PORTAL_UNPAIRABLE: 'BF064',
184
+ // A `'use client'` component's markup writes a component binding while it
185
+ // renders (`{++nextId}`, a `.map()` row incrementing a counter, a
186
+ // callback any call in the markup may run in place), outside a function
187
+ // the markup hands on (an attribute / prop value, or a wrapped event
188
+ // handler; `markupTiming`). The client template runs at module scope
189
+ // and cannot write the binding, and init re-evaluates only reactive
190
+ // positions, so a client-side mount would silently lose the written
191
+ // value. Refused instead (`markWrittenBindings`, analyzer.ts).
192
+ STAGE_WRITE_IN_MARKUP: 'BF065',
176
193
 
177
194
  // Inline JSX-callback synthesis errors (BF080-BF089) — raised by the
178
195
  // preprocess-inline-jsx-callbacks pass (#1211) when an inline JSX-
@@ -281,6 +298,10 @@ const errorMessages: Record<ErrorCode, string> = {
281
298
  [ErrorCodes.FORMAT_DATE_AUTHORED_CALL]:
282
299
  'formatDate cannot be called directly — it is compiler ABI, not an authored API.',
283
300
 
301
+ [ErrorCodes.RUNTIME_HELPER_NAME_COLLISION]:
302
+ 'This module-level name is also a BarefootJS runtime helper, and the compiled client JS calls it. ' +
303
+ 'Rename the declaration, or import it under an alias.',
304
+
284
305
  [ErrorCodes.BUILTIN_REQUIRES_IMPORT]:
285
306
  "Built-in <Async> / <Region> must be imported from '@barefootjs/client'. " +
286
307
  'The compiler recognises these tags by their import (not by tag name), ' +
@@ -308,6 +329,8 @@ const errorMessages: Record<ErrorCode, string> = {
308
329
 
309
330
  [ErrorCodes.ROW_PORTAL_UNPAIRABLE]:
310
331
  'A ref callback portals an element out of a .map() row that hydration cannot pair with the element (the row root itself, a nested or unkeyed loop, an element inside a reactive conditional in the row, or an element inside a child component\'s children), so its event handlers would stop running after hydration.',
332
+ [ErrorCodes.STAGE_WRITE_IN_MARKUP]:
333
+ "A client component's markup writes a component binding while it renders (an assignment or ++/-- outside an event handler), which the client template cannot reproduce.",
311
334
 
312
335
  [ErrorCodes.INLINE_JSX_CALLBACK_CAPTURE]:
313
336
  "Inline JSX-returning arrow function captures a non-module identifier. Extract the callback into a top-level 'use client' component (e.g. `function MyNode(n) { return <div/> }` then `renderNode={MyNode}`) or pass captured values via component props.",
@@ -61,8 +61,10 @@ export type ParsedExpr =
61
61
  // callbacks (`.filter`/`.sort`/`.reduce`/`.flatMap`) arrive as a generic
62
62
  // `call` whose argument is this kind; the adapter serializes `body` to the
63
63
  // runtime evaluator (#2018). Block bodies with locals / multiple statements,
64
- // and array-binding-pattern params, stay `unsupported`.
65
- | { kind: 'arrow'; params: string[]; body: ParsedExpr }
64
+ // and array-binding-pattern params, stay `unsupported`. `callKind` marks an
65
+ // async arrow / function or a generator function: calling one returns a
66
+ // Promise or an iterator, not `body`'s value (#3562 review).
67
+ | { kind: 'arrow'; params: string[]; body: ParsedExpr; callKind?: 'async' | 'generator' }
66
68
  // A regex literal carried as its exact source text (`/\/+$/`), so the Go
67
69
  // ctor lowering matches the one trailing-slash-strip pattern it recognises
68
70
  // (`String.replace`). Outside that narrow surface a regex resolves to
@@ -707,10 +709,6 @@ export function parseProviderObjectLiteral(source: string): ProviderObjectMember
707
709
  * either a static string literal or a raw JS expression for the adapter to
708
710
  * lower (`color` → its template interpolation).
709
711
  */
710
- export type StyleObjectEntry =
711
- | { cssKey: string; kind: 'literal'; value: string }
712
- | { cssKey: string; kind: 'expr'; expr: string }
713
-
714
712
  /** camelCase → kebab-case for CSS property names (`backgroundColor` →
715
713
  * `background-color`, `WebkitTransform` → `-webkit-transform`). The `ms`
716
714
  * vendor prefix is lowercase in React style keys (`msTransform`) yet the CSS
@@ -772,40 +770,6 @@ export function hasUnsafeStyleValue(value: string): boolean {
772
770
  return quote !== 0 || blockStack.length !== 0 // unterminated quote/bracket
773
771
  }
774
772
 
775
- /**
776
- * Parse a JSX `style={{ … }}` object-literal source into CSS entries, or
777
- * `null` when the shape isn't a plain object of static-keyed properties
778
- * (spread, computed key, shorthand, method, getter) — the adapter then keeps
779
- * refusing it. A bare `{…}` parses as a block statement, so the source is
780
- * wrapped in parens to force expression context. Used by the template adapters
781
- * to lower `style={{ backgroundColor: color, padding: '8px' }}` to a CSS
782
- * string instead of emitting BF101.
783
- */
784
- export function parseStyleObjectEntries(source: string): StyleObjectEntry[] | null {
785
- const sf = ts.createSourceFile('__style__.ts', `(${source})`, ts.ScriptTarget.Latest, true)
786
- const stmt = sf.statements[0]
787
- if (!stmt || !ts.isExpressionStatement(stmt) || sf.statements.length !== 1) return null
788
- let expr: ts.Expression = stmt.expression
789
- while (ts.isParenthesizedExpression(expr)) expr = expr.expression
790
- if (!ts.isObjectLiteralExpression(expr)) return null
791
- const entries: StyleObjectEntry[] = []
792
- for (const prop of expr.properties) {
793
- if (!ts.isPropertyAssignment(prop)) return null // shorthand/spread/method/getter
794
- let key: string
795
- if (ts.isIdentifier(prop.name)) key = prop.name.text
796
- else if (ts.isStringLiteral(prop.name)) key = prop.name.text
797
- else return null // computed / numeric key
798
- const cssKey = cssKebabCase(key)
799
- const init = prop.initializer
800
- if (ts.isStringLiteral(init) || ts.isNoSubstitutionTemplateLiteral(init)) {
801
- entries.push({ cssKey, kind: 'literal', value: init.text })
802
- } else {
803
- entries.push({ cssKey, kind: 'expr', expr: init.getText(sf).trim() })
804
- }
805
- }
806
- return entries.length > 0 ? entries : null
807
- }
808
-
809
773
  /**
810
774
  * Parse a JavaScript expression string into a ParsedExpr tree.
811
775
  */
@@ -1159,6 +1123,7 @@ function convertNode(node: ts.Node, raw: string): ParsedExpr {
1159
1123
  // a generic `call` whose argument is this kind; the adapter serializes
1160
1124
  // `body` to the runtime evaluator.
1161
1125
  if (ts.isArrowFunction(node) || ts.isFunctionExpression(node)) {
1126
+ const callKind = arrowCallKind(node)
1162
1127
  // Resolve the body expression: an expression-bodied arrow carries it
1163
1128
  // directly; a block body (arrow `=> { … }` or a function expression)
1164
1129
  // must reduce to exactly one `return <expr>;`. Multi-statement /
@@ -1287,7 +1252,7 @@ function convertNode(node: ts.Node, raw: string): ParsedExpr {
1287
1252
  }
1288
1253
  const syntheticParam = pickSyntheticParam(fieldMap, body)
1289
1254
  const rewritten = substituteDestructuredFields(body, fieldMap, syntheticParam, restName)
1290
- return { kind: 'arrow', params: [syntheticParam], body: rewritten }
1255
+ return { kind: 'arrow', params: [syntheticParam], body: rewritten, ...callKind }
1291
1256
  }
1292
1257
 
1293
1258
  // Every (remaining) parameter must be a plain identifier. Multi-param
@@ -1300,7 +1265,7 @@ function convertNode(node: ts.Node, raw: string): ParsedExpr {
1300
1265
  }
1301
1266
  params.push(p.name.text)
1302
1267
  }
1303
- return { kind: 'arrow', params, body }
1268
+ return { kind: 'arrow', params, body, ...callKind }
1304
1269
  }
1305
1270
 
1306
1271
  // Default: unsupported
@@ -2961,6 +2926,30 @@ function usesPerPath(name: string, expr: ParsedExpr): { min: number; max: number
2961
2926
  return walk(expr)
2962
2927
  }
2963
2928
 
2929
+ /** `{ callKind }` for an async or generator function, else nothing (see the `arrow` kind). */
2930
+ function arrowCallKind(node: ts.ArrowFunction | ts.FunctionExpression): { callKind?: 'async' | 'generator' } {
2931
+ if (ts.isFunctionExpression(node) && node.asteriskToken) return { callKind: 'generator' }
2932
+ if (node.modifiers?.some(m => m.kind === ts.SyntaxKind.AsyncKeyword)) return { callKind: 'async' }
2933
+ return {}
2934
+ }
2935
+
2936
+ /**
2937
+ * The value a call of `value` with no arguments evaluates to, when that is
2938
+ * just its body: a zero-param, synchronous, non-generator arrow whose body
2939
+ * is a pure value expression. Null otherwise (an async call returns a
2940
+ * Promise, a generator an iterator, and a body that mutates state, like
2941
+ * `++nextId`, must run where it is declared).
2942
+ */
2943
+ export function zeroArgCallBody(value: ParsedExpr): ParsedExpr | null {
2944
+ if (value.kind !== 'arrow' || value.params.length !== 0 || value.callKind) return null
2945
+ return isSupportedValue(value.body).supported ? value.body : null
2946
+ }
2947
+
2948
+ /** `name()` with no arguments, where `name` is not shadowed by an enclosing param. */
2949
+ function isBareCallOf(e: Extract<ParsedExpr, { kind: 'call' }>, name: string, enclosing: ReadonlySet<string>): boolean {
2950
+ return e.args.length === 0 && e.callee.kind === 'identifier' && e.callee.name === name && !enclosing.has(name)
2951
+ }
2952
+
2964
2953
  /**
2965
2954
  * Inline `name → value` everywhere it appears free in `expr` (the let-inline
2966
2955
  * step). Returns `null` if the substitution would capture a free variable of
@@ -2989,6 +2978,27 @@ export function inlineBinding(
2989
2978
  const valueFree = new Set<string>()
2990
2979
  collectIdentifiers(value, valueFree)
2991
2980
  let captured = false
2981
+ // A zero-param arrow (`const isWide = () => props.mode === 'wide'`) called
2982
+ // with no arguments inlines as its body, so `isWide()` reads what the call
2983
+ // returns (#3562; `zeroArgCallBody` says which arrows qualify). Calling it
2984
+ // evaluates the body in the same scope the substitution resolves it in;
2985
+ // the capture check covers the body's free variables, which are `value`'s.
2986
+ const callBody = zeroArgCallBody(value)
2987
+ // Inlining here: does any enclosing param capture a free var of `value`?
2988
+ const capturesValueFree = (enclosing: ReadonlySet<string>): boolean => {
2989
+ for (const p of enclosing) {
2990
+ if (valueFree.has(p)) {
2991
+ captured = true
2992
+ return true
2993
+ }
2994
+ }
2995
+ return false
2996
+ }
2997
+
2998
+ const walkCall = (e: Extract<ParsedExpr, { kind: 'call' }>, enclosing: ReadonlySet<string>): ParsedExpr => {
2999
+ if (callBody && isBareCallOf(e, name, enclosing)) return capturesValueFree(enclosing) ? e : callBody
3000
+ return { kind: 'call', callee: walk(e.callee, enclosing), args: e.args.map(a => walk(a, enclosing)) }
3001
+ }
2992
3002
 
2993
3003
  const walk = (e: ParsedExpr, enclosing: ReadonlySet<string>): ParsedExpr => {
2994
3004
  switch (e.kind) {
@@ -2997,17 +3007,10 @@ export function inlineBinding(
2997
3007
  // Shadowed by an enclosing callback param → this is the parameter, not
2998
3008
  // the binding; leave it.
2999
3009
  if (enclosing.has(e.name)) return e
3000
- // Inlining here: does any enclosing param capture a free var of `value`?
3001
- for (const p of enclosing) {
3002
- if (valueFree.has(p)) {
3003
- captured = true
3004
- return e
3005
- }
3006
- }
3007
- return value
3010
+ return capturesValueFree(enclosing) ? e : value
3008
3011
  }
3009
3012
  case 'call':
3010
- return { kind: 'call', callee: walk(e.callee, enclosing), args: e.args.map(a => walk(a, enclosing)) }
3013
+ return walkCall(e, enclosing)
3011
3014
  case 'member':
3012
3015
  return { kind: 'member', object: walk(e.object, enclosing), property: e.property, computed: e.computed, optional: e.optional }
3013
3016
  case 'index-access':
@@ -3029,7 +3032,7 @@ export function inlineBinding(
3029
3032
  }
3030
3033
  case 'arrow': {
3031
3034
  const innerEnclosing = e.params.length === 0 ? enclosing : new Set([...enclosing, ...e.params])
3032
- return { kind: 'arrow', params: e.params, body: walk(e.body, innerEnclosing) }
3035
+ return { ...e, body: walk(e.body, innerEnclosing) }
3033
3036
  }
3034
3037
  case 'array-literal':
3035
3038
  return { kind: 'array-literal', elements: e.elements.map(el => walk(el, enclosing)) }
@@ -3425,7 +3428,7 @@ export function materializeGetterCalls(expr: ParsedExpr, names: ReadonlySet<stri
3425
3428
  properties: expr.properties.map(p => (p.kind === 'spread' ? { ...p, expr: rw(p.expr) } : { ...p, value: rw(p.value) })),
3426
3429
  }
3427
3430
  case 'arrow':
3428
- return { kind: 'arrow', params: expr.params, body: rw(expr.body) }
3431
+ return { ...expr, body: rw(expr.body) }
3429
3432
  // Leaves / opaque shapes — nothing to rewrite.
3430
3433
  case 'identifier':
3431
3434
  case 'literal':
package/src/free-refs.ts CHANGED
@@ -23,6 +23,7 @@ import type {
23
23
  ConstantInfo,
24
24
  FunctionInfo,
25
25
  } from './types.ts'
26
+ import { isChildrenPropParam } from './types.ts'
26
27
  import { isReactiveType } from './reactivity-checker.ts'
27
28
  import { incrementCounter } from './instrumentation.ts'
28
29
 
@@ -36,6 +37,12 @@ export interface BindingEnvironment {
36
37
  memos: readonly MemoInfo[]
37
38
  propsParams: readonly ParamInfo[]
38
39
  propsObjectName: string | null
40
+ /**
41
+ * Component-scope consts that alias the props object (`const p = props`,
42
+ * through any number of hops). A `.children` read through one of them is
43
+ * the children prop, the same as `props.children` (#3572).
44
+ */
45
+ propsObjectAliases?: ReadonlySet<string>
39
46
  restPropsName: string | null
40
47
  localConstants: readonly ConstantInfo[]
41
48
  localFunctions: readonly FunctionInfo[]
@@ -106,7 +113,7 @@ function buildBindingMap(env: BindingEnvironment): Map<string, BindingKind> {
106
113
  // the OR-combined `reactive` flag promotes it to a text slot,
107
114
  // breaking SSR hydration on every UI component that forwards
108
115
  // children.
109
- if (p.name === 'children') continue
116
+ if (isChildrenPropParam(p)) continue
110
117
  map.set(p.name, 'prop')
111
118
  }
112
119
  if (env.propsObjectName !== null) {
@@ -298,6 +305,25 @@ function resolveConstantInitializerRefs(
298
305
  * the transitive-taint expansion path. `visited` tracks identifier names
299
306
  * already expanded to break cycles like `const a = b; const b = a`.
300
307
  */
308
+ /**
309
+ * `props.children` is rendered into the server-side HTML (it is the child
310
+ * slot, not a reactive value). The `props` identifier is a non-reactive
311
+ * reference *only* in this position, so consumers don't wrap the
312
+ * surrounding expression in createEffect just because it touches `props`.
313
+ * Matches the legacy `isPropsReference` semantics. A const alias of the
314
+ * props object (`const p = props; p.children`) reads the same prop (#3572).
315
+ */
316
+ function isPropsChildrenRead(ident: ts.Identifier, env: BindingEnvironment): boolean {
317
+ if (env.propsObjectName !== ident.text && !env.propsObjectAliases?.has(ident.text)) return false
318
+ const parent = ident.parent
319
+ return (
320
+ !!parent &&
321
+ ts.isPropertyAccessExpression(parent) &&
322
+ parent.expression === ident &&
323
+ parent.name.text === 'children'
324
+ )
325
+ }
326
+
301
327
  function resolveFreeRefsInternal(
302
328
  node: ts.Node,
303
329
  env: BindingEnvironment,
@@ -312,22 +338,7 @@ function resolveFreeRefsInternal(
312
338
  for (const ident of idents) {
313
339
  const name = ident.text
314
340
 
315
- // `props.children` is rendered into the server-side HTML (it is the
316
- // child slot, not a reactive value). Treat the `props` identifier as
317
- // a non-reactive reference *only* in this position so consumers don't
318
- // wrap the surrounding expression in createEffect just because it
319
- // touches `props`. Matches the legacy `isPropsReference` semantics.
320
- if (env.propsObjectName === name) {
321
- const parent = ident.parent
322
- if (
323
- parent &&
324
- ts.isPropertyAccessExpression(parent) &&
325
- parent.expression === ident &&
326
- parent.name.text === 'children'
327
- ) {
328
- continue
329
- }
330
- }
341
+ if (isPropsChildrenRead(ident, env)) continue
331
342
 
332
343
  let kind: BindingKind | undefined = bindingMap.get(name)
333
344
 
package/src/index.ts CHANGED
@@ -20,6 +20,7 @@ export { isOpaqueLocalAccessorName } from './opaque-local-accessor.ts'
20
20
  // data props, not handlers. Shared by the IR builder, client-JS prop wiring
21
21
  // and the SSR adapters' "a handler has no SSR value" skips.
22
22
  export { isEventHandlerName } from './event-handler-name.ts'
23
+ export { fallbackChainParts, nullishChainParts } from './children-nullish.ts'
23
24
 
24
25
  // Shared props-destructure binding + alias-map helpers (#2524, #2788)
25
26
  export { propsDestructureBinding, buildPropAliasMap, isIdentifierName, resolveBodyDestructuredPropAliases } from './props-binding.ts'
@@ -38,11 +39,12 @@ export { resolveGetterAliases, collectAliasableGetterNames } from './ir-to-clien
38
39
  export { buildImportAliasMap } from './ir-to-client-js/component-scope.ts'
39
40
 
40
41
  // Backend-neutral SSR seed plan (in-template derived signal/memo seeding)
41
- export { computeSsrSeedPlan } from './ssr-seed-plan.ts'
42
+ export { computeSsrSeedPlan, inDefaultReadOrder } from './ssr-seed-plan.ts'
42
43
  export type { SsrSeedPlan, SsrSeedStep } from './ssr-seed-plan.ts'
43
44
 
44
45
  // Pure IR types
45
46
  export type {
47
+ JsSourceText,
46
48
  ComponentIR,
47
49
  IRNode,
48
50
  IRElement,
@@ -64,6 +66,7 @@ export type {
64
66
  AttrValue,
65
67
  LiteralAttr,
66
68
  ExpressionAttr,
69
+ TypedExprSource,
67
70
  BooleanAttr,
68
71
  BooleanShorthandAttr,
69
72
  TemplateAttr,
@@ -72,6 +75,8 @@ export type {
72
75
  IRTemplatePart,
73
76
  IRProp,
74
77
  ParamInfo,
78
+ PropDefaultPart,
79
+ PropDefaultRead,
75
80
  PropertyInfo,
76
81
  MemoInfo,
77
82
  ConstantInfo,
@@ -87,7 +92,7 @@ export type {
87
92
  RenderDivergences,
88
93
  ImportInfo,
89
94
  } from './types.ts'
90
- export { isElidedFactoryGetter } from './types.ts'
95
+ export { isElidedFactoryGetter, isChildrenPropParam } from './types.ts'
91
96
 
92
97
  // Analyzer
93
98
  export { analyzeComponent, listComponentFunctions, listComponentFunctions as listExportedComponents, scanComponentFile, createProgramForFile, createAnchoredProgram, needsTypeBasedDetection, resolveRelativeImportToFile, REACTIVE_PRIMITIVES, CLIENT_EXPORTS, BROWSER_ONLY_CLIENT_APIS, type AnalyzerContext, type ComponentFileScan } from './analyzer.ts'
@@ -102,6 +107,8 @@ export { generateModuleExports, extractFunctionParams, formatParamWithType, find
102
107
 
103
108
  // Adapters
104
109
  export { BaseAdapter } from './adapters/interface.ts'
110
+ export { DslTemplateAdapter } from './adapters/dsl-template-adapter.ts'
111
+ export type { TemplateIdentifierSpelling } from './adapters/dsl-template-adapter.ts'
105
112
  // Dependency-free adapter for tooling that only needs client JS (e.g. the
106
113
  // profiler scenario driver) — the client output is adapter-independent.
107
114
  export { TestAdapter, testAdapter } from './adapters/test-adapter.ts'
@@ -117,9 +124,10 @@ export type {
117
124
  export { JsxAdapter } from './adapters/jsx-adapter.ts'
118
125
  export type { JsxAdapterConfig } from './adapters/jsx-adapter.ts'
119
126
  export { rewriteImportsForTemplate, rewriteDynamicImportsInSource } from './adapters/template-imports.ts'
120
- export { emitParsedExpr, groupBinaryOperand, groupObjectLiteralSegments, isStringTypedOperand, isStringConcatBinary, isNumericArithmeticResult } from './adapters/parsed-expr-emitter.ts'
121
- export type { ParsedExprEmitter, LoweringEmitter, HigherOrderMethod, ArrayMethod, SortMethod, LiteralType } from './adapters/parsed-expr-emitter.ts'
127
+ export { emitParsedExpr, arithmeticHelper, groupBinaryOperand, groupUnaryOperand, groupObjectLiteralSegments, isStringTypedOperand, isStringConcatBinary, isNumericArithmeticResult } from './adapters/parsed-expr-emitter.ts'
128
+ export type { ArithmeticHelper, ParsedExprEmitter, LoweringEmitter, HigherOrderMethod, ArrayMethod, SortMethod, LiteralType } from './adapters/parsed-expr-emitter.ts'
122
129
  export { collectLoopBoundNames } from './adapters/loop-bound-names.ts'
130
+ export { planStyleObject, type StyleObjectPlanEntry } from './adapters/style-object.ts'
123
131
  export { filterCaptureCollisions } from './adapters/filter-capture-collisions.ts'
124
132
  export { templateNameCollisionErrors } from './adapters/template-name-collisions.ts'
125
133
  export {
@@ -144,7 +152,10 @@ export {
144
152
  emitCallbackEval,
145
153
  isPredicateMethod,
146
154
  lowerCallbackMethod,
155
+ lowerSortComparator,
147
156
  nestedCallbackRefusal,
157
+ filterPredicateShapeRefusal,
158
+ missingFilterPredicateRefusal,
148
159
  isUnloweredCall,
149
160
  unloweredCallRefusal,
150
161
  sortEvalPlan,
@@ -158,6 +169,7 @@ export type {
158
169
  CallbackLoweringOptions,
159
170
  CallbackPlan,
160
171
  PredicateMethod,
172
+ SortPlan,
161
173
  } from './adapters/callback-method.ts'
162
174
  export type {
163
175
  ArrayMethodArg,
@@ -169,14 +181,23 @@ export type {
169
181
  ArrayMethodSpelling,
170
182
  } from './adapters/array-method.ts'
171
183
  export { derivesScopeFromSlot } from './adapters/child-scope.ts'
172
- export { childTemplateName, componentPropKey, isEmptyComponentProps, planComponentProps, spellComponentProps } from './adapters/component-props.ts'
173
- export type { ComponentPropEntry, ComponentPropSegment, ComponentPropSpelling, ComponentPropsOptions, SpelledComponentPropSegment } from './adapters/component-props.ts'
184
+ export { childTemplateName, componentPropKey, isEmptyComponentProps, planComponentProps, propsSpreadParam, resolveComponentPropKeys, spellComponentProps } from './adapters/component-props.ts'
185
+ export type { ComponentPropEntry, ComponentPropSegment, ComponentPropSpelling, ComponentPropsOptions, ComponentPropsParam, EarlierComponentProps, ResolvedComponentProp, SpelledComponentPropSegment } from './adapters/component-props.ts'
174
186
  export { parseUndefinedAlternateTernary, planAttrExpression, planSpreadAttr, unsupportedAttrExpression, unsupportedAttrExpressionError } from './adapters/attr-plan.ts'
175
187
  export type { AttrExpressionPlan, AttrPlanContext, SpreadAttrPlan, SpreadPlanContext, UndefinedAlternateTernary } from './adapters/attr-plan.ts'
176
- export { planLoop } from './adapters/loop-plan.ts'
188
+ export { planLoop, spellDestructureLocals, spellFilteredRow, spellSortedSource } from './adapters/loop-plan.ts'
177
189
  export { computedConstContext, inlineComputedConstAttr, inlineComputedConsts } from './adapters/computed-const.ts'
178
190
  export type { ComputedConstContext } from './adapters/computed-const.ts'
179
- export type { LoopPlan, LoopPlanContext } from './adapters/loop-plan.ts'
191
+ export type {
192
+ DestructureSpelling,
193
+ DestructureValue,
194
+ LoopFilterPlan,
195
+ LoopFilterPredicate,
196
+ LoopFilterSpelling,
197
+ LoopPlan,
198
+ LoopPlanContext,
199
+ LoopSortSpelling,
200
+ } from './adapters/loop-plan.ts'
180
201
  export { evaluateStaticLiteral, isFullyStaticLiteral, resolveStaticLoopSource } from './static-literal.ts'
181
202
  export {
182
203
  arithmeticOperandIsNull,
@@ -184,6 +205,7 @@ export {
184
205
  arithmeticOperandCoercion,
185
206
  bareGetterCallName,
186
207
  attrValueMayBeNullish,
208
+ collectAbsentPropSeedReads,
187
209
  collectNullableSignalGetters,
188
210
  collectNullishAttrContext,
189
211
  isNullableSignal,
@@ -311,8 +333,7 @@ export { ErrorCodes, createError, formatError, generateCodeFrame } from './error
311
333
  export { isValueReferenceIdentifier, collectValueReferencedNames } from './value-references.ts'
312
334
 
313
335
  // Expression Parser
314
- export { parseExpression, tsNodeToParsedExpr, asCallbackMethodCall, hasOpaqueCall, unboundCallbackParamRead, unboundCallbackParamReason, CALLBACK_METHODS, sortComparatorFromArrow, serializeParsedExpr, freeVarsInBody, freeIdentifiers, renameFreeIdentifiers, materializeGetterCalls, isSupported, isSupportedValue, exprToString, stringifyParsedExpr, identifierPath, parseBlockBody, parseBlockBodyTolerant, foldBlockToExpr, predicateTernaryToLogical, containsHigherOrder, extractArrowBodyExpression, parseStyleObjectEntries, hasUnsafeStyleValue, parseProviderObjectLiteral, isFunctionShapedExpression, type ProviderObjectMember, type FoldBlockOptions } from './expression-parser.ts'
315
- export type { StyleObjectEntry } from './expression-parser.ts'
336
+ export { parseExpression, tsNodeToParsedExpr, asCallbackMethodCall, hasOpaqueCall, unboundCallbackParamRead, unboundCallbackParamReason, CALLBACK_METHODS, sortComparatorFromArrow, serializeParsedExpr, freeVarsInBody, freeIdentifiers, renameFreeIdentifiers, materializeGetterCalls, isSupported, isSupportedValue, exprToString, stringifyParsedExpr, identifierPath, parseBlockBody, parseBlockBodyTolerant, foldBlockToExpr, predicateTernaryToLogical, containsHigherOrder, extractArrowBodyExpression, hasUnsafeStyleValue, parseProviderObjectLiteral, isFunctionShapedExpression, type ProviderObjectMember, type FoldBlockOptions } from './expression-parser.ts'
316
337
  export { literalMemberIndex } from './literal-member-index.ts'
317
338
  export { PARSED_EXPR_KINDS, ARRAY_METHOD_NAMES, SORT_KEY_TYPES, SORT_KEY_TARGETS, SORT_KEY_DIRECTIONS } from './expression-parser.ts'
318
339
  export type { ParsedExpr, ObjectLiteralProperty, ParsedStatement, SortComparator, SortKey, FlatDepth, SupportLevel, SupportResult, TemplatePart } from './expression-parser.ts'
@@ -30,6 +30,7 @@ import { extractIdentifiers, extractTemplateIdentifiers } from './identifiers.ts
30
30
  import { isInlinableInTemplate, buildRelocateEnvFromIR } from '../relocate.ts'
31
31
  import type { RelocateEnv, RelocateDecision } from '../relocate.ts'
32
32
  import { createError, ErrorCodes } from '../errors.ts'
33
+ import { zeroArgCallBody } from '../expression-parser.ts'
33
34
  import { attrValueToString } from './utils.ts'
34
35
  import { walkIR, type IRVisitor } from './walker.ts'
35
36
  import { buildSignalMemoEnv, csrSubstitute, resolveGetterAliases, type CsrEnv, type CsrSubstitution } from './csr-substitute.ts'
@@ -368,7 +369,10 @@ export function computeInlinability(
368
369
  * in which case it gets an identity entry (`rewrittenValue: name`)
369
370
  * instead of `null` — the compiled bundle declares the const at
370
371
  * module scope too, so referencing it by its own bare name from the
371
- * CSR template is exactly as safe as a `module-scope-safe` function
372
+ * CSR template is exactly as safe as a `module-scope-safe` function.
373
+ * A zero-param arrow helper (`() => props.mode === 'wide'`) is not
374
+ * marked here either: it is substituted like any other value, so a
375
+ * template call `isWide()` reads its body (#3562)
372
376
  * - it's a system construct (`createContext`, `new WeakMap`)
373
377
  * - it's a JSX literal (handled by jsx-inline routing)
374
378
  * - it's a bare alias-hop chain naming a signal/memo getter (`getterAliases`)
@@ -437,7 +441,12 @@ function populateCsrInlinable(
437
441
  finalised.add(c.name)
438
442
  continue
439
443
  }
440
- if (c.isJsx || !c.value || c.containsArrow || c.systemConstructKind || c.mutatedAfterDeclaration || getterAliases.has(c.name)) {
444
+ // A zero-param helper (`const isWide = () => props.mode === 'wide'`) goes
445
+ // through the substitution below like any other const: `isWide()` then
446
+ // reads `(() => props.mode === 'wide')()` in template scope, so a seed
447
+ // or attribute that calls it renders its value instead of the empty
448
+ // fallback (#3562).
449
+ if (hasNoCsrSubstitute(c) || getterAliases.has(c.name)) {
441
450
  ctx.csrInlinable.set(c.name, null)
442
451
  finalised.add(c.name)
443
452
  }
@@ -471,7 +480,7 @@ function populateCsrInlinable(
471
480
  // sees `props.X` and can detect bridged-arg calls. The final
472
481
  // emit-time substitution applies the bare-prop rewrite.
473
482
  const source = c.value!.trim()
474
- const { rewritten, freeIdentifiers } = csrSubstitute(source, env)
483
+ const { rewritten, freeIdentifiers, writes } = csrSubstitute(source, env)
475
484
 
476
485
  // If the rewrite still references any unresolved local constant
477
486
  // by name, defer to a later iteration — its substitution may
@@ -496,7 +505,7 @@ function populateCsrInlinable(
496
505
  // `rewritePropsObjectRef` doesn't need to redo the AST work. The
497
506
  // free identifiers are re-extracted from the bridged form so
498
507
  // the post-substitution unsafe-name check stays exact.
499
- const bridgedRewritten = bridgedCsrForm(rewritten, source, env, relocateEnv, receivers)
508
+ const bridgedRewritten = bridgedCsrForm(rewritten, writes, source, env, relocateEnv, receivers)
500
509
  if (bridgedRewritten === null) {
501
510
  ctx.csrInlinable.set(c.name, null)
502
511
  } else {
@@ -523,17 +532,38 @@ function populateCsrInlinable(
523
532
  }
524
533
  }
525
534
 
535
+ /**
536
+ * A const whose value is a zero-param, synchronous arrow with a pure value
537
+ * body (`() => props.mode === 'wide'`, see `zeroArgCallBody`): calling it
538
+ * only reads the names its body reads, so splicing the arrow into template
539
+ * scope is as safe as splicing that body, which the substitution's own
540
+ * template-safety check decides. A body that mutates state
541
+ * (`() => ({ id: ++nextId })`) must run where it is declared.
542
+ */
543
+ function isZeroParamArrowHelper(c: ConstantInfo): boolean {
544
+ return c.parsed !== undefined && zeroArgCallBody(c.parsed) !== null
545
+ }
546
+
547
+ /** A const with no value this pass can substitute (see `populateCsrInlinable`). */
548
+ function hasNoCsrSubstitute(c: ConstantInfo): boolean {
549
+ const containsUnsplicedArrow = c.containsArrow && !isZeroParamArrowHelper(c)
550
+ return Boolean(c.isJsx || !c.value || containsUnsplicedArrow || c.systemConstructKind || c.mutatedAfterDeclaration)
551
+ }
552
+
526
553
  /**
527
554
  * The bridged CSR form of a const whose substituted text is `rewritten`, or
528
- * null when it isn't safe in template scope.
555
+ * null when it isn't safe in template scope. A value that writes a binding
556
+ * (`writes`, see `csrSubstitute`) runs only where it is declared.
529
557
  */
530
558
  function bridgedCsrForm(
531
559
  rewritten: string,
560
+ writes: ReadonlySet<string>,
532
561
  source: string,
533
562
  env: CsrEnv,
534
563
  relocateEnv: RelocateEnv,
535
564
  receivers: ReturnType<typeof inlinedReceiverCheck>,
536
565
  ): string | null {
566
+ if (writes.size > 0) return null
537
567
  const inlineResult = isInlinableInTemplate(rewritten, relocateEnv)
538
568
  return inlineResult.ok ? inlineResult.rewrittenValue : receivers.check(source, env)
539
569
  }
@@ -28,6 +28,7 @@ import {
28
28
  buildChildRefBindings,
29
29
  hasReactiveLoopBindings,
30
30
  buildChildrenTextEffect,
31
+ buildRowEventBinding,
31
32
  } from '../shared.ts'
32
33
  import { irChildrenToJsExpr, renderPreamble } from '../../html-template.ts'
33
34
  import { buildReactiveEffectsPlan } from './build-reactive-effects.ts'
@@ -138,6 +139,18 @@ export function buildComponentLoopPlan(elem: TopLevelLoop, profileComponentName?
138
139
  : elem.bindings.reactiveTexts
139
140
  const hasReactiveEffects = hasReactiveLoopBindings({ ...elem.bindings, reactiveTexts: rowReactiveTexts })
140
141
 
142
+ // #3607: an event on an element forwarded as the root component's own
143
+ // `children` is collected into `elem.bindings.events` by the same
144
+ // `collectLoopChildBindings` walk as the reactive attrs/texts above, and
145
+ // was dropped here the same way they were before #3143. A component-root
146
+ // loop has no delegation pass (`loopEventDelegationVariant` returns null
147
+ // for it), so each row attaches its handlers directly, exactly like the
148
+ // composite row's `outerEvents`. Events inside an inner loop of the
149
+ // forwarded children (`nestedLoops` non-empty) are not reached here.
150
+ const rowEvents = elem.bindings.events
151
+ .filter(ev => ev.nestedLoops.length === 0)
152
+ .map(ev => buildRowEventBinding(ev, elem.param, elem.paramBindings, elem.index))
153
+
141
154
  return {
142
155
  kind: 'component',
143
156
  // Rows are createComponent-driven: a lowered HTML-string leaf passed as a
@@ -156,11 +169,14 @@ export function buildComponentLoopPlan(elem: TopLevelLoop, profileComponentName?
156
169
  componentPropsExpr: propsExpr,
157
170
  keyExpr,
158
171
  nestedComps,
159
- // Refs on a component element (`<Comp ref={fn} />`) are not currently
160
- // wired here — the body root is the component, not a DOM element, so
161
- // the per-item factory has no `__el` handle to invoke. Still required
162
- // by the type so the structural invariant (every variant has a
163
- // `childRefs`) is preserved; populated as empty.
172
+ rowEvents,
173
+ // #3612: refs on elements forwarded as the root component's own
174
+ // `children` (`<Chip><input ref={el => …} /></Chip>`), collected by the
175
+ // same `collectLoopChildBindings` walk as `rowEvents` above and resolved
176
+ // with the same loop-param accessor rewrite. Each row (hydrated and
177
+ // client-built) invokes them against its own element. A `ref` on the
178
+ // root component element itself (`<Chip ref={fn} />`) is a prop, not a
179
+ // binding here: it goes to the component through `componentPropsExpr`.
164
180
  childRefs: buildChildRefBindings(elem.bindings.refs, elem.param, elem.paramBindings, elem.index),
165
181
  profileLoopId: profileComponentName ? `${profileComponentName}#binding:${elem.slotId}` : undefined,
166
182
  reactiveEffects: hasReactiveEffects
@@ -20,13 +20,14 @@
20
20
 
21
21
  import type { InteractiveElement } from '../../types.ts'
22
22
  import { toDomEventName, NON_BUBBLING_EVENTS } from '../../utils.ts'
23
+ import type { JsSourceText } from '../../../types.ts'
23
24
 
24
25
  export interface ContainerOwnHandler {
25
26
  /** The container element's own slot id (used for profile-mode turn ids). */
26
27
  slotId: string
27
28
  /** Original (pre-DOM-mapped) event name, e.g. 'contextmenu'. */
28
29
  eventName: string
29
- handler: string
30
+ handler: JsSourceText
30
31
  }
31
32
 
32
33
  /**
@@ -6,7 +6,7 @@
6
6
  * `ArmBody.conditionals`, so one stringifier handles arbitrary depth.
7
7
  */
8
8
 
9
- import type { AttrMeta } from '../../../types.ts'
9
+ import type { AttrMeta, JsSourceText } from '../../../types.ts'
10
10
  import type { ScopeRef } from './common.ts'
11
11
  import type { BranchLoopPlan } from './branch-loop.ts'
12
12
 
@@ -84,7 +84,7 @@ export interface ArmEventBind {
84
84
  slotId: string
85
85
  eventName: string
86
86
  /** Handler source expression (already trimmed). The stringifier wraps it. */
87
- handler: string
87
+ handler: JsSourceText
88
88
  /** Profile-mode turn id (#1690, SR3); when set the listener is turn-wrapped. */
89
89
  turnId?: string
90
90
  }