@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
@@ -13,7 +13,8 @@ import type { ClientJsContext } from './types.ts'
13
13
  import { PROPS_PARAM, isCommentScopedRoot, initFunctionName } from './utils.ts'
14
14
  import { buildReferencesGraph } from './build-references.ts'
15
15
  import { computePropUsage } from './compute-prop-usage.ts'
16
- import { IMPORT_PLACEHOLDER, MODULE_CONSTANTS_PLACEHOLDER } from './imports.ts'
16
+ import { IMPORT_PLACEHOLDER, MODULE_CONSTANTS_PLACEHOLDER, runtimeNameCollisions } from './imports.ts'
17
+ import { signalSecondBinding } from '../signal-initializer.ts'
17
18
  import { emitRegistrationAndHydration, csrInlinableConstantsFromCtx } from './emit-registration.ts'
18
19
  import { computeDeferredChildSlots } from './html-template.ts'
19
20
  import { emitChildComponentImports } from './child-components.ts'
@@ -137,6 +138,21 @@ export function generateInitFunction(
137
138
  const codeWithModuleConstants = pruneUnusedPropExtractions(
138
139
  generatedCode.replace(MODULE_CONSTANTS_PLACEHOLDER, () => moduleConstantsCode),
139
140
  )
141
+ ctx.warnings.push(
142
+ ...runtimeNameCollisions(
143
+ [
144
+ ...classification.moduleLevelConstants,
145
+ ...classification.moduleLevelFunctions,
146
+ ...classification.moduleLevelSignals.flatMap(s => {
147
+ const second = signalSecondBinding(s)
148
+ return [{ name: s.getter, loc: s.loc }, ...(second ? [{ name: second, loc: s.loc }] : [])]
149
+ }),
150
+ ...classification.moduleLevelMemos,
151
+ ],
152
+ ir.metadata.imports,
153
+ codeWithModuleConstants,
154
+ ),
155
+ )
140
156
  const allImportLines = resolveFinalImports(codeWithModuleConstants, ir, localImportPrefixes)
141
157
 
142
158
  return codeWithModuleConstants.replace(IMPORT_PLACEHOLDER, () => allImportLines)
@@ -2,7 +2,7 @@
2
2
  * IR → HTML template string generation and validation.
3
3
  */
4
4
 
5
- import type { AttrValue, FlatMapCallback, IRAttribute, IRElement, IRExpression, IRNode, IRProp, MapCallbackPreamble } from '../types.ts'
5
+ import type { AttrValue, FlatMapCallback, IRAttribute, IRElement, IRExpression, IRNode, IRProp, MapCallbackPreamble, JsSourceText } from '../types.ts'
6
6
  import { isBooleanAttr } from '../html-constants.ts'
7
7
  import { toHtmlAttrName, attrValueToString, quotePropName, PROPS_PARAM, DATA_BF_PH, keyAttrName, loopStartMarker, loopEndMarker, loopItemMarker, freeIdsFromRefs, setIntersects, wrapExprWithLoopParams, specsInsideRow } from './utils.ts'
8
8
  import type { LoopParamSpec } from './utils.ts'
@@ -18,29 +18,7 @@ import { BindingScope } from '../scope/binding-scope.ts'
18
18
  import { interp, spliceChildValue, conditionalMarkup, renderChildCall, mappedRowsMarkup, withOuterBindings, dangerousInnerHtml, EMPTY_MARKUP } from './safe-html.ts'
19
19
  import { markupSlotIdsOf } from './markup-slots.ts'
20
20
  import { isEventHandlerName } from '../event-handler-name.ts'
21
-
22
- /**
23
- * Protect string literals from regex-based replacements.
24
- * Returns protect/restore functions that extract string literals before
25
- * regex replacements and restore them after.
26
- */
27
- export function createStringProtector(): {
28
- protect: (s: string) => string
29
- restore: (s: string) => string
30
- } {
31
- const strings: string[] = []
32
- const protect = (s: string): string => {
33
- return s.replace(/'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"/g, (match) => {
34
- const idx = strings.length
35
- strings.push(match)
36
- return `__STRLIT_${idx}__`
37
- })
38
- }
39
- const restore = (s: string): string => {
40
- return s.replace(/__STRLIT_(\d+)__/g, (_, idx) => strings[Number(idx)])
41
- }
42
- return { protect, restore }
43
- }
21
+ import { writesAnyBinding } from '../props-binding.ts'
44
22
 
45
23
  /**
46
24
  * Split a template literal body into static segments and `${...}` interpolations,
@@ -327,7 +305,7 @@ function escapeAttrValueExpr(valExpr: string): string {
327
305
  */
328
306
  function dangerouslyHtmlChildren(
329
307
  attrs: ReadonlyArray<IRAttribute>,
330
- toExpr: (v: { expr: string; templateExpr?: string }) => string,
308
+ toExpr: (v: { expr: JsSourceText; templateExpr?: JsSourceText }) => string,
331
309
  ): string | null {
332
310
  const attr = attrs.find(a => a.name === 'dangerouslySetInnerHTML')
333
311
  if (!attr || attr.value.kind !== 'expression') return null
@@ -341,7 +319,7 @@ function dangerouslyHtmlChildren(
341
319
  * template path; for non-`expression`/`spread`/`template` variants we
342
320
  * delegate to the canonical projection.
343
321
  */
344
- function transformKeyValue(value: AttrValue, transformExpr: (expr: string, templateExpr?: string) => string): string {
322
+ function transformKeyValue(value: AttrValue, transformExpr: (expr: JsSourceText, templateExpr?: JsSourceText) => string): string {
345
323
  switch (value.kind) {
346
324
  case 'expression':
347
325
  case 'spread':
@@ -1838,8 +1816,22 @@ export function irToComponentTemplate(
1838
1816
  return irToComponentTemplateWithOpts(node, { inlinableConstants, restSpreadNames, propsObjectName, loopDepth: -1, markupSlotIds, restPropsName })
1839
1817
  }
1840
1818
 
1819
+ /**
1820
+ * The `csrSubstitute` environment that inlines each template constant by
1821
+ * name (#3535), or null when there is none to inline.
1822
+ */
1823
+ function inlinableConstantEnv(inlinableConstants: ReadonlyMap<string, string> | undefined): CsrEnv | null {
1824
+ if (!inlinableConstants || inlinableConstants.size === 0) return null
1825
+ const substitutions = new Map<string, CsrSubstitution>()
1826
+ for (const [name, value] of inlinableConstants) {
1827
+ substitutions.set(name, { kind: 'identifier', replacement: value, freeIdentifiers: new Set() })
1828
+ }
1829
+ return { substitutions, propsObjectName: null }
1830
+ }
1831
+
1841
1832
  function irToComponentTemplateWithOpts(node: IRNode, opts: TemplateOptions): string {
1842
1833
  const { inlinableConstants, restSpreadNames, propsObjectName, restPropsName, loopDepth = 0 } = opts
1834
+ const constantEnv = inlinableConstantEnv(inlinableConstants)
1843
1835
  // `recurse` preserves `inHoistedChildren` for structural pass-through
1844
1836
  // (fragment / conditional); `childrenRecurse` clears it so element
1845
1837
  // descendants don't re-emit the placeholder. (#1320)
@@ -1849,29 +1841,19 @@ function irToComponentTemplateWithOpts(node: IRNode, opts: TemplateOptions): str
1849
1841
  // Bare prop name prefixing (org → _p.org) is handled by templateExpr
1850
1842
  // from Phase 1 AST rewrite. Only constant inlining and props object
1851
1843
  // normalization are done here. (#807)
1852
- const transformExpr = (expr: string, templateExpr?: string): string => {
1853
- const { protect, restore } = createStringProtector()
1854
- let result = protect(templateExpr ?? expr)
1855
-
1856
- // Inline constant references with their resolved values (#343)
1857
- if (inlinableConstants && inlinableConstants.size > 0) {
1858
- for (const [constName, constValue] of inlinableConstants) {
1859
- result = result.replace(new RegExp(`(?<![-.])\\b${constName}\\b`, 'g'), `(${protect(constValue)})`)
1860
- }
1861
- }
1844
+ const transformExpr = (expr: JsSourceText, templateExpr?: JsSourceText): string => {
1845
+ // Inline constant references with their resolved values (#343), on the
1846
+ // expression tree: a constant's name inside a string or template
1847
+ // literal, a member name, or a binding that shadows it is never
1848
+ // replaced, and a shorthand `{ size }` expands to `size: (value)`
1849
+ // (#3535).
1850
+ const source = templateExpr ?? expr
1851
+ const restored = constantEnv ? csrSubstitute(source, constantEnv, opts.scope).rewritten : source
1862
1852
 
1863
- // Normalize source-level props object access (e.g., props.xxx → _p.xxx).
1864
- // Restore FIRST: `rewritePropsObjectRef` parses `result` as real
1865
- // TypeScript, and a still-protected string/template-literal span would
1866
- // parse as an opaque placeholder token instead of the source text it
1867
- // stands for (harmless for the placeholder itself, but it must not be
1868
- // mistaken for unparsed leftover input by a caller reading `result`
1869
- // before this point). Regex-based `\b${propsObjectName}\.` (removed
1870
- // here) required the name to be immediately followed by `.`, so a
1871
- // parenthesised receiver — `(props).label`, produced by this same
1872
- // function's own constant-inlining step just above when the inlined
1873
- // value is itself `props` (a local alias of the whole props object) —
1874
- // silently kept the pre-rewrite name instead of `_p`.
1853
+ // Normalize source-level props object access (e.g., props.xxx → _p.xxx),
1854
+ // also on the tree: a parenthesised receiver — `(props).label`, produced
1855
+ // by the constant inlining just above when the inlined value is itself
1856
+ // `props` (a local alias of the whole props object) — resolves too.
1875
1857
  //
1876
1858
  // The gate stays keyed on `propsObjectName` for the destructured-prop
1877
1859
  // case (unconditionally rewriting here would also change static-path
@@ -1881,7 +1863,6 @@ function irToComponentTemplateWithOpts(node: IRNode, opts: TemplateOptions): str
1881
1863
  // param), so `rest.header` resolves to `_p.header` here the same way
1882
1864
  // it already does in the init body (`generate-init.ts`, #2723) instead
1883
1865
  // of reaching the template as a bare, undeclared `rest` (#2806).
1884
- const restored = restore(result)
1885
1866
  return (propsObjectName && propsObjectName !== PROPS_PARAM) || restPropsName
1886
1867
  ? rewritePropsObjectRef(restored, propsObjectName ?? null, restPropsName ?? null, { enclosingScope: opts.scope })
1887
1868
  : restored
@@ -2382,12 +2363,14 @@ function propResolvesUnsafe(
2382
2363
  env: CsrEnv,
2383
2364
  unsafeLocalNames: ReadonlySet<string>,
2384
2365
  ): boolean {
2385
- if (unsafeLocalNames.size === 0) return false
2386
2366
  let source: string | undefined
2387
2367
  switch (prop.value.kind) {
2388
2368
  case 'expression':
2389
2369
  case 'spread':
2390
- source = prop.value.expr
2370
+ // The same text the CSR `component` emit reads (`transformExpr(expr,
2371
+ // templateExpr)`): a prop read Phase 1 already lowered to
2372
+ // `_p.<key> ?? <default>` in `templateExpr` names no init local (#3579).
2373
+ source = prop.value.templateExpr ?? prop.value.expr
2391
2374
  break
2392
2375
  case 'template':
2393
2376
  source = attrValueToString(prop.value, { useTemplate: true }) ?? undefined
@@ -2397,8 +2380,8 @@ function propResolvesUnsafe(
2397
2380
  return false
2398
2381
  }
2399
2382
  if (!source) return false
2400
- const { freeIdentifiers } = csrSubstitute(source, env)
2401
- return setIntersects(freeIdentifiers, unsafeLocalNames)
2383
+ const { freeIdentifiers, writes } = csrSubstitute(source, env)
2384
+ return writes.size > 0 || setIntersects(freeIdentifiers, unsafeLocalNames)
2402
2385
  }
2403
2386
 
2404
2387
  /**
@@ -2423,7 +2406,10 @@ export function computeDeferredChildSlots(
2423
2406
  propsObjectName?: string | null,
2424
2407
  ): Set<string> {
2425
2408
  const deferred = new Set<string>()
2426
- if (!unsafeLocalNames || unsafeLocalNames.size === 0) return deferred
2409
+ // A prop can also be dropped for writing a binding (`get={() => ++id}`,
2410
+ // see `transformExpr`), which only a component that writes one can have.
2411
+ if (!writesAnyBinding(ctx) && (!unsafeLocalNames || unsafeLocalNames.size === 0)) return deferred
2412
+ const unsafe = unsafeLocalNames ?? new Set<string>()
2427
2413
  const env = buildCsrEnvForCtx(ctx, inlinableConstants, propsObjectName)
2428
2414
 
2429
2415
  const visit = (n: IRNode): void => {
@@ -2445,7 +2431,7 @@ export function computeDeferredChildSlots(
2445
2431
  if (p.name === 'ref') return false
2446
2432
  if (isEventHandlerName(p.name)) return false
2447
2433
  if (p.clientOnly) return false
2448
- return propResolvesUnsafe(p, env, unsafeLocalNames)
2434
+ return propResolvesUnsafe(p, env, unsafe)
2449
2435
  })
2450
2436
  if (dropped) deferred.add(n.slotId)
2451
2437
  }
@@ -2478,7 +2464,7 @@ export function computeDeferredChildSlots(
2478
2464
  function generateCsrTemplateWithOpts(node: IRNode, opts: TemplateOptions): string {
2479
2465
  const { restSpreadNames, propsObjectName, restPropsName, csrEnv, unsafeLocalNames, loopDepth = 0 } = opts
2480
2466
  const env: CsrEnv = csrEnv ?? { substitutions: new Map(), propsObjectName: propsObjectName ?? null }
2481
- const transformExpr = (expr: string, templateExpr?: string): string => {
2467
+ const transformExpr = (expr: JsSourceText, templateExpr?: JsSourceText): string => {
2482
2468
  // Single AST substitution pass: replaces signal getter calls
2483
2469
  // (`count()` → `(initialValue)`), memo calls (`bars()` → `(body)`),
2484
2470
  // and inlinable-const refs (`label` → `(rewrittenValue)`) in one
@@ -2488,7 +2474,12 @@ function generateCsrTemplateWithOpts(node: IRNode, opts: TemplateOptions): strin
2488
2474
  // the IR — emit does no string transformation of its own (#1277).
2489
2475
  const source = templateExpr ?? expr
2490
2476
  if (!source) return source
2491
- const { rewritten, freeIdentifiers } = csrSubstitute(source, env, opts.scope)
2477
+ const { rewritten, freeIdentifiers, writes } = csrSubstitute(source, env, opts.scope)
2478
+
2479
+ // An expression that writes a binding (`{++nextId}`, a child prop
2480
+ // `() => ++start`) cannot run here: the template has no binding to
2481
+ // write, and the write belongs to init's run of the component.
2482
+ if (writes.size > 0) return UNSAFE_TEMPLATE_EXPR
2492
2483
 
2493
2484
  // The CSR template runs at module scope, so any post-substitution
2494
2485
  // free identifier that lands in `unsafeLocalNames` (init-body-only
@@ -11,6 +11,9 @@
11
11
  * issue #1021 Stage B for the rationale.
12
12
  */
13
13
 
14
+ import ts from 'typescript'
15
+ import { isIdentifierLikeToken, isTriviaKind, iterateJsTokens } from '../scanner/js-scanner.ts'
16
+
14
17
  /** JavaScript keywords and common globals to skip during identifier extraction. */
15
18
  const KEYWORDS_AND_GLOBALS = new Set([
16
19
  'true',
@@ -56,46 +59,94 @@ const KEYWORDS_AND_GLOBALS = new Set([
56
59
  ])
57
60
 
58
61
  /**
59
- * Extract identifiers from an expression string.
62
+ * Words that can never name a binding in module (strict) code. Every other
63
+ * identifier-or-keyword token, contextual keywords included (`type`, `of`,
64
+ * `get`, …), can.
60
65
  */
61
- export function extractIdentifiers(expr: string, set: Set<string>): void {
62
- const matches = expr.match(/\b[a-zA-Z_][a-zA-Z0-9_]*\b/g)
63
- if (matches) {
64
- for (const id of matches) {
65
- if (!isKeywordOrGlobal(id)) {
66
- set.add(id)
67
- }
66
+ const RESERVED_WORDS = new Set([
67
+ 'await', 'break', 'case', 'catch', 'class', 'const', 'continue', 'debugger', 'default', 'delete', 'do',
68
+ 'else', 'enum', 'export', 'extends', 'false', 'finally', 'for', 'function', 'if', 'implements', 'import',
69
+ 'in', 'instanceof', 'interface', 'let', 'new', 'null', 'package', 'private', 'protected', 'public',
70
+ 'return', 'static', 'super', 'switch', 'this', 'throw', 'true', 'try', 'typeof', 'var', 'void', 'while',
71
+ 'with', 'yield',
72
+ ])
73
+
74
+ /**
75
+ * Walk the tokens of `text` (`iterateJsTokens`, the shared JS lexer, which
76
+ * reads a regex literal as one token and closes template substitutions at
77
+ * their own `}`), calling `onName` for every identifier, member names
78
+ * included (`props.value` yields both: the reference graph reads a
79
+ * props-object member as a use of that prop), and `onSubstitution` with the
80
+ * source span of every outermost `${…}` body. String, regex and comment
81
+ * contents produce no names, and `$` is an identifier character, so
82
+ * `step$` / `$step` are found (#3536).
83
+ *
84
+ * A contextual keyword (`type`, `of`, `get`, …) is a legal binding name, so
85
+ * it is reported like an identifier; a reserved word is reported only as a
86
+ * member name (`props.default`).
87
+ */
88
+ function scanNames(
89
+ text: string,
90
+ onName: (name: string) => void,
91
+ onSubstitution?: (start: number, end: number) => void,
92
+ ): void {
93
+ // The source offset where each open template's current `${` body starts.
94
+ const bodyStarts: number[] = []
95
+ let prev: ts.SyntaxKind | undefined
96
+ for (const token of iterateJsTokens(text)) {
97
+ if (isTriviaKind(token.kind)) continue
98
+ if (token.kind === ts.SyntaxKind.TemplateHead) {
99
+ bodyStarts.push(token.end)
100
+ } else if (token.kind === ts.SyntaxKind.TemplateMiddle || token.kind === ts.SyntaxKind.TemplateTail) {
101
+ const bodyStart = bodyStarts.pop()
102
+ // Only an outermost body: a nested template stays inside its parent's.
103
+ if (bodyStart !== undefined && bodyStarts.length === 0) onSubstitution?.(bodyStart, token.pos)
104
+ if (token.kind === ts.SyntaxKind.TemplateMiddle) bodyStarts.push(token.end)
105
+ } else if (isIdentifierLikeToken(token.kind)) {
106
+ const name = text.slice(token.pos, token.end)
107
+ const isMemberName = prev === ts.SyntaxKind.DotToken || prev === ts.SyntaxKind.QuestionDotToken
108
+ if (isMemberName || !RESERVED_WORDS.has(name)) onName(name)
68
109
  }
110
+ prev = token.kind
69
111
  }
70
112
  }
71
113
 
114
+ /** `text` as a template literal: already backtick-quoted, or quoted here. */
115
+ function asTemplateLiteral(text: string): string {
116
+ return text.startsWith('`') && text.endsWith('`') && text.length >= 2 ? text : `\`${text}\``
117
+ }
118
+
72
119
  /**
73
- * Yield each `${...}` substitution body inside a template-style string.
74
- * Returns the inner expressions — the surrounding HTML / static text is
75
- * stripped. Empty array when no substitutions are present.
76
- *
77
- * Uses a `[^}]+` character class rather than a balance-aware scanner —
78
- * cheap and matches the legacy reach. Object literals inside `${...}`
79
- * are not supported (they would split prematurely on the inner `}`).
120
+ * Extract identifiers from an expression string.
121
+ */
122
+ export function extractIdentifiers(expr: string, set: Set<string>): void {
123
+ scanNames(expr, name => {
124
+ if (!isKeywordOrGlobal(name)) set.add(name)
125
+ })
126
+ }
127
+
128
+ /**
129
+ * Yield each `${...}` substitution body inside a template-style string
130
+ * (backtick-quoted or not). Returns the inner expressions — the
131
+ * surrounding HTML / static text is stripped. Empty array when no
132
+ * substitutions are present. Nested braces and template literals inside a
133
+ * body are kept whole.
80
134
  */
81
135
  export function extractTemplateExpressions(template: string): string[] {
82
- const re = /\$\{([^}]+)\}/g
136
+ const literal = asTemplateLiteral(template)
83
137
  const out: string[] = []
84
- let match
85
- while ((match = re.exec(template)) !== null) {
86
- out.push(match[1])
87
- }
138
+ scanNames(literal, () => {}, (start, end) => out.push(literal.slice(start, end)))
88
139
  return out
89
140
  }
90
141
 
91
142
  /**
92
143
  * Extract identifiers from template literal expressions.
93
- * Finds ${...} patterns and extracts identifiers from inside.
144
+ * Only `${...}` substitutions are scanned; static text is not code.
94
145
  */
95
146
  export function extractTemplateIdentifiers(template: string, set: Set<string>): void {
96
- for (const expr of extractTemplateExpressions(template)) {
97
- extractIdentifiers(expr, set)
98
- }
147
+ scanNames(asTemplateLiteral(template), name => {
148
+ if (!isKeywordOrGlobal(name)) set.add(name)
149
+ })
99
150
  }
100
151
 
101
152
  /**
@@ -3,9 +3,10 @@
3
3
  */
4
4
 
5
5
  import ts from 'typescript'
6
- import type { ComponentIR, IRNode } from '../types.ts'
6
+ import type { CompilerError, ComponentIR, ImportInfo, IRNode, SourceLocation } from '../types.ts'
7
+ import { createError, ErrorCodes } from '../errors.ts'
7
8
  import { isClientBuiltinName } from '../builtins.ts'
8
- import { collectValueReferencedNames } from '../value-references.ts'
9
+ import { analyzeEmittedReferences, collectValueReferencedNames } from '../value-references.ts'
9
10
  import { identifierCallPattern } from '../identifier-pattern.ts'
10
11
 
11
12
  // All exports from @barefootjs/client/runtime that may be used in generated code
@@ -84,32 +85,68 @@ export const RUNTIME_MODULE = '@barefootjs/client/runtime'
84
85
  export const IMPORT_PLACEHOLDER = '/* __BAREFOOTJS_DOM_IMPORTS__ */'
85
86
  export const MODULE_CONSTANTS_PLACEHOLDER = '/* __MODULE_LEVEL_CONSTANTS__ */'
86
87
 
88
+ /** Runtime names `detectUsedImports` can report: the candidates plus the slot finders. */
89
+ const RUNTIME_IMPORT_NAMES: ReadonlySet<string> = new Set<string>([...RUNTIME_IMPORT_CANDIDATES, '$', '$c', '$t'])
90
+
87
91
  /**
88
- * Detect which @barefootjs/client/runtime functions are actually used in the generated code
92
+ * Detect which @barefootjs/client/runtime functions the generated code uses:
93
+ * the runtime names it references without binding them itself (#3537). A
94
+ * module-level user helper emitted as `var insert = …`, or a parameter that
95
+ * happens to be called `qsa`, binds its name, so it neither pulls in the
96
+ * runtime import nor collides with it as a duplicate declaration.
97
+ *
98
+ * Falls back to the per-name call scan only when the code does not parse
99
+ * cleanly, where narrowing on a partial parse could drop a needed import.
89
100
  */
90
101
  export function detectUsedImports(code: string): Set<string> {
102
+ const refs = analyzeEmittedReferences(code)
103
+ if (refs) return new Set([...refs.free].filter(name => RUNTIME_IMPORT_NAMES.has(name)))
91
104
  const used = new Set<string>()
92
105
  for (const name of RUNTIME_IMPORT_CANDIDATES) {
93
- // Match function calls: name(
94
- if (identifierCallPattern(name).test(code)) {
95
- used.add(name)
96
- }
97
- }
98
- // Shorthand finders need special detection ($ is not a word character)
99
- if (/\$c\s*\(/.test(code)) {
100
- used.add('$c')
101
- }
102
- // Match $t( for text node finders
103
- if (/\$t\s*\(/.test(code)) {
104
- used.add('$t')
105
- }
106
- // Match $( but not $c( or $t( - use negative lookahead
107
- if (/\$\s*\(/.test(code)) {
108
- used.add('$')
106
+ if (identifierCallPattern(name).test(code)) used.add(name)
109
107
  }
108
+ if (/\$c\s*\(/.test(code)) used.add('$c')
109
+ if (/\$t\s*\(/.test(code)) used.add('$t')
110
+ if (/\$\s*\(/.test(code)) used.add('$')
110
111
  return used
111
112
  }
112
113
 
114
+ /**
115
+ * BF057 for each module-level binding of the user's that takes a runtime
116
+ * helper's name (#3537): a module-level declaration the client JS re-emits,
117
+ * or a value import from anything but the runtime itself, whose name the
118
+ * emitted `code` also calls. That call may be the compiler's own, which the
119
+ * user's binding would capture, so it is refused rather than guessed at.
120
+ * This is exactly the case that used to emit both the binding and a runtime
121
+ * import of the same name, a duplicate-declaration SyntaxError. A binding
122
+ * the code never calls (`const qsa = {…}` read as `qsa.step`) stays legal.
123
+ */
124
+ export function runtimeNameCollisions(
125
+ declarations: readonly { name: string; loc: SourceLocation }[],
126
+ imports: readonly ImportInfo[],
127
+ code: string,
128
+ ): CompilerError[] {
129
+ const runtimeSources = new Set([RUNTIME_MODULE, '@barefootjs/client'])
130
+ const bound = [...declarations]
131
+ for (const imp of imports) {
132
+ if (imp.isTypeOnly || runtimeSources.has(imp.source)) continue
133
+ for (const spec of imp.specifiers) {
134
+ if (!spec.isTypeOnly) bound.push({ name: spec.alias ?? spec.name, loc: imp.loc })
135
+ }
136
+ }
137
+ const colliding = bound.filter(b => RUNTIME_IMPORT_NAMES.has(b.name))
138
+ if (colliding.length === 0) return []
139
+ const called = analyzeEmittedReferences(code)?.called
140
+ return colliding
141
+ .filter(b => called?.has(b.name) ?? true)
142
+ .map(b =>
143
+ createError(ErrorCodes.RUNTIME_HELPER_NAME_COLLISION, b.loc, {
144
+ message: `'${b.name}' is also a BarefootJS runtime helper, and the compiled client JS calls '${b.name}(…)'. ` +
145
+ 'Rename the declaration, or import it under an alias.',
146
+ }),
147
+ )
148
+ }
149
+
113
150
  /**
114
151
  * Collect user-defined imports from @barefootjs/client (or the
115
152
  * compiler-emitted /runtime subpath).
@@ -22,7 +22,7 @@ import { buildInlinableConstants, csrInlinableConstantsFromCtx } from './emit-re
22
22
  import { buildEnvFromCtx } from './compute-inlinability.ts'
23
23
  import { nameForRegistryRef, buildImportAliasMap, setActiveImportAliases } from './component-scope.ts'
24
24
  import { resolveRestSpreadNames } from './prop-handling.ts'
25
- import { IMPORT_PLACEHOLDER, RUNTIME_MODULE, detectUsedImports, collectExternalImports } from './imports.ts'
25
+ import { IMPORT_PLACEHOLDER, RUNTIME_MODULE, detectUsedImports, collectExternalImports, runtimeNameCollisions } from './imports.ts'
26
26
  import { isInlinableInTemplate } from '../relocate.ts'
27
27
  import { buildSourceMapFromIR, type SourceMapV3 } from './source-map.ts'
28
28
  import { resolvePropDeclaredType, baseTypeName } from '../rich-type-evidence.ts'
@@ -391,6 +391,7 @@ function generateTemplateOnlyMount(ir: ComponentIR, ctx: ClientJsContext): strin
391
391
  // same — without it, a constant whose value got inlined into the
392
392
  // template (e.g. `useYjs(_p.x)`) leaves the template referencing a
393
393
  // bare module-import name that's no longer imported (#1138 / #1133).
394
+ ctx.warnings.push(...runtimeNameCollisions([], ir.metadata.imports, generatedCode))
394
395
  const externalImports = collectExternalImports(ir, generatedCode)
395
396
  const allImports = externalImports.length > 0
396
397
  ? `${importLine}\n${externalImports.join('\n')}`
@@ -17,7 +17,7 @@
17
17
  */
18
18
 
19
19
  import type { ClientJsContext } from '../types.ts'
20
- import { toDomEventName, varSlotId, wrapHandlerInBlock, wrapHandlerForTurn } from '../utils.ts'
20
+ import { toDomEventName, varSlotId, wrapHandlerForTurn } from '../utils.ts'
21
21
  import type { LoopDelegationIndex } from '../control-flow/plan/loop-delegation-index.ts'
22
22
 
23
23
  export function emitEventHandlers(
@@ -35,7 +35,7 @@ export function emitEventHandlers(
35
35
  // profiling run attributes the reactive work it triggers to this turn.
36
36
  const wrappedHandler = ctx.profile
37
37
  ? wrapHandlerForTurn(event.handler, `${ctx.componentName}#handler:${elem.slotId}:${event.name}`)
38
- : wrapHandlerInBlock(event.handler)
38
+ : event.handler.trim()
39
39
  if (elem.slotId === '__scope') {
40
40
  lines.push(` if (__scope) __scope.addEventListener('${eventName}', ${wrappedHandler})`)
41
41
  } else {
@@ -1,6 +1,9 @@
1
1
  /**
2
- * `props-extraction` phase — emit the one surviving one-time prop
3
- * extraction, `const children = _p.children [?? <default>]`.
2
+ * `props-extraction` phase — emit the one-time prop extractions:
3
+ * `const children = _p.children [?? <default>]` (or `const kids =
4
+ * _p.children` for a renamed `{ children: kids }`), and `let start =
5
+ * _p.start [?? <default>]` for each prop the component writes
6
+ * (`ParamInfo.reassigned`, see `keepsDeclaredValue`).
4
7
  *
5
8
  * `children` must stay a ONE-TIME read: a prop's slot-children value is a
6
9
  * getter that INSTANTIATES child components when read (see
@@ -18,13 +21,10 @@
18
21
  * downstream code there reads `_p.X` directly via the late-stage rename.
19
22
  */
20
23
 
21
- import type { PropUsage } from '../../types.ts'
24
+ import { type PropUsage, isChildrenPropParam } from '../../types.ts'
22
25
  import { computePropsUsedAsConditions } from '../compute-prop-usage.ts'
23
- import { propReadBase, propReadFallback } from '../../props-binding.ts'
26
+ import { propReadBase, propReadFallback, keepsDeclaredValue } from '../../props-binding.ts'
24
27
  import type { ClientJsContext } from '../types.ts'
25
- import { PROPS_PARAM } from '../utils.ts'
26
-
27
- const CHILDREN = 'children'
28
28
 
29
29
  export function emitPropsExtraction(
30
30
  lines: string[],
@@ -33,16 +33,38 @@ export function emitPropsExtraction(
33
33
  propUsage: Map<string, PropUsage>,
34
34
  ): void {
35
35
  if (ctx.propsObjectName) return
36
- if (!neededProps.has(CHILDREN)) return
37
-
38
- const prop = ctx.propsParams.find(p => p.name === CHILDREN)
39
- if (!prop) {
40
- lines.push(` const ${CHILDREN} = ${PROPS_PARAM}.${CHILDREN}`, '')
41
- return
42
- }
36
+ emitWrittenPropLocals(lines, ctx, propUsage)
37
+ // The children prop's local binding: `children`, or the renamed local of
38
+ // `{ children: kids }` (`isChildrenPropParam`, #3572), which reads
39
+ // `_p.children` the same one-time way. A local named `children` that binds
40
+ // another prop (`{ items: children }`) is an ordinary prop, read live.
41
+ // `neededProps` holds only props-param locals, so a component with no
42
+ // children param has nothing to extract.
43
+ const prop = ctx.propsParams.find(isChildrenPropParam)
44
+ if (!prop) return
45
+ const local = prop.name
46
+ if (!neededProps.has(local)) return
43
47
 
44
- const usedAsCondition = computePropsUsedAsConditions(ctx, neededProps).has(CHILDREN)
45
- const fallback = propReadFallback(prop, propUsage.get(CHILDREN), usedAsCondition)
48
+ const usedAsCondition = computePropsUsedAsConditions(ctx, neededProps).has(local)
49
+ const fallback = propReadFallback(prop, propUsage.get(local), usedAsCondition)
46
50
  const read = propReadBase(prop) + (fallback === null ? '' : ` ?? ${fallback}`)
47
- lines.push(` const ${CHILDREN} = ${read}`, '')
51
+ // A children binding the component writes needs a `let` to take the write.
52
+ lines.push(` ${keepsDeclaredValue(prop) ? 'const' : 'let'} ${local} = ${read}`, '')
53
+ }
54
+
55
+ /**
56
+ * A prop the component writes (`++start`, `start = clamp(start)`) is a
57
+ * local it owns, as in JS: declared once from the prop, then read and
58
+ * written in place. It is declared whether or not `neededProps` lists it,
59
+ * since a write is itself a use.
60
+ */
61
+ function emitWrittenPropLocals(lines: string[], ctx: ClientJsContext, propUsage: Map<string, PropUsage>): void {
62
+ const written = ctx.propsParams.filter(p => !p.isRest && !isChildrenPropParam(p) && !keepsDeclaredValue(p))
63
+ if (written.length === 0) return
64
+ const usedAsCondition = computePropsUsedAsConditions(ctx, new Set(written.map(p => p.name)))
65
+ for (const prop of written) {
66
+ const fallback = propReadFallback(prop, propUsage.get(prop.name), usedAsCondition.has(prop.name))
67
+ lines.push(` let ${prop.name} = ${propReadBase(prop)}${fallback === null ? '' : ` ?? ${fallback}`}`)
68
+ }
69
+ lines.push('')
48
70
  }
@@ -13,7 +13,7 @@ import type { Declaration } from '../declaration-sort.ts'
13
13
  import type { ClientJsContext } from '../types.ts'
14
14
  import type { ParamInfo, SignalInfo } from '../../types.ts'
15
15
  import { inferDefaultValue, PROPS_PARAM, readsBareProp } from '../utils.ts'
16
- import { livePropReadExpr } from '../../props-binding.ts'
16
+ import { livePropReadExpr, propDefaultText } from '../../props-binding.ts'
17
17
  import { signalFactoryInitializer, signalSecondBinding } from '../../signal-initializer.ts'
18
18
  import type {
19
19
  ControlledSignalEffectPlan,
@@ -138,7 +138,7 @@ function resolveSignalInitialValue(signal: SignalInfo, lookups: DeclarationEmitL
138
138
  const controlled = lookups.controlledBySignal.get(signal)
139
139
  if (controlled) {
140
140
  const prop = lookups.propByName.get(controlled.propName)
141
- const defaultVal = prop?.defaultValue ?? inferDefaultValue(signal.type)
141
+ const defaultVal = (prop && propDefaultText(prop)) ?? inferDefaultValue(signal.type)
142
142
  // `_p` is always keyed by the caller-facing name (#2524 CSR half).
143
143
  return `${PROPS_PARAM}.${prop?.sourceName ?? controlled.propName} ?? ${defaultVal}`
144
144
  }
@@ -130,6 +130,13 @@ function buildSingleCompPlan(
130
130
  indexParam: elem.index || '__idx',
131
131
  outerPreludeStatements: staticPreludeStatements(elem.preamble),
132
132
  propsExpr: buildStaticPropsExpr(props),
133
+ // #3607: the static twin of the component-root loop's `rowEvents` — a
134
+ // static array has no delegation pass for a component row either
135
+ // (`loopEventDelegationVariant`), so each hydrated row attaches the
136
+ // handlers on its forwarded children directly.
137
+ rowEvents: elem.bindings.events
138
+ .filter(ev => ev.nestedLoops.length === 0)
139
+ .map(ev => ({ childSlotId: ev.childSlotId, eventName: ev.eventName, handler: ev.handler })),
133
140
  }
134
141
  }
135
142
 
@@ -25,6 +25,7 @@
25
25
  * shapes were determined by inline branching on the IR.
26
26
  */
27
27
 
28
+ import type { LoopRowEventBinding } from '../control-flow/plan/loop.ts'
28
29
  import type { PreludeStatements } from '../control-flow/plan/inner-loop.ts'
29
30
  import type { LoopChildRefBinding } from '../control-flow/plan/loop.ts'
30
31
  import type { LoopChildReactiveAttr, LoopChildReactiveText } from '../types.ts'
@@ -71,6 +72,13 @@ export interface SingleCompInitPlan {
71
72
  outerPreludeStatements: PreludeStatements
72
73
  /** Pre-built props object expression for the child component. */
73
74
  propsExpr: PropsExpr
75
+ /**
76
+ * Event handlers on elements forwarded as the row component's own
77
+ * `children`, outside any inner loop (#3607). Attached to each hydrated
78
+ * row after its `initChild`. Unwrapped: the forEach binds `param` to the
79
+ * plain item, as for `propsExpr`.
80
+ */
81
+ rowEvents: readonly LoopRowEventBinding[]
74
82
  }
75
83
 
76
84
  /** Plan for one depth-0 component inside `loop.nestedComponents`. */