@barefootjs/jsx 0.40.0 → 0.40.2

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 (249) hide show
  1. package/dist/adapters/ambiguous-nil-arithmetic.d.ts +42 -0
  2. package/dist/adapters/ambiguous-nil-arithmetic.d.ts.map +1 -0
  3. package/dist/adapters/attr-plan.d.ts.map +1 -1
  4. package/dist/adapters/boolean-carrier.d.ts +31 -0
  5. package/dist/adapters/boolean-carrier.d.ts.map +1 -0
  6. package/dist/adapters/boolean-result.d.ts +32 -10
  7. package/dist/adapters/boolean-result.d.ts.map +1 -1
  8. package/dist/adapters/brace-delimiter-text.d.ts +18 -0
  9. package/dist/adapters/brace-delimiter-text.d.ts.map +1 -0
  10. package/dist/adapters/callback-method.d.ts +38 -5
  11. package/dist/adapters/callback-method.d.ts.map +1 -1
  12. package/dist/adapters/component-props.d.ts +22 -7
  13. package/dist/adapters/component-props.d.ts.map +1 -1
  14. package/dist/adapters/computed-const.d.ts +28 -1
  15. package/dist/adapters/computed-const.d.ts.map +1 -1
  16. package/dist/adapters/dsl-template-adapter.d.ts +39 -1
  17. package/dist/adapters/dsl-template-adapter.d.ts.map +1 -1
  18. package/dist/adapters/loop-bound-names.d.ts +9 -1
  19. package/dist/adapters/loop-bound-names.d.ts.map +1 -1
  20. package/dist/adapters/loop-row-type.d.ts +52 -0
  21. package/dist/adapters/loop-row-type.d.ts.map +1 -0
  22. package/dist/adapters/nil-reading.d.ts +68 -0
  23. package/dist/adapters/nil-reading.d.ts.map +1 -0
  24. package/dist/adapters/non-primitive-equality.d.ts +33 -0
  25. package/dist/adapters/non-primitive-equality.d.ts.map +1 -0
  26. package/dist/adapters/number-value.d.ts +45 -0
  27. package/dist/adapters/number-value.d.ts.map +1 -0
  28. package/dist/adapters/operand-typing.d.ts +126 -0
  29. package/dist/adapters/operand-typing.d.ts.map +1 -0
  30. package/dist/adapters/parsed-expr-emitter.d.ts +70 -12
  31. package/dist/adapters/parsed-expr-emitter.d.ts.map +1 -1
  32. package/dist/adapters/primitive-plan.d.ts +291 -0
  33. package/dist/adapters/primitive-plan.d.ts.map +1 -0
  34. package/dist/analyzer-context.d.ts +11 -0
  35. package/dist/analyzer-context.d.ts.map +1 -1
  36. package/dist/analyzer.d.ts +34 -0
  37. package/dist/analyzer.d.ts.map +1 -1
  38. package/dist/augment-inherited-props.d.ts +63 -8
  39. package/dist/augment-inherited-props.d.ts.map +1 -1
  40. package/dist/compiler.d.ts.map +1 -1
  41. package/dist/event-handler-name.d.ts +12 -0
  42. package/dist/event-handler-name.d.ts.map +1 -1
  43. package/dist/expression-parser.d.ts +8 -0
  44. package/dist/expression-parser.d.ts.map +1 -1
  45. package/dist/index.d.ts +24 -11
  46. package/dist/index.d.ts.map +1 -1
  47. package/dist/index.js +5671 -2586
  48. package/dist/ir-to-client-js/build-references.d.ts.map +1 -1
  49. package/dist/ir-to-client-js/child-props-object.d.ts +64 -0
  50. package/dist/ir-to-client-js/child-props-object.d.ts.map +1 -0
  51. package/dist/ir-to-client-js/collect-elements.d.ts.map +1 -1
  52. package/dist/ir-to-client-js/control-flow/plan/build-component-loop.d.ts.map +1 -1
  53. package/dist/ir-to-client-js/control-flow/plan/build-inner-loop.d.ts +29 -0
  54. package/dist/ir-to-client-js/control-flow/plan/build-inner-loop.d.ts.map +1 -1
  55. package/dist/ir-to-client-js/control-flow/plan/build-lazy-row.d.ts +2 -0
  56. package/dist/ir-to-client-js/control-flow/plan/build-lazy-row.d.ts.map +1 -1
  57. package/dist/ir-to-client-js/control-flow/plan/build-loop-child-arm.d.ts.map +1 -1
  58. package/dist/ir-to-client-js/control-flow/plan/build-reactive-effects.d.ts.map +1 -1
  59. package/dist/ir-to-client-js/control-flow/plan/inner-loop.d.ts +5 -4
  60. package/dist/ir-to-client-js/control-flow/plan/inner-loop.d.ts.map +1 -1
  61. package/dist/ir-to-client-js/control-flow/plan/loop-child-arm.d.ts +2 -0
  62. package/dist/ir-to-client-js/control-flow/plan/loop-child-arm.d.ts.map +1 -1
  63. package/dist/ir-to-client-js/control-flow/plan/loop.d.ts +15 -0
  64. package/dist/ir-to-client-js/control-flow/plan/loop.d.ts.map +1 -1
  65. package/dist/ir-to-client-js/control-flow/plan/reactive-effects.d.ts +2 -0
  66. package/dist/ir-to-client-js/control-flow/plan/reactive-effects.d.ts.map +1 -1
  67. package/dist/ir-to-client-js/control-flow/shared.d.ts.map +1 -1
  68. package/dist/ir-to-client-js/control-flow/stringify/claim-plan.d.ts +22 -0
  69. package/dist/ir-to-client-js/control-flow/stringify/claim-plan.d.ts.map +1 -1
  70. package/dist/ir-to-client-js/control-flow/stringify/component-loop.d.ts.map +1 -1
  71. package/dist/ir-to-client-js/control-flow/stringify/event-listener.d.ts +1 -1
  72. package/dist/ir-to-client-js/control-flow/stringify/event-listener.d.ts.map +1 -1
  73. package/dist/ir-to-client-js/control-flow/stringify/lazy-row.d.ts.map +1 -1
  74. package/dist/ir-to-client-js/html-template.d.ts +3 -2
  75. package/dist/ir-to-client-js/html-template.d.ts.map +1 -1
  76. package/dist/ir-to-client-js/imports.d.ts +2 -2
  77. package/dist/ir-to-client-js/imports.d.ts.map +1 -1
  78. package/dist/ir-to-client-js/index.d.ts +2 -6
  79. package/dist/ir-to-client-js/index.d.ts.map +1 -1
  80. package/dist/ir-to-client-js/plan/build-static-array-child-init.d.ts.map +1 -1
  81. package/dist/ir-to-client-js/plan/static-array-child-init.d.ts +37 -19
  82. package/dist/ir-to-client-js/plan/static-array-child-init.d.ts.map +1 -1
  83. package/dist/ir-to-client-js/prop-handling.d.ts.map +1 -1
  84. package/dist/ir-to-client-js/reactivity.d.ts.map +1 -1
  85. package/dist/ir-to-client-js/safe-html.d.ts +9 -3
  86. package/dist/ir-to-client-js/safe-html.d.ts.map +1 -1
  87. package/dist/ir-to-client-js/stringify/static-array-child-init.d.ts +3 -2
  88. package/dist/ir-to-client-js/stringify/static-array-child-init.d.ts.map +1 -1
  89. package/dist/ir-to-client-js/types.d.ts +30 -0
  90. package/dist/ir-to-client-js/types.d.ts.map +1 -1
  91. package/dist/ir-to-client-js/utils.d.ts +8 -0
  92. package/dist/ir-to-client-js/utils.d.ts.map +1 -1
  93. package/dist/jsx-to-ir.d.ts +1 -0
  94. package/dist/jsx-to-ir.d.ts.map +1 -1
  95. package/dist/nullable-signal-attr.d.ts +95 -10
  96. package/dist/nullable-signal-attr.d.ts.map +1 -1
  97. package/dist/prop-rewrite.d.ts +7 -0
  98. package/dist/prop-rewrite.d.ts.map +1 -1
  99. package/dist/props-binding.d.ts +27 -3
  100. package/dist/props-binding.d.ts.map +1 -1
  101. package/dist/props-object-whole-read.d.ts +15 -0
  102. package/dist/props-object-whole-read.d.ts.map +1 -0
  103. package/dist/rich-type-refusal.d.ts.map +1 -1
  104. package/dist/scope/binding-scope.d.ts +100 -4
  105. package/dist/scope/binding-scope.d.ts.map +1 -1
  106. package/dist/scope/lexical-scope-walk.d.ts +3 -2
  107. package/dist/scope/lexical-scope-walk.d.ts.map +1 -1
  108. package/dist/scope/root-prop-alias.d.ts +16 -0
  109. package/dist/scope/root-prop-alias.d.ts.map +1 -1
  110. package/dist/signal-prop-name-collision.d.ts.map +1 -1
  111. package/dist/ssr-defaults.d.ts +4 -2
  112. package/dist/ssr-defaults.d.ts.map +1 -1
  113. package/dist/ssr-seed-plan.d.ts +14 -0
  114. package/dist/ssr-seed-plan.d.ts.map +1 -1
  115. package/dist/strip-types.d.ts +13 -0
  116. package/dist/strip-types.d.ts.map +1 -1
  117. package/dist/template-parts.d.ts.map +1 -1
  118. package/dist/template-position-walk.d.ts +21 -3
  119. package/dist/template-position-walk.d.ts.map +1 -1
  120. package/dist/types.d.ts +120 -0
  121. package/dist/types.d.ts.map +1 -1
  122. package/package.json +2 -2
  123. package/src/__tests__/__snapshots__/doc-examples.test.ts.snap +3 -3
  124. package/src/__tests__/binding-scope-ratchet.test.ts +12 -2
  125. package/src/__tests__/binding-scope.test.ts +89 -1
  126. package/src/__tests__/body-destructure-props-object-alias.test.ts +123 -0
  127. package/src/__tests__/boolean-carrier.test.ts +74 -0
  128. package/src/__tests__/boolean-result.test.ts +22 -5
  129. package/src/__tests__/brace-delimiter-text.test.ts +26 -0
  130. package/src/__tests__/callback-method.test.ts +62 -2
  131. package/src/__tests__/child-components-in-map.test.ts +1 -1
  132. package/src/__tests__/component-props.test.ts +14 -0
  133. package/src/__tests__/computed-const.test.ts +188 -0
  134. package/src/__tests__/emit-to-string-call.test.ts +2 -1
  135. package/src/__tests__/expression-parser.test.ts +24 -0
  136. package/src/__tests__/hydration-payload-analysis.test.ts +166 -0
  137. package/src/__tests__/issue-2724-prop-alias-loop-not-static.test.ts +7 -7
  138. package/src/__tests__/issue-2754-rest-spread-needs-slot.test.ts +5 -2
  139. package/src/__tests__/issue-2798-static-nested-loop-bindings.test.ts +1 -1
  140. package/src/__tests__/issue-2835-props-type-member-name-collision.test.ts +4 -4
  141. package/src/__tests__/issue-3044-nested-prop-object-array-not-static.test.ts +1 -1
  142. package/src/__tests__/issue-3688-props-spread-child-csr.test.ts +143 -0
  143. package/src/__tests__/issue-3713-props-spread-loop-row.test.ts +65 -0
  144. package/src/__tests__/lookup-literal-const.test.ts +9 -3
  145. package/src/__tests__/loop-index-reactivity.test.ts +2 -2
  146. package/src/__tests__/loop-param-accessor-key-member-safety.test.ts +1 -1
  147. package/src/__tests__/loop-plan.test.ts +1 -1
  148. package/src/__tests__/loop-row-const-initializer-shadow.test.ts +146 -0
  149. package/src/__tests__/loop-row-prop-read.test.ts +111 -0
  150. package/src/__tests__/loop-row-type.test.ts +64 -0
  151. package/src/__tests__/lowering-value-position.test.ts +4 -0
  152. package/src/__tests__/memo-body-expr.test.ts +137 -0
  153. package/src/__tests__/module-const-destructure-default.test.ts +156 -0
  154. package/src/__tests__/nested-loop-index-param.test.ts +1 -1
  155. package/src/__tests__/nested-loop-reactive-attrs.test.ts +2 -2
  156. package/src/__tests__/nested-row-shadowing.test.ts +2 -2
  157. package/src/__tests__/nil-reading.test.ts +77 -0
  158. package/src/__tests__/nullable-signal-attr.test.ts +231 -2
  159. package/src/__tests__/primitive-plan.test.ts +416 -0
  160. package/src/__tests__/profile-binding-ids.test.ts +14 -0
  161. package/src/__tests__/profile-loop-binding-ids.test.ts +2 -2
  162. package/src/__tests__/profile-nested-binding-ids.test.ts +2 -2
  163. package/src/__tests__/props-object-whole-read.test.ts +40 -0
  164. package/src/__tests__/reactive-attrs-in-map.test.ts +1 -1
  165. package/src/__tests__/reactive-factory-inlining.test.ts +4 -1
  166. package/src/__tests__/rest-binding-gaps.test.ts +192 -0
  167. package/src/__tests__/root-prop-alias.test.ts +79 -1
  168. package/src/__tests__/signal-prop-name-collision.test.ts +102 -2
  169. package/src/__tests__/source-file-cache.test.ts +105 -0
  170. package/src/__tests__/ssr-seed-plan.test.ts +43 -0
  171. package/src/__tests__/static-loop-csr-materialize.test.ts +2 -2
  172. package/src/__tests__/static-record-literal-array.test.ts +171 -0
  173. package/src/__tests__/string-concat-identifier.test.ts +40 -1
  174. package/src/__tests__/template-parts-literal-boundary.test.ts +19 -0
  175. package/src/adapters/ambiguous-nil-arithmetic.ts +103 -0
  176. package/src/adapters/attr-plan.ts +6 -2
  177. package/src/adapters/boolean-carrier.ts +76 -0
  178. package/src/adapters/boolean-result.ts +72 -66
  179. package/src/adapters/brace-delimiter-text.ts +25 -0
  180. package/src/adapters/callback-method.ts +151 -27
  181. package/src/adapters/component-props.ts +28 -8
  182. package/src/adapters/computed-const.ts +443 -10
  183. package/src/adapters/dsl-template-adapter.ts +79 -2
  184. package/src/adapters/loop-bound-names.ts +9 -1
  185. package/src/adapters/loop-plan.ts +1 -1
  186. package/src/adapters/loop-row-type.ts +139 -0
  187. package/src/adapters/nil-reading.ts +297 -0
  188. package/src/adapters/non-primitive-equality.ts +92 -0
  189. package/src/adapters/number-value.ts +108 -0
  190. package/src/adapters/operand-typing.ts +522 -0
  191. package/src/adapters/parsed-expr-emitter.ts +154 -19
  192. package/src/adapters/primitive-plan.ts +696 -0
  193. package/src/analyzer-context.ts +14 -0
  194. package/src/analyzer.ts +692 -85
  195. package/src/augment-inherited-props.ts +108 -10
  196. package/src/compiler.ts +17 -0
  197. package/src/event-handler-name.ts +15 -0
  198. package/src/expression-parser.ts +74 -2
  199. package/src/index.ts +45 -9
  200. package/src/ir-to-client-js/build-references.ts +69 -0
  201. package/src/ir-to-client-js/child-props-object.ts +106 -0
  202. package/src/ir-to-client-js/collect-elements.ts +100 -67
  203. package/src/ir-to-client-js/compute-inlinability.ts +1 -1
  204. package/src/ir-to-client-js/control-flow/plan/build-component-loop.ts +15 -1
  205. package/src/ir-to-client-js/control-flow/plan/build-inner-loop.ts +85 -5
  206. package/src/ir-to-client-js/control-flow/plan/build-lazy-row.ts +3 -0
  207. package/src/ir-to-client-js/control-flow/plan/build-loop-child-arm.ts +30 -28
  208. package/src/ir-to-client-js/control-flow/plan/build-reactive-effects.ts +1 -0
  209. package/src/ir-to-client-js/control-flow/plan/inner-loop.ts +5 -4
  210. package/src/ir-to-client-js/control-flow/plan/loop-child-arm.ts +2 -0
  211. package/src/ir-to-client-js/control-flow/plan/loop.ts +12 -0
  212. package/src/ir-to-client-js/control-flow/plan/reactive-effects.ts +2 -0
  213. package/src/ir-to-client-js/control-flow/shared.ts +23 -24
  214. package/src/ir-to-client-js/control-flow/stringify/claim-plan.ts +29 -0
  215. package/src/ir-to-client-js/control-flow/stringify/component-loop.ts +8 -2
  216. package/src/ir-to-client-js/control-flow/stringify/event-listener.ts +8 -1
  217. package/src/ir-to-client-js/control-flow/stringify/inner-loop.ts +8 -7
  218. package/src/ir-to-client-js/control-flow/stringify/lazy-row.ts +8 -7
  219. package/src/ir-to-client-js/control-flow/stringify/loop-child-arm.ts +4 -4
  220. package/src/ir-to-client-js/control-flow/stringify/loop.ts +3 -3
  221. package/src/ir-to-client-js/control-flow/stringify/reactive-effects.ts +6 -6
  222. package/src/ir-to-client-js/emit-reactive.ts +1 -1
  223. package/src/ir-to-client-js/html-template.ts +95 -38
  224. package/src/ir-to-client-js/imports.ts +1 -1
  225. package/src/ir-to-client-js/index.ts +53 -11
  226. package/src/ir-to-client-js/plan/build-static-array-child-init.ts +42 -15
  227. package/src/ir-to-client-js/plan/static-array-child-init.ts +34 -19
  228. package/src/ir-to-client-js/prop-handling.ts +22 -3
  229. package/src/ir-to-client-js/reactivity.ts +14 -0
  230. package/src/ir-to-client-js/safe-html.ts +11 -4
  231. package/src/ir-to-client-js/stringify/static-array-child-init.ts +30 -12
  232. package/src/ir-to-client-js/types.ts +23 -0
  233. package/src/ir-to-client-js/utils.ts +15 -1
  234. package/src/jsx-to-ir.ts +510 -58
  235. package/src/nullable-signal-attr.ts +366 -28
  236. package/src/prop-rewrite.ts +30 -6
  237. package/src/props-binding.ts +54 -3
  238. package/src/props-object-whole-read.ts +87 -0
  239. package/src/rich-type-refusal.ts +2 -1
  240. package/src/scope/binding-scope.ts +203 -11
  241. package/src/scope/lexical-scope-walk.ts +4 -3
  242. package/src/scope/root-prop-alias.ts +23 -0
  243. package/src/signal-prop-name-collision.ts +113 -22
  244. package/src/ssr-defaults.ts +10 -4
  245. package/src/ssr-seed-plan.ts +82 -17
  246. package/src/strip-types.ts +31 -3
  247. package/src/template-parts.ts +21 -1
  248. package/src/template-position-walk.ts +57 -28
  249. package/src/types.ts +117 -0
package/src/jsx-to-ir.ts CHANGED
@@ -43,19 +43,22 @@ import {
43
43
  AttrValueOf,
44
44
  } from './types.ts'
45
45
  import { type AnalyzerContext, type MultiReturnJsxInfo, getSourceLocation, collectReactiveGetterNames, tsTypeToTypeInfo } from './analyzer-context.ts'
46
- import { parseExpression, isSupported, parseBlockBody, foldBlockToExpr, predicateTernaryToLogical, tsNodeToParsedExpr, sortComparatorFromArrow, stringifyParsedExpr, cssKebabCase, CALLBACK_METHODS, unboundCallbackParamRead, unboundCallbackParamReason, type ParsedExpr } from './expression-parser.ts'
46
+ import { parseExpression, freeIdentifiers, isSupported, parseBlockBody, foldBlockToExpr, predicateTernaryToLogical, tsNodeToParsedExpr, sortComparatorFromArrow, stringifyParsedExpr, cssKebabCase, CALLBACK_METHODS, unboundCallbackParamRead, unboundCallbackParamReason, type ParsedExpr } from './expression-parser.ts'
47
47
  import { fallbackChainParts, nullishChainParts } from './children-nullish.ts'
48
- import type { IRLoopSort, FunctionInfo, ConstantInfo, ParamInfo, FreeReference } from './types.ts'
48
+ import type { IRLoopSort, FunctionInfo, ConstantInfo, ParamInfo, FreeReference, SpreadAttr, JsSourceText } from './types.ts'
49
+ import { resolveStaticConstBinding } from './augment-inherited-props.ts'
50
+ import { componentScopeNames } from './adapters/computed-const.ts'
49
51
  import { formatParamWithType } from './module-exports.ts'
50
52
  import { createError, ErrorCodes, internalInvariant } from './errors.ts'
51
53
  import { CLIENT_BUILTIN_SOURCE, isClientBuiltinName, type ClientBuiltinTag } from './builtins.ts'
52
54
  import { containsReactiveExpression, collectReactiveBrandLeaves } from './reactivity-checker.ts'
53
55
  import {
54
56
  rewriteBarePropRefs as rewriteBarePropRefsCore,
57
+ rewriteBarePropRefsStructural as rewriteBarePropRefsStructuralCore,
55
58
  collectAstPropRefs,
56
59
  rewriteScopedValueRefs,
57
60
  } from './prop-rewrite.ts'
58
- import { boundPropLocalNames, buildPropAliasMap, isPropsAliasConst, isRenamedBodyPropParam, keepsDeclaredValue, resolveAliasOrigin, resolveRestSpreadOriginCore, livePropReadExpr } from './props-binding.ts'
61
+ import { boundPropLocalNames, buildPropAliasMap, templatePropReadParams, resolveAliasOrigin, resolveRestSpreadOriginCore, livePropReadExpr } from './props-binding.ts'
59
62
  import { PROPS_PARAM } from './ir-to-client-js/utils.ts'
60
63
  import { walkIR } from './ir-to-client-js/walker.ts'
61
64
  import { resolveFreeRefs, rebindHelperParamRefs, isNameBound as isNameBoundInEnv, type BindingEnvironment } from './free-refs.ts'
@@ -624,6 +627,24 @@ function lowerToLocaleDateCalls(text: string, expr: ts.Node, ctx: TransformConte
624
627
  * Returns undefined if no rewriting is needed (SolidJS-style or no props).
625
628
  */
626
629
  function rewriteBarePropRefs(text: string, expr: ts.Node, ctx: TransformContext): string | undefined {
630
+ return rewriteBarePropRefsVia(text, expr, ctx, rewriteBarePropRefsCore) ?? undefined
631
+ }
632
+
633
+ /**
634
+ * `rewriteBarePropRefs` with no regex fallback (#3845): `null` when `text`
635
+ * does not parse as an expression, for a caller that refuses the shape
636
+ * rather than emit a scope-blind splice.
637
+ */
638
+ function rewriteBarePropRefsStructural(text: string, expr: ts.Node, ctx: TransformContext): string | undefined | null {
639
+ return rewriteBarePropRefsVia(text, expr, ctx, rewriteBarePropRefsStructuralCore)
640
+ }
641
+
642
+ function rewriteBarePropRefsVia(
643
+ text: string,
644
+ expr: ts.Node,
645
+ ctx: TransformContext,
646
+ core: typeof rewriteBarePropRefsStructuralCore,
647
+ ): string | undefined | null {
627
648
  // #2292: lower a Date-typed prop's catalogued accessor call BEFORE the
628
649
  // bare-prop-name rewrite below, so the receiver identifier still picks
629
650
  // up the usual `_p.` prefix (destructured mode) or falls through to the
@@ -676,7 +697,7 @@ function rewriteBarePropRefs(text: string, expr: ts.Node, ctx: TransformContext)
676
697
  return info ? livePropReadExpr(info, undefined, false) : `${PROPS_PARAM}.${callerKey}`
677
698
  }
678
699
  : undefined
679
- return rewriteBarePropRefsCore(dateLowered, expr, propNames, extraPropRefs, propAliases ?? undefined, replacementFor)
700
+ return core(dateLowered, expr, propNames, extraPropRefs, propAliases ?? undefined, replacementFor)
680
701
  }
681
702
 
682
703
  /**
@@ -745,8 +766,7 @@ function collectBranchLocalPropRefsViaSubstitution(
745
766
  */
746
767
  function getDestructuredPropNames(ctx: TransformContext): Set<string> | null {
747
768
  if (ctx._destructuredPropNames === undefined) {
748
- const shadowed = propShadowingNames(ctx.analyzer)
749
- const eligible = ctx.analyzer.propsParams.filter(p => !shadowed.has(p.name))
769
+ const eligible = templatePropReadParams(ctx.analyzer)
750
770
  const names = eligible.map(p => p.name)
751
771
  ctx._destructuredPropNames = names.length > 0 ? new Set(names) : null
752
772
  ctx._destructuredPropAliases = buildPropAliasMap(eligible) ?? null
@@ -762,35 +782,6 @@ function getDestructuredPropNames(ctx: TransformContext): Set<string> | null {
762
782
  return ctx._destructuredPropNames ?? null
763
783
  }
764
784
 
765
- /**
766
- * The component-scope names that shadow a prop of the same name in a
767
- * `(props)`-arg component (`getDestructuredPropNames`' shadow guard): its
768
- * signals, memos and locals, except a local that is the prop itself.
769
- */
770
- function propShadowingNames(analyzer: AnalyzerContext): Set<string> {
771
- const shadowed = new Set<string>()
772
- if (!analyzer.propsObjectName) return shadowed
773
- for (const s of analyzer.signals) {
774
- shadowed.add(s.getter)
775
- if (s.setter) shadowed.add(s.setter)
776
- }
777
- for (const m of analyzer.memos) shadowed.add(m.name)
778
- for (const c of analyzer.localConstants) {
779
- // A body destructure binding that is reassigned or mutated no longer
780
- // holds its prop, renamed or not, so the template keeps it a local.
781
- if (c.propsDestructure && !keepsDeclaredValue(c)) {
782
- shadowed.add(c.name)
783
- continue
784
- }
785
- if (isPropsAliasConst(c, analyzer.propsObjectName)) continue
786
- // A renamed body binding with a default reads as its own prop entry,
787
- // like the parameter form (#3579).
788
- if (isRenamedBodyPropParam(c, analyzer.propsParams)) continue
789
- shadowed.add(c.name)
790
- }
791
- return shadowed
792
- }
793
-
794
785
  /**
795
786
  * Companion to `getDestructuredPropNames`: local-name → `ParamInfo` for the
796
787
  * same shadow-filtered eligible set. Both caches are written in one pass.
@@ -1186,6 +1177,61 @@ function childrenReadOf(
1186
1177
  return readsProps && isPropsChildrenMember(parsed, analyzer) ? 'bare' : null
1187
1178
  }
1188
1179
 
1180
+ /**
1181
+ * Whether `parsed`, read in the component scope, is `<props object>.<name>`
1182
+ * for a prop other than `children` (`props.footer`, `p.footer` for `const p
1183
+ * = props`).
1184
+ */
1185
+ function isPropsValueMember(parsed: ParsedExpr | undefined, analyzer: AnalyzerContext): boolean {
1186
+ return (
1187
+ parsed?.kind === 'member' &&
1188
+ !parsed.computed &&
1189
+ parsed.property !== 'children' &&
1190
+ parsed.object.kind === 'identifier' &&
1191
+ isPropsObjectBinding(parsed.object.name, analyzer)
1192
+ )
1193
+ }
1194
+
1195
+ /**
1196
+ * Whether the component-scope name `name` holds one of the component's own
1197
+ * props other than `children`: a destructured props param (renamed or not),
1198
+ * a body destructure or member read of the props object (`const { footer }
1199
+ * = props`, `const f = props.footer`), or a const alias hop of one.
1200
+ */
1201
+ function isPropValueBinding(name: string, analyzer: AnalyzerContext): boolean {
1202
+ const consts = childrenHopConstants(analyzer)
1203
+ const params = boundPropLocalNames(analyzer)
1204
+ const terminal = (n: string): true | null => {
1205
+ if (consts.has(n)) return isPropsValueMember(consts.get(n), analyzer) ? true : null
1206
+ return params.has(n) && !analyzer.propsParams.some(p => p.name === n && isChildrenPropParam(p)) ? true : null
1207
+ }
1208
+ return resolveAliasOrigin(childrenAliasHops(analyzer), name, terminal) === true
1209
+ }
1210
+
1211
+ /**
1212
+ * Whether a child-position expression inside a loop row is a bare read of one
1213
+ * of the component's own props other than `children`
1214
+ * (`IRExpression.loopRowPropRead`). A name or `props` object the enclosing
1215
+ * loop rows bind shadows the prop.
1216
+ */
1217
+ function isLoopRowPropRead(parsed: ParsedExpr, analyzer: AnalyzerContext, scope: BindingScope): boolean {
1218
+ if (!scope.insideLoopRow()) return false
1219
+ if (parsed.kind === 'identifier') return !scope.isBound(parsed.name) && isPropValueBinding(parsed.name, analyzer)
1220
+ return (
1221
+ parsed.kind === 'member' &&
1222
+ parsed.object.kind === 'identifier' &&
1223
+ !scope.isBound(parsed.object.name) &&
1224
+ isPropsValueMember(parsed, analyzer)
1225
+ )
1226
+ }
1227
+
1228
+ /** Set `childrenRead` and `loopRowPropRead` on an expression child from its parse. */
1229
+ function attachPropReadFlags(node: IRExpression, parsed: ParsedExpr, analyzer: AnalyzerContext, scope: BindingScope): void {
1230
+ const childrenRead = childrenReadOf(parsed, analyzer, scope)
1231
+ if (childrenRead) node.childrenRead = childrenRead
1232
+ if (isLoopRowPropRead(parsed, analyzer, scope)) node.loopRowPropRead = true
1233
+ }
1234
+
1189
1235
  /**
1190
1236
  * Attach `parsed` to every expression-valued attribute / prop so adapters can
1191
1237
  * lower from the tree instead of re-parsing the string. Element attrs,
@@ -1242,8 +1288,7 @@ function attachParsedExpressions(node: IRNode, analyzer: AnalyzerContext, scope:
1242
1288
  if (node.type === 'expression') {
1243
1289
  const trimmed = node.expr.trim()
1244
1290
  if (trimmed) node.parsed = parse(trimmed)
1245
- const childrenRead = node.parsed ? childrenReadOf(node.parsed, analyzer, scope) : null
1246
- if (childrenRead) node.childrenRead = childrenRead
1291
+ if (node.parsed) attachPropReadFlags(node, node.parsed, analyzer, scope)
1247
1292
  } else if (node.type === 'conditional' || node.type === 'if-statement') {
1248
1293
  const trimmed = node.condition.trim()
1249
1294
  if (trimmed) node.parsedCondition = parse(trimmed)
@@ -3966,6 +4011,7 @@ type FilterPredicateResult = {
3966
4011
  param: string
3967
4012
  predicate?: ParsedExpr
3968
4013
  raw: string
4014
+ templateRaw?: string
3969
4015
  }
3970
4016
 
3971
4017
  /**
@@ -4061,7 +4107,7 @@ function extractFilterPredicate(
4061
4107
  }
4062
4108
  const unbound = unboundFilterParamReason(callback, predicate, ctx)
4063
4109
  if (unbound) return { result: null, unsupportedReason: unbound }
4064
- return { result: { param, predicate, raw } }
4110
+ return withTemplatePredicate({ param, predicate, raw }, callback, ctx)
4065
4111
  }
4066
4112
 
4067
4113
  // Expression body: filter(t => !t.done)
@@ -4076,7 +4122,53 @@ function extractFilterPredicate(
4076
4122
  const unbound = unboundFilterParamReason(callback, predicate, ctx)
4077
4123
  if (unbound) return { result: null, unsupportedReason: unbound }
4078
4124
 
4079
- return { result: { param, predicate, raw } }
4125
+ return withTemplatePredicate({ param, predicate, raw }, callback, ctx)
4126
+ }
4127
+
4128
+ /**
4129
+ * Attach the predicate's client-template text (`templateRaw`, #3845): `raw`
4130
+ * with each destructured-prop read rewritten to `_p.<key>`, the same rewrite
4131
+ * `templateArray` gets. The predicate's own parameters are bound for the
4132
+ * rewrite, so `filter((one) => one)` keeps its parameter even when a prop is
4133
+ * named `one`.
4134
+ *
4135
+ * The rewrite is structural only. A block body is rewritten as the body of
4136
+ * an arrow (`() => { … }`), so its `let` / `const` shadow a prop for their
4137
+ * block and a `var` for the whole body (`walkWithScope`). The regex fallback
4138
+ * is never used: it cannot see an inner binding and would turn
4139
+ * `const one = 'a'` into `const _p.one = 'a'`. A text that does not parse is
4140
+ * refused as off-subset, like any other predicate the compiler cannot
4141
+ * model.
4142
+ */
4143
+ function withTemplatePredicate(
4144
+ result: FilterPredicateResult,
4145
+ callback: ts.ArrowFunction,
4146
+ ctx: TransformContext,
4147
+ ): FilterExtractionResult {
4148
+ const savedScope = ctx.scope
4149
+ const params = new Set<string>()
4150
+ for (const p of callback.parameters) collectBindingNames(p.name, params)
4151
+ ctx.scope = savedScope.enterCallback([...params])
4152
+ try {
4153
+ const templateRaw = rewritePredicateBody(result.raw, callback.body, ctx)
4154
+ if (templateRaw === null) {
4155
+ return { result: null, unsupportedReason: 'Filter predicate cannot be rewritten for the client template' }
4156
+ }
4157
+ return { result: templateRaw === undefined ? result : { ...result, templateRaw } }
4158
+ } finally {
4159
+ ctx.scope = savedScope
4160
+ }
4161
+ }
4162
+
4163
+ /** Arrow head a block-bodied predicate is parsed under, so its body is a function body. */
4164
+ const BLOCK_PREDICATE_HEAD = '() => '
4165
+
4166
+ /** The structural prop rewrite of a predicate body: `null` when it cannot be done. */
4167
+ function rewritePredicateBody(raw: string, body: ts.ConciseBody, ctx: TransformContext): string | undefined | null {
4168
+ if (!ts.isBlock(body)) return rewriteBarePropRefsStructural(raw, body, ctx)
4169
+ const rewritten = rewriteBarePropRefsStructural(`${BLOCK_PREDICATE_HEAD}${raw}`, body, ctx)
4170
+ if (rewritten === undefined || rewritten === null) return rewritten
4171
+ return rewritten.startsWith(BLOCK_PREDICATE_HEAD) ? rewritten.slice(BLOCK_PREDICATE_HEAD.length) : null
4080
4172
  }
4081
4173
 
4082
4174
  /**
@@ -7212,44 +7304,60 @@ interface ProcessedAttributes {
7212
7304
  // runtime to spread at hydration time, which loses that per-key resolution
7213
7305
  // and is reserved for cases where the key set isn't statically known.
7214
7306
  //
7215
- // The `spreadExpr === restName` check is what restricts unrolling to the
7216
- // rest-prop itself: arbitrary `{...someObject}` spreads can't be unrolled
7217
- // because we don't have a static key list for them.
7307
+ // `closedRestSpreadSource` restricts unrolling to the rest-prop itself:
7308
+ // arbitrary `{...someObject}` spreads can't be unrolled because we don't
7309
+ // have a static key list for them.
7218
7310
  //
7219
7311
  // The shape returned satisfies both IRAttribute and IRProp.
7220
7312
  function expandSpreadAttribute(
7221
7313
  attr: ts.JsxSpreadAttribute,
7222
7314
  ctx: TransformContext,
7315
+ constEntries?: ReadonlyArray<{ key: string; text: string }>,
7316
+ restFallbacks?: ReadonlyMap<string, RestKeyFallback>,
7223
7317
  ): Array<{
7224
7318
  name: string
7225
7319
  value: AttrValue
7226
7320
  loc: SourceLocation
7227
7321
  freeIdentifiers?: ReadonlySet<string>
7228
7322
  restExpandedKey?: boolean
7323
+ restFallback?: JsSourceText
7229
7324
  }> {
7230
7325
  const spreadExpr = ctx.getJS(attr.expression)
7231
7326
  const expandedKeys = ctx.analyzer.restPropsExpandedKeys
7232
- const restName = ctx.analyzer.restPropsName
7233
7327
  const loc = getSourceLocation(attr, ctx.sourceFile, ctx.filePath)
7234
7328
  const spreadFreeIdentifiers = extractFreeIdentifiersFromNode(attr.expression)
7329
+ const source = closedRestSpreadSource(attr, ctx)
7330
+ if (source === null && refuseBodyRestSpreadUnderShadowedProps(attr, ctx)) return []
7235
7331
 
7236
- if (expandedKeys.length > 0 && restName && spreadExpr === restName) {
7332
+ if (source !== null) {
7237
7333
  // Expanded per-key attrs reference `${restName}.${key}` — `restName` is
7238
7334
  // the only free identifier (the `.${key}` tail is a member-access name,
7239
7335
  // not an identifier reference). `restExpandedKey` (#3057) marks these so
7240
7336
  // Phase 2 (`collectElements`) can bind them reactively off a live
7241
7337
  // `_p.<key>` read instead of the one-time `${restName}.${key}` snapshot
7242
- // — see `IRAttribute.restExpandedKey`'s docstring.
7243
- const perKeyFreeIds: ReadonlySet<string> = new Set([restName])
7244
- return expandedKeys.map(key => ({
7245
- name: key,
7246
- value: AttrValueOf.expression(`${restName}.${key}`),
7247
- loc,
7248
- freeIdentifiers: perKeyFreeIds,
7249
- restExpandedKey: true,
7250
- }))
7338
+ // — see `IRAttribute.restExpandedKey`'s docstring. `source` is the
7339
+ // props object for a body rest (`closedRestSpreadSource`). A key an
7340
+ // earlier attribute also writes keeps that value when the caller
7341
+ // omitted it (`restFallbacks`, {@link closedRestFallbacks}).
7342
+ const perKeyFreeIds: ReadonlySet<string> = new Set([source])
7343
+ return expandedKeys.map(key => {
7344
+ const read = `${source}.${key}`
7345
+ const fallback = restFallbacks?.get(key)
7346
+ return {
7347
+ name: key,
7348
+ value: fallback === undefined
7349
+ ? AttrValueOf.expression(read)
7350
+ : AttrValueOf.expression(restKeyWithFallback(read, fallback.text), { templateExpr: restKeyWithFallback(read, fallback.templateText) }),
7351
+ loc,
7352
+ freeIdentifiers: fallback === undefined ? perKeyFreeIds : new Set([source, ...fallback.freeIdentifiers]),
7353
+ restExpandedKey: true,
7354
+ ...(fallback !== undefined && { restFallback: fallback.templateText }),
7355
+ }
7356
+ })
7251
7357
  }
7252
7358
 
7359
+ if (constEntries) return constEntries.map(({ key, text }) => ({ name: key, value: AttrValueOf.expression(text), loc }))
7360
+
7253
7361
  // Allocate a component-scoped slot ID so adapters that need a
7254
7362
  // structured plumbing path (Go's `.Spread_N` struct field) can
7255
7363
  // address this spread without recomputing identity downstream
@@ -7257,14 +7365,341 @@ function expandSpreadAttribute(
7257
7365
  // it. The closed-type expansion branch above returns before this
7258
7366
  // point, so closed-type rest spreads stay on the per-key fast path.
7259
7367
  const slotId = generateSpreadSlotId(ctx)
7368
+ const value = AttrValueOf.spread(spreadExpr, ctx.getTemplateJS(attr.expression), slotId)
7369
+ const callerBag = callerBagOfSpread(value, ctx)
7260
7370
  return [{
7261
7371
  name: '...',
7262
- value: AttrValueOf.spread(spreadExpr, ctx.getTemplateJS(attr.expression), slotId),
7372
+ value: callerBag ? { ...value, callerBag } : value,
7263
7373
  loc,
7264
7374
  freeIdentifiers: spreadFreeIdentifiers,
7265
7375
  }]
7266
7376
  }
7267
7377
 
7378
+ /**
7379
+ * The name each key of a closed-type rest spread (`{...rest}` with a
7380
+ * statically known key set, `IRMetadata.restPropsExpandedKeys`) is read
7381
+ * off, or null when `attr` is not one. A rest a body destructure of the
7382
+ * props object binds (`const { label, ...rest } = props`) holds the props
7383
+ * object's keys minus the ones the destructure takes, so its keys read the
7384
+ * props object (#3844): a template binds every declared prop as its own
7385
+ * variable, while its rest bag holds only undeclared keys. A loop row or
7386
+ * callback parameter spelled like the rest binding is that binding, not
7387
+ * the component's rest props (#3851).
7388
+ */
7389
+ function closedRestSpreadSource(attr: ts.JsxSpreadAttribute, ctx: TransformContext): string | null {
7390
+ const restName = ctx.analyzer.restPropsName
7391
+ if (ctx.analyzer.restPropsExpandedKeys.length === 0 || !restName || ctx.scope.isBound(restName)) return null
7392
+ let expr: ts.Expression = attr.expression
7393
+ while (ts.isParenthesizedExpression(expr)) expr = expr.expression
7394
+ if (!ts.isIdentifier(expr) || expr.text !== restName) return null
7395
+ const source = ctx.analyzer.restPropsOmittedKeys && ctx.analyzer.propsObjectName ? ctx.analyzer.propsObjectName : restName
7396
+ // A body rest's keys read the props object, which a loop row or callback
7397
+ // parameter of the same name hides here: no spelling of the per-key read
7398
+ // reaches the component's props (`expandSpreadAttribute` refuses it).
7399
+ return source !== restName && ctx.scope.isBound(source) ? null : source
7400
+ }
7401
+
7402
+ /**
7403
+ * BF101 for a spread of a props-object body rest (`const { a, ...rest } =
7404
+ * props`) where a loop row or callback parameter shadows the props
7405
+ * object's name (`rows.map(props => <li {...rest} />)`): its keys are read
7406
+ * off the props object, which that binding hides (#3854).
7407
+ */
7408
+ function refuseBodyRestSpreadUnderShadowedProps(attr: ts.JsxSpreadAttribute, ctx: TransformContext): boolean {
7409
+ const restName = ctx.analyzer.restPropsName
7410
+ const propsName = ctx.analyzer.propsObjectName
7411
+ if (!restName || !propsName || !ctx.analyzer.restPropsOmittedKeys || ctx.analyzer.restPropsExpandedKeys.length === 0) return false
7412
+ if (ctx.scope.isBound(restName) || !ctx.scope.isBound(propsName)) return false
7413
+ let expr: ts.Expression = attr.expression
7414
+ while (ts.isParenthesizedExpression(expr)) expr = expr.expression
7415
+ if (!ts.isIdentifier(expr) || expr.text !== restName) return false
7416
+ ctx.analyzer.errors.push({
7417
+ code: 'BF101',
7418
+ severity: 'error',
7419
+ message: `\`{...${restName}}\` spreads the component's props through a rest, inside a binding that shadows the props object's name \`${propsName}\`, so its keys have no spelling that reaches the component's props.`,
7420
+ loc: getSourceLocation(attr, ctx.sourceFile, ctx.filePath),
7421
+ suggestion: { message: `Rename the inner \`${propsName}\` binding.` },
7422
+ })
7423
+ return true
7424
+ }
7425
+
7426
+ /**
7427
+ * What a closed-type rest spread's keys fall back to (#3851). JSX applies
7428
+ * attributes and spreads in order, and a spread overrides only with the
7429
+ * keys its object has: `<Chip tone="x" {...rest} />` keeps `tone="x"` when
7430
+ * the caller omitted `tone`. A closed rest spread is expanded into one
7431
+ * attribute per key the props type declares, so each key an earlier
7432
+ * attribute (or an expanded const spread) writes reads `rest.key ??
7433
+ * (earlier)` instead ({@link restKeyWithFallback}), and the earlier explicit
7434
+ * attribute is dropped: the expanded key now carries both values.
7435
+ *
7436
+ * `fallbacks` maps each closed rest spread to its keys' fallback sources,
7437
+ * and `properties` is `properties` without the dropped attributes. An
7438
+ * earlier value that has no source form (a JSX element prop) or may have an
7439
+ * effect (`isReadOnlyAttrValue`) is refused with BF021. `ref`, `key` and
7440
+ * event handlers are not attribute writes and are left as they are; an
7441
+ * open spread (`{...obj}`) writes keys nothing knows statically, so no
7442
+ * fallback reaches across it.
7443
+ */
7444
+ function closedRestFallbacks(
7445
+ properties: readonly ts.JsxAttributeLike[],
7446
+ entries: ReadonlyMap<ts.JsxSpreadAttribute, ReadonlyArray<{ key: string; text: string }>>,
7447
+ ctx: TransformContext,
7448
+ ): { properties: ts.JsxAttributeLike[]; fallbacks: Map<ts.JsxSpreadAttribute, Map<string, RestKeyFallback>> } {
7449
+ const fallbacks = new Map<ts.JsxSpreadAttribute, Map<string, RestKeyFallback>>()
7450
+ const dropped = new Set<ts.JsxAttributeLike>()
7451
+ const lastWrite = new Map<string, KeyWrite>()
7452
+ for (const attr of properties) {
7453
+ if (ts.isJsxAttribute(attr)) {
7454
+ const name = attr.name.getText(ctx.sourceFile)
7455
+ if (name !== 'ref' && name !== 'key' && !isEventHandlerName(name)) lastWrite.set(name, { attr, value: attrValueFallback(attr, ctx) })
7456
+ continue
7457
+ }
7458
+ if (!ts.isJsxSpreadAttribute(attr)) continue
7459
+ const constEntries = entries.get(attr)
7460
+ const source = constEntries ? null : closedRestSpreadSource(attr, ctx)
7461
+ if (constEntries) {
7462
+ for (const e of constEntries) lastWrite.set(e.key, { value: { text: e.text, templateText: e.text, freeIdentifiers: new Set() } })
7463
+ } else if (source === null) {
7464
+ lastWrite.clear()
7465
+ } else {
7466
+ const keyFallbacks = closedRestKeyFallbacks(attr, source, lastWrite, dropped, ctx)
7467
+ if (keyFallbacks.size > 0) fallbacks.set(attr, keyFallbacks)
7468
+ }
7469
+ }
7470
+ return { properties: properties.filter(attr => !dropped.has(attr)), fallbacks }
7471
+ }
7472
+
7473
+ /** {@link closedRestFallbacks} for one closed rest spread reading its keys off `source`. */
7474
+ function closedRestKeyFallbacks(
7475
+ attr: ts.JsxSpreadAttribute,
7476
+ source: string,
7477
+ lastWrite: Map<string, KeyWrite>,
7478
+ dropped: Set<ts.JsxAttributeLike>,
7479
+ ctx: TransformContext,
7480
+ ): Map<string, RestKeyFallback> {
7481
+ const keyFallbacks = new Map<string, RestKeyFallback>()
7482
+ for (const key of ctx.analyzer.restPropsExpandedKeys) {
7483
+ const read = `${source}.${key}`
7484
+ const earlier = lastWrite.get(key)
7485
+ lastWrite.set(key, { value: { text: read, templateText: read, freeIdentifiers: new Set([source]) } })
7486
+ if (!earlier) continue
7487
+ if (earlier.value === null || (earlier.attr && !isReadOnlyAttrValue(earlier.attr.initializer))) {
7488
+ const why = earlier.value === null ? 'its value has no expression form to keep' : 'its value may have an effect, which JS runs exactly once'
7489
+ ctx.analyzer.errors.push(createError(ErrorCodes.UNSUPPORTED_JSX_PATTERN, getSourceLocation(earlier.attr ?? attr, ctx.sourceFile, ctx.filePath), {
7490
+ message: `'${key}' is written before a {...${ctx.getJS(attr.expression)}} spread that may also carry it, and ${why} when the caller omits '${key}'.`,
7491
+ suggestion: { message: `Write '${key}' after the spread, or compute the value in a local const and pass that.` },
7492
+ }))
7493
+ continue
7494
+ }
7495
+ keyFallbacks.set(key, earlier.value)
7496
+ lastWrite.set(key, {
7497
+ value: {
7498
+ text: restKeyWithFallback(read, earlier.value.text),
7499
+ templateText: restKeyWithFallback(read, earlier.value.templateText),
7500
+ freeIdentifiers: new Set([source, ...earlier.value.freeIdentifiers]),
7501
+ },
7502
+ })
7503
+ if (earlier.attr) dropped.add(earlier.attr)
7504
+ }
7505
+ return keyFallbacks
7506
+ }
7507
+
7508
+ /** A value a closed rest spread's key falls back to ({@link closedRestFallbacks}): its source text and free names. */
7509
+ interface RestKeyFallback {
7510
+ text: string
7511
+ /** `text` as a client-JS template reads it (`TransformContext.getTemplateJS`). */
7512
+ templateText: string
7513
+ freeIdentifiers: ReadonlySet<string>
7514
+ }
7515
+
7516
+ /** The last write of a key before a spread: the explicit attribute that made it, if any, and its value (null when it has no expression form). */
7517
+ interface KeyWrite {
7518
+ attr?: ts.JsxAttribute
7519
+ value: RestKeyFallback | null
7520
+ }
7521
+
7522
+ /**
7523
+ * `read`, or `fallback` when the key `read` reads is absent. A caller's
7524
+ * explicit `null` reads as absent too, as everywhere a template tests
7525
+ * whether a spread carries a key: no template backend tells the two apart.
7526
+ */
7527
+ function restKeyWithFallback(read: string, fallback: string): string {
7528
+ return `${read} ?? (${fallback})`
7529
+ }
7530
+
7531
+ /**
7532
+ * A JSX attribute's value as a fallback of a later closed rest spread
7533
+ * ({@link closedRestFallbacks}): `true` for a bare attribute, the string
7534
+ * literal, or the expression. Null for a value with no expression form (a
7535
+ * JSX element, an empty `{}`).
7536
+ */
7537
+ function attrValueFallback(attr: ts.JsxAttribute, ctx: TransformContext): RestKeyFallback | null {
7538
+ const value = attr.initializer
7539
+ if (value === undefined) return { text: 'true', templateText: 'true', freeIdentifiers: new Set() }
7540
+ if (ts.isStringLiteral(value)) {
7541
+ const text = JSON.stringify(value.text)
7542
+ return { text, templateText: text, freeIdentifiers: new Set() }
7543
+ }
7544
+ if (!ts.isJsxExpression(value) || value.expression === undefined) return null
7545
+ const expr = unwrapTransparentTsWrappers(value.expression)
7546
+ if (ts.isJsxElement(expr) || ts.isJsxSelfClosingElement(expr) || ts.isJsxFragment(expr)) return null
7547
+ return {
7548
+ text: ctx.getJS(value.expression),
7549
+ templateText: ctx.getTemplateJS(value.expression),
7550
+ freeIdentifiers: extractFreeIdentifiersFromNode(value.expression),
7551
+ }
7552
+ }
7553
+
7554
+ /**
7555
+ * How an element's or component call's static const spreads resolve
7556
+ * against everything else it is given (#3844): `entries` maps each spread
7557
+ * of a const holding a static object literal to the `key: value-source`
7558
+ * pairs it passes, and `properties` is the attribute list without the
7559
+ * explicit attributes such a spread overrides.
7560
+ *
7561
+ * JSX applies attributes and spreads in order and the last write of a key
7562
+ * wins, so the plan walks them from the last: a key an explicit attribute
7563
+ * or an expanded spread writes is dropped from every earlier explicit
7564
+ * attribute and expanded spread. A spread that is not expanded (`{...rest}`,
7565
+ * a computed object) overrides nothing statically; what it holds is merged
7566
+ * at render time after what comes before it, as before. Each key is
7567
+ * therefore written once, with the value JS gives it. When an overridden
7568
+ * attribute's value may have an effect, nothing is expanded (see the end
7569
+ * of the function).
7570
+ */
7571
+ function staticSpreadPlan(attributes: ts.JsxAttributes, ctx: TransformContext): {
7572
+ properties: ts.JsxAttributeLike[]
7573
+ entries: Map<ts.JsxSpreadAttribute, Array<{ key: string; text: string }>>
7574
+ } {
7575
+ const entries = new Map<ts.JsxSpreadAttribute, Array<{ key: string; text: string }>>()
7576
+ const overridden = new Set<ts.JsxAttributeLike>()
7577
+ const written = new Set<string>()
7578
+ for (const attr of [...attributes.properties].reverse()) {
7579
+ if (ts.isJsxAttribute(attr)) {
7580
+ const name = attr.name.getText(ctx.sourceFile)
7581
+ if (written.has(name)) overridden.add(attr)
7582
+ written.add(name)
7583
+ continue
7584
+ }
7585
+ const spread = expandStaticConstSpread(attr, ctx)
7586
+ if (!spread) continue
7587
+ entries.set(attr, spread.filter(e => !written.has(e.key)))
7588
+ for (const e of spread) written.add(e.key)
7589
+ }
7590
+ // Dropping an overridden attribute drops the evaluation of its value. JS
7591
+ // still evaluates it, so a value that may have an effect (a call, an
7592
+ // assignment) keeps every spread of the element a spread, merged in order
7593
+ // at render time.
7594
+ if ([...overridden].some(attr => !ts.isJsxAttribute(attr) || !isEffectFreeAttrValue(attr.initializer))) {
7595
+ return { properties: [...attributes.properties], entries: new Map() }
7596
+ }
7597
+ return { properties: attributes.properties.filter(attr => !overridden.has(attr)), entries }
7598
+ }
7599
+
7600
+ /**
7601
+ * Whether evaluating a JSX attribute's value can have no effect: no value
7602
+ * (`disabled`), a string, or an expression {@link isEffectFreeExpression}
7603
+ * accepts.
7604
+ */
7605
+ function isEffectFreeAttrValue(value: ts.JsxAttributeValue | undefined): boolean {
7606
+ if (value === undefined || ts.isStringLiteral(value)) return true
7607
+ if (!ts.isJsxExpression(value)) return false
7608
+ return value.expression === undefined || isEffectFreeExpression(value.expression)
7609
+ }
7610
+
7611
+ /**
7612
+ * Whether a JSX attribute's value reads without an effect for a closed
7613
+ * rest spread's fallback ({@link closedRestFallbacks}), which evaluates it
7614
+ * only when the caller omits the key: an {@link isEffectFreeAttrValue}
7615
+ * value, or a member read off a name (`props.title`, `row?.label`). A prop
7616
+ * or row read has no effect the render can observe; anything else (a call,
7617
+ * an assignment) is refused, since JS evaluates it exactly once.
7618
+ */
7619
+ function isReadOnlyAttrValue(value: ts.JsxAttributeValue | undefined): boolean {
7620
+ if (isEffectFreeAttrValue(value)) return true
7621
+ if (value === undefined || !ts.isJsxExpression(value) || value.expression === undefined) return false
7622
+ let expr: ts.Expression = value.expression
7623
+ while (ts.isParenthesizedExpression(expr) || ts.isPropertyAccessExpression(expr)) expr = expr.expression
7624
+ return ts.isIdentifier(expr)
7625
+ }
7626
+
7627
+ /**
7628
+ * A literal (string, number, boolean, `null`, a template literal without
7629
+ * substitutions, a negated number) or a plain name (`label`), possibly
7630
+ * parenthesized. Anything else is treated as possibly having an effect: a
7631
+ * call, an assignment, `new`, an operator, and also a member access
7632
+ * (`props.value.title`), which can run a getter.
7633
+ */
7634
+ function isEffectFreeExpression(expr: ts.Expression): boolean {
7635
+ if (ts.isParenthesizedExpression(expr)) return isEffectFreeExpression(expr.expression)
7636
+ if (ts.isStringLiteral(expr) || ts.isNumericLiteral(expr) || ts.isNoSubstitutionTemplateLiteral(expr) || ts.isIdentifier(expr)) return true
7637
+ if (expr.kind === ts.SyntaxKind.TrueKeyword || expr.kind === ts.SyntaxKind.FalseKeyword || expr.kind === ts.SyntaxKind.NullKeyword) return true
7638
+ if (ts.isPrefixUnaryExpression(expr) && expr.operator === ts.SyntaxKind.MinusToken) return ts.isNumericLiteral(expr.operand)
7639
+ return false
7640
+ }
7641
+
7642
+ /**
7643
+ * The entries of a spread of a const holding a static object literal
7644
+ * (`const base = { label: 'x', tone: 'info' }`, `<Chip {...base} />`), as
7645
+ * the `key: value-source` pairs the spread passes, one per key with the
7646
+ * value of its last occurrence in the literal (#3844). Carried that way,
7647
+ * every backend reads each value as a literal instead of a bag no template
7648
+ * binds; {@link staticSpreadPlan} resolves them against the element's other
7649
+ * attributes.
7650
+ *
7651
+ * Only when the read reaches the const (`resolveStaticConstBinding`; a
7652
+ * module const also not shadowed by a component binding) and every entry
7653
+ * is a plain `key: value` whose value reads no name (a literal, or an array
7654
+ * or object of literals), and whose key is not `key`, `ref` or an event
7655
+ * handler name. `null` otherwise, and the spread stays a spread.
7656
+ */
7657
+ function expandStaticConstSpread(attr: ts.JsxSpreadAttribute, ctx: TransformContext): Array<{ key: string; text: string }> | null {
7658
+ let expr: ts.Expression = attr.expression
7659
+ while (ts.isParenthesizedExpression(expr)) expr = expr.expression
7660
+ if (!ts.isIdentifier(expr)) return null
7661
+ const name = expr.text
7662
+ const constant = resolveStaticConstBinding(name, ctx.analyzer.localConstants, n => ctx.scope.isBound(n))
7663
+ if (!constant || constant.parsed?.kind !== 'object-literal') return null
7664
+ if (constant.isModule && componentScopeNames(ctx.analyzer).has(name)) return null
7665
+ const init = parseConstInitializer(constant)
7666
+ if (!init || !ts.isObjectLiteralExpression(init)) return null
7667
+ return staticObjectSpreadEntries(init)
7668
+ }
7669
+
7670
+ /**
7671
+ * {@link expandStaticConstSpread}'s entries of the object literal `init`,
7672
+ * or `null` when one of them has no per-key form.
7673
+ */
7674
+ function staticObjectSpreadEntries(init: ts.ObjectLiteralExpression): Array<{ key: string; text: string }> | null {
7675
+ const entries = new Map<string, string>()
7676
+ for (const prop of init.properties) {
7677
+ if (!ts.isPropertyAssignment(prop)) return null
7678
+ const key = ts.isIdentifier(prop.name) || ts.isStringLiteral(prop.name) ? prop.name.text : null
7679
+ if (key === null || key === 'key' || key === 'ref' || isEventHandlerName(key)) return null
7680
+ if (freeIdentifiers(tsNodeToParsedExpr(prop.initializer))?.size !== 0) return null
7681
+ entries.set(key, astText(prop.initializer))
7682
+ }
7683
+ return [...entries].map(([key, text]) => ({ key, text }))
7684
+ }
7685
+
7686
+ /**
7687
+ * Which caller prop bag a spread forwards whole (`SpreadAttr.callerBag`):
7688
+ * its `expr` / `templateExpr` resolved through any alias hop
7689
+ * (`resolveRestSpreadOriginCore`). A name an enclosing loop row or callback
7690
+ * binds is that binding, not the component's bag (#3713: `items.map((props)
7691
+ * => <Tag {...props} />)`).
7692
+ */
7693
+ function callerBagOfSpread(value: SpreadAttr, ctx: TransformContext): 'props' | 'rest' | undefined {
7694
+ const constants = constantValuesByName(ctx)
7695
+ for (const name of new Set([value.expr, value.templateExpr])) {
7696
+ if (!name || ctx.scope.isBound(name)) continue
7697
+ const origin = resolveRestSpreadOriginCore(ctx.analyzer, constants, name)
7698
+ if (origin !== null) return origin
7699
+ }
7700
+ return undefined
7701
+ }
7702
+
7268
7703
  // Extract free identifiers from an attribute's initializer expression
7269
7704
  // (#1267). Returns undefined for boolean shorthand / string-literal attrs
7270
7705
  // that have no expression. Downstream callers can ask
@@ -7353,11 +7788,13 @@ function processAttributes(
7353
7788
  let ref: string | null = null
7354
7789
  let refExpr: ts.Expression | null = null
7355
7790
  let hasSpread = false
7791
+ const spreadPlan = staticSpreadPlan(attributes, ctx)
7792
+ const restPlan = closedRestFallbacks(spreadPlan.properties, spreadPlan.entries, ctx)
7356
7793
 
7357
- for (const attr of attributes.properties) {
7794
+ for (const attr of restPlan.properties) {
7358
7795
  if (ts.isJsxSpreadAttribute(attr)) {
7359
7796
  hasSpread = true
7360
- attrs.push(...expandSpreadAttribute(attr, ctx))
7797
+ attrs.push(...expandSpreadAttribute(attr, ctx, spreadPlan.entries.get(attr), restPlan.fallbacks.get(attr)))
7361
7798
  continue
7362
7799
  }
7363
7800
 
@@ -9009,8 +9446,10 @@ function processComponentProps(
9009
9446
  ctx: TransformContext
9010
9447
  ): IRProp[] {
9011
9448
  const props: IRProp[] = []
9449
+ const spreadPlan = staticSpreadPlan(attributes, ctx)
9450
+ const restPlan = closedRestFallbacks(spreadPlan.properties, spreadPlan.entries, ctx)
9012
9451
 
9013
- for (const attr of attributes.properties) {
9452
+ for (const attr of restPlan.properties) {
9014
9453
  if (ts.isJsxSpreadAttribute(attr)) {
9015
9454
  // `restExpandedKey` (#3057) is consumed only by the element-attribute
9016
9455
  // path (`collect-elements.ts`'s `attr.restExpandedKey` branch) — a
@@ -9019,7 +9458,7 @@ function processComponentProps(
9019
9458
  // rewrite, so `IRProp` declares no such field. Strip it here rather
9020
9459
  // than letting the shared helper's per-key marking leak into IRProp
9021
9460
  // as an inert flag nothing reads.
9022
- props.push(...expandSpreadAttribute(attr, ctx).map(({ restExpandedKey: _restExpandedKey, ...prop }) => prop))
9461
+ props.push(...expandSpreadAttribute(attr, ctx, spreadPlan.entries.get(attr), restPlan.fallbacks.get(attr)).map(({ restExpandedKey: _restExpandedKey, restFallback: _restFallback, ...prop }) => markPropsObjectSpread(prop)))
9023
9462
  continue
9024
9463
  }
9025
9464
 
@@ -9826,6 +10265,19 @@ function forwardsCallerRestProps(attrs: IRAttribute[], ctx: TransformContext): b
9826
10265
  return false
9827
10266
  }
9828
10267
 
10268
+ /**
10269
+ * Mark a child-component spread of the component's own props object
10270
+ * (`SpreadAttr.propsObject`, #3688): the `'props'` case of
10271
+ * `SpreadAttr.callerBag` (`callerBagOfSpread`). A `{...rest}` bag leaves out
10272
+ * the keys the component destructured, so it does not merge as the caller's
10273
+ * props.
10274
+ */
10275
+ function markPropsObjectSpread<T extends { value: AttrValue }>(prop: T): T {
10276
+ const value = prop.value
10277
+ if (value.kind !== 'spread' || value.callerBag !== 'props') return prop
10278
+ return { ...prop, value: { ...value, propsObject: true } }
10279
+ }
10280
+
9829
10281
  /** `ctx.analyzer.localConstants` indexed by name → value text, memoized per component walk. */
9830
10282
  function constantValuesByName(ctx: TransformContext): ReadonlyMap<string, string | undefined> {
9831
10283
  if (ctx._constantValuesByName) return ctx._constantValuesByName