@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
@@ -15,10 +15,11 @@
15
15
  * shadow the name are respected.
16
16
  */
17
17
 
18
- import { collectContextConsumers, lookupLiteralConst } from '../augment-inherited-props.ts'
19
- import { freeIdentifiers, inlineBinding, parseExpression, stringifyParsedExpr, type ParsedExpr } from '../expression-parser.ts'
20
- import type { ConstantInfo, ExpressionAttr, IRMetadata } from '../types.ts'
18
+ import { collectContextConsumers, lookupLiteralConst, resolveStaticConstBinding } from '../augment-inherited-props.ts'
19
+ import { freeIdentifiers, inlineBinding, mapParsedExpr, parseExpression, stringifyParsedExpr, type ParsedExpr } from '../expression-parser.ts'
20
+ import type { ConstantInfo, ExpressionAttr, IRMetadata, ParamInfo } from '../types.ts'
21
21
  import { componentBindings } from '../relocate.ts'
22
+ import { PROPS_OBJECT_IDENTIFIER } from '../scope/binding-scope.ts'
22
23
 
23
24
  export interface ComputedConstContext {
24
25
  constants: IRMetadata['localConstants'] | undefined
@@ -28,6 +29,25 @@ export interface ComputedConstContext {
28
29
  contextConsumers: ReadonlySet<string>
29
30
  /** Consts a props destructure binds, which the adapter binds as props params. */
30
31
  propsBindings: ReadonlySet<string>
32
+ /**
33
+ * Component-scope names that hold a prop as passed, with the prop's
34
+ * caller-facing key: a destructured signature param (`{ children: kids }`
35
+ * → `kids` → `children`) or a props destructure const. Empty when the
36
+ * props object identifier names something else.
37
+ */
38
+ propReads: ReadonlyMap<string, string>
39
+ /** Component-scope local functions, which shadow a module const of the same name. */
40
+ localFunctions: ReadonlySet<string>
41
+ /**
42
+ * Names the component scope lexically binds (the props object, destructured
43
+ * and rest props, its consts, local functions, signals, memos), which
44
+ * shadow a module binding of the same name. A module const's initializer
45
+ * never reads one of them. A prop reachable only through the props object
46
+ * (`function C(props: { label: string })`) binds no name.
47
+ */
48
+ componentNames: ReadonlySet<string>
49
+ /** The component's props params and props object name, which type an index read (`keyedValue`). */
50
+ props: { params: readonly ParamInfo[]; objectName: string | null }
31
51
  /** Whether a loop row or callback binds `name` where the expression is read. */
32
52
  isShadowed(name: string): boolean
33
53
  /** Whether the adapter binds the const `name` itself, so a read of it stays as written. */
@@ -52,6 +72,10 @@ export function computedConstContext(
52
72
  getters: new Set([...metadata.signals.map(s => s.getter), ...metadata.memos.map(m => m.name)]),
53
73
  contextConsumers: new Set(collectContextConsumers(metadata).map(c => c.localName)),
54
74
  propsBindings: propsBindingNames(metadata),
75
+ propReads: propReadKeys(metadata, bindings),
76
+ localFunctions: new Set(metadata.localFunctions.filter(f => !f.isModule).map(f => f.name)),
77
+ componentNames: componentScopeNames(metadata),
78
+ props: { params: metadata.propsParams, objectName: metadata.propsObjectName },
55
79
  isShadowed,
56
80
  isAdapterBound,
57
81
  isGlobal: name => !bindings.has(name) && name !== metadata.restPropsName && !isShadowed(name),
@@ -83,6 +107,56 @@ function propsBindingNames(metadata: IRMetadata): Set<string> {
83
107
  return names
84
108
  }
85
109
 
110
+ /**
111
+ * {@link ComputedConstContext.componentNames}. Not `componentBindings`, which
112
+ * also lists every typed prop of a props object as a `prop` binding.
113
+ */
114
+ export function componentScopeNames(
115
+ metadata: Pick<IRMetadata, 'propsObjectName' | 'propsParams' | 'restPropsName' | 'localConstants' | 'localFunctions' | 'signals' | 'memos'>,
116
+ ): Set<string> {
117
+ const names = new Set<string>()
118
+ if (metadata.propsObjectName !== null) names.add(metadata.propsObjectName)
119
+ // With no props object the signature destructures, so every param is bound.
120
+ else for (const p of metadata.propsParams) names.add(p.name)
121
+ if (metadata.restPropsName) names.add(metadata.restPropsName)
122
+ for (const c of metadata.localConstants) if (!c.isModule) names.add(c.name)
123
+ for (const f of metadata.localFunctions) if (!f.isModule) names.add(f.name)
124
+ for (const s of metadata.signals) {
125
+ if (s.isModule) continue
126
+ names.add(s.getter)
127
+ if (s.setter) names.add(s.setter)
128
+ }
129
+ for (const m of metadata.memos) if (!m.isModule) names.add(m.name)
130
+ return names
131
+ }
132
+
133
+ /**
134
+ * {@link ComputedConstContext.propReads}: each component-scope name bound to
135
+ * a prop as passed, with the prop's key, so a read of it can be spelled
136
+ * `props.<key>` where a loop row or callback shadows the name. A template
137
+ * reads that as the prop's own variable, which holds a destructure default
138
+ * already. Only when the props object identifier `props` names the props
139
+ * object or nothing in the component, so the spelling cannot read another
140
+ * binding.
141
+ */
142
+ function propReadKeys(metadata: IRMetadata, bindings: ReadonlyMap<string, unknown>): Map<string, string> {
143
+ const reads = new Map<string, string>()
144
+ const propsObject = metadata.propsObjectName
145
+ // Under another props object name (`function C(p)`) the adapters do not
146
+ // agree on what a read of `props` is, so no prop read is respelled.
147
+ if (propsObject === null ? bindings.has(PROPS_OBJECT_IDENTIFIER) : propsObject !== PROPS_OBJECT_IDENTIFIER) return reads
148
+ const destructures = propsBindingNames(metadata)
149
+ for (const param of metadata.propsParams) {
150
+ if (param.isRest) continue
151
+ // A signature that names the props object binds no param locally; only
152
+ // a props destructure const does.
153
+ if (propsObject !== null && !destructures.has(param.name)) continue
154
+ if (bindings.get(param.name) !== 'prop') continue
155
+ reads.set(param.name, param.sourceName ?? param.name)
156
+ }
157
+ return reads
158
+ }
159
+
86
160
  /** Upper bound on const-of-const chains, a guard against a malformed cycle. */
87
161
  const MAX_DEPTH = 16
88
162
 
@@ -106,13 +180,147 @@ function inlineOnce(expr: ParsedExpr, ctx: ComputedConstContext): ParsedExpr {
106
180
  if (!free) return expr
107
181
  let result = expr
108
182
  for (const name of free) {
183
+ const object = objectConstInitializer(name, ctx)
184
+ if (object) {
185
+ result = projectObjectReads(result, name, object, ctx) ?? result
186
+ continue
187
+ }
109
188
  const init = inlinableInitializer(name, ctx)
110
189
  if (!init) continue
111
- result = inlineBinding(result, name, init) ?? result
190
+ result = inlineBinding(result, name, init) ?? inlineUnderCallbacks(result, name, init, ctx) ?? result
112
191
  }
113
192
  return result
114
193
  }
115
194
 
195
+ /**
196
+ * {@link inlineBinding} for an initializer a callback param inside `expr`
197
+ * would capture (`rows.filter(a => a !== b)` with `const b = a`): the
198
+ * initializer resolved in the component scope first
199
+ * ({@link resolveInComponentScope}), so none of its free names is one the
200
+ * expression's callbacks bind.
201
+ */
202
+ function inlineUnderCallbacks(expr: ParsedExpr, name: string, init: ParsedExpr, ctx: ComputedConstContext): ParsedExpr | null {
203
+ const params = arrowParamNames(expr)
204
+ if (params.size === 0) return null
205
+ const resolved = resolveInComponentScope(init, ctx, n => params.has(n) || ctx.isShadowed(n))
206
+ return resolved ? inlineBinding(expr, name, resolved) : null
207
+ }
208
+
209
+ /** Every param name an arrow anywhere in `expr` binds. */
210
+ function arrowParamNames(expr: ParsedExpr): Set<string> {
211
+ const names = new Set<string>()
212
+ const visit = (node: unknown): void => {
213
+ if (node === null || typeof node !== 'object') return
214
+ if (Array.isArray(node)) {
215
+ node.forEach(visit)
216
+ return
217
+ }
218
+ const e = node as ParsedExpr
219
+ if (e.kind === 'arrow') for (const p of e.params) names.add(p)
220
+ for (const value of Object.values(e)) visit(value)
221
+ }
222
+ visit(expr)
223
+ return names
224
+ }
225
+
226
+ /** The scope a const's initializer is written in, which its free names resolve against. */
227
+ type InitScope = 'component' | 'module'
228
+
229
+ /**
230
+ * `init`, an initializer written in `scope`, with each free name replaced
231
+ * where reading it at the use site would reach a different binding: one
232
+ * `captured` holds there (a loop row or callback binds it), or, for a module
233
+ * const's initializer, one the component scope binds. The name becomes what
234
+ * it holds in `scope`: a computed or literal const its own initializer,
235
+ * resolved the same way (`const a = children; const b = a` read in
236
+ * `rows.map(a => …{b}…)` reads `children`), and a component-scope prop
237
+ * binding `props.<key>`, which the adapters read as the prop wherever a row
238
+ * rebinds its bare name (#3696). `null` when such a name holds anything
239
+ * else, or when `props` itself is captured.
240
+ */
241
+ function resolveInitializer(
242
+ init: ParsedExpr,
243
+ ctx: ComputedConstContext,
244
+ captured: (name: string) => boolean,
245
+ scope: InitScope,
246
+ depth = 0,
247
+ ): ParsedExpr | null {
248
+ const free = freeIdentifiers(init)
249
+ if (!free || depth >= MAX_DEPTH) return null
250
+ let result = init
251
+ for (const name of free) {
252
+ if (!captured(name) && !(scope === 'module' && ctx.componentNames.has(name))) continue
253
+ const value = scope === 'module' ? moduleScopeValue(name, ctx, captured, depth) : componentScopeValue(name, ctx, captured, depth)
254
+ const next = value ? inlineBinding(result, name, value) : null
255
+ if (!next) return null
256
+ result = next
257
+ }
258
+ return result
259
+ }
260
+
261
+ /** {@link resolveInitializer} for an initializer written in the component scope. */
262
+ function resolveInComponentScope(init: ParsedExpr, ctx: ComputedConstContext, captured: (name: string) => boolean): ParsedExpr | null {
263
+ return resolveInitializer(init, ctx, captured, 'component')
264
+ }
265
+
266
+ /** What the component-scope name `name` holds, for {@link resolveInitializer}. */
267
+ function componentScopeValue(
268
+ name: string,
269
+ ctx: ComputedConstContext,
270
+ captured: (name: string) => boolean,
271
+ depth: number,
272
+ ): ParsedExpr | null {
273
+ if (ctx.getters.has(name) || ctx.contextConsumers.has(name) || ctx.localFunctions.has(name)) return null
274
+ if (ctx.isAdapterBound(name)) return null
275
+ const key = ctx.propReads.get(name)
276
+ if (key !== undefined) {
277
+ if (captured(PROPS_OBJECT_IDENTIFIER)) return null
278
+ return { kind: 'member', object: { kind: 'identifier', name: PROPS_OBJECT_IDENTIFIER }, property: key, computed: false, optional: false }
279
+ }
280
+ // Any other component binding of the name is not a const this can read.
281
+ if (ctx.componentNames.has(name) && !componentConst(name, ctx)) return null
282
+ return constValue(componentConst(name, ctx) ?? moduleConst(name, ctx), ctx, captured, depth)
283
+ }
284
+
285
+ /**
286
+ * What the module-scope name `name` holds, for {@link resolveInitializer}:
287
+ * only a module const, whatever the component scope binds by that name.
288
+ * `isAdapterBound` names a component-scope binding, so it does not apply.
289
+ */
290
+ function moduleScopeValue(
291
+ name: string,
292
+ ctx: ComputedConstContext,
293
+ captured: (name: string) => boolean,
294
+ depth: number,
295
+ ): ParsedExpr | null {
296
+ return constValue(moduleConst(name, ctx), ctx, captured, depth)
297
+ }
298
+
299
+ /** A const's initializer resolved in the scope it is declared in, or `null` when it is not one a template can inline. */
300
+ function constValue(
301
+ constant: ConstantInfo | undefined,
302
+ ctx: ComputedConstContext,
303
+ captured: (name: string) => boolean,
304
+ depth: number,
305
+ ): ParsedExpr | null {
306
+ const init = constant?.parsed
307
+ // A props destructure const is the component's; a module const of that name is not one.
308
+ if (!constant || !init || (!constant.isModule && ctx.propsBindings.has(constant.name))) return null
309
+ const literal = lookupLiteralConst(constant.name, [constant], () => false) !== null
310
+ if (!literal && !(isPlainComputedConst(constant, init) && callsOnlyGetters(init, constant.isModule ? new Set() : ctx.getters))) return null
311
+ return resolveInitializer(init, ctx, captured, constant.isModule ? 'module' : 'component', depth + 1)
312
+ }
313
+
314
+ /** The component-scope const `name`. */
315
+ function componentConst(name: string, ctx: ComputedConstContext): ConstantInfo | undefined {
316
+ return ctx.constants?.find(c => c.name === name && !c.isModule)
317
+ }
318
+
319
+ /** The module-scope const `name`. */
320
+ function moduleConst(name: string, ctx: ComputedConstContext): ConstantInfo | undefined {
321
+ return ctx.constants?.find(c => c.name === name && c.isModule)
322
+ }
323
+
116
324
  /**
117
325
  * An `{expr}` attribute value read through {@link inlineComputedConsts}, so
118
326
  * the attribute's own plan (a nullable prop read drops the attribute) sees
@@ -131,17 +339,18 @@ export function inlineComputedConstAttr(value: ExpressionAttr, ctx: ComputedCons
131
339
 
132
340
  /** The initializer of a const read `name` stands for, or `null` when the read stays as it is. */
133
341
  function inlinableInitializer(name: string, ctx: ComputedConstContext): ParsedExpr | null {
134
- const constant = ctx.constants?.find(c => c.name === name)
342
+ // A component-scope binding of the name shadows a module const.
343
+ const constant = componentConst(name, ctx) ?? (ctx.componentNames.has(name) ? undefined : moduleConst(name, ctx))
135
344
  const init = constant?.parsed
136
345
  if (!constant || !init || !isPlainComputedConst(constant, init)) return null
137
346
  if (ctx.isShadowed(name) || ctx.getters.has(name) || ctx.contextConsumers.has(name) || ctx.propsBindings.has(name)) return null
138
347
  if (ctx.isAdapterBound(name)) return null
139
348
  // An adapter already inlines a literal const in its own syntax.
140
- if (lookupLiteralConst(name, ctx.constants, ctx.isShadowed) !== null) return null
141
- // A free name the read site rebinds would be captured by the substitution.
142
- const free = freeIdentifiers(init)
143
- if (!free || [...free].some(n => ctx.isShadowed(n))) return null
144
- return callsOnlyGetters(init, ctx.getters) ? init : null
349
+ if (lookupLiteralConst(name, [constant], ctx.isShadowed) !== null) return null
350
+ if (!callsOnlyGetters(init, ctx.getters)) return null
351
+ // A free name the read site rebinds would be captured by the substitution:
352
+ // it is read as what it holds where the const is declared instead.
353
+ return resolveInitializer(init, ctx, n => ctx.isShadowed(n), constant.isModule ? 'module' : 'component')
145
354
  }
146
355
 
147
356
  /**
@@ -183,3 +392,227 @@ function callsOnlyGetters(init: ParsedExpr, getters: ReadonlySet<string>): boole
183
392
  visit(init)
184
393
  return ok
185
394
  }
395
+
396
+ /**
397
+ * The initializer of a `const` holding an object literal (`const flags = { a:
398
+ * n > 1, label: 'L' + n }`, `const labels = { ok: 'Fine', err: 'Broken' }`)
399
+ * that a read of `name` stands for, resolved in the scope the const is
400
+ * declared in, or `null` when the read stays as it is. The same visibility
401
+ * rules as {@link inlinableInitializer}, with the const a read reaches decided
402
+ * by `resolveStaticConstBinding`; the literal must list plain
403
+ * `key: value` entries only (no spread), so each key's value is known.
404
+ */
405
+ function objectConstInitializer(name: string, ctx: ComputedConstContext): ObjectLiteral | null {
406
+ if (ctx.componentNames.has(name) && !componentConst(name, ctx)) return null
407
+ const constant = resolveStaticConstBinding(name, ctx.constants, n => ctx.isShadowed(n))
408
+ const init = constant?.parsed
409
+ if (!constant || init?.kind !== 'object-literal' || constant.systemConstructKind) return null
410
+ if (literalValues(init) === null) return null
411
+ if (ctx.isShadowed(name) || ctx.getters.has(name) || ctx.contextConsumers.has(name) || ctx.propsBindings.has(name)) return null
412
+ if (ctx.isAdapterBound(name)) return null
413
+ if (!callsOnlyGetters(init, constant.isModule ? new Set() : ctx.getters)) return null
414
+ const resolved = resolveInitializer(init, ctx, n => ctx.isShadowed(n), constant.isModule ? 'module' : 'component')
415
+ return resolved?.kind === 'object-literal' ? resolved : null
416
+ }
417
+
418
+ /**
419
+ * `expr` with each read of a property of the object const `name` replaced by
420
+ * what JS reads there (#3844): `flags.label` by the value the literal gives
421
+ * `label` (`undefined` for a key it does not list), and `labels[kind]` by
422
+ * the conditional that picks the value of the key `kind` equals
423
+ * ({@link keyedValue}). A const that holds an object has no binding in a
424
+ * template, the same as a computed const.
425
+ *
426
+ * An index whose keys are not all known at compile time is read off the
427
+ * literal itself, which the adapter refuses (BF101). `null` (the read stays
428
+ * as written) when `expr` reads `name` whole or reads a key
429
+ * `Object.prototype` holds.
430
+ */
431
+ function projectObjectReads(
432
+ expr: ParsedExpr,
433
+ name: string,
434
+ object: ObjectLiteral,
435
+ ctx: ComputedConstContext,
436
+ ): ParsedExpr | null {
437
+ const objectFree = freeIdentifiers(object) ?? new Set<string>()
438
+ let ok = true
439
+ // What a read chain rooted at `name` (`flags`, `conf.inner`, `labels[k]`)
440
+ // holds, or null for a chain rooted elsewhere.
441
+ const resolve = (e: ParsedExpr, enclosing: ReadonlySet<string>): ParsedExpr | null => {
442
+ if (e.kind === 'identifier') return e.name === name && !enclosing.has(name) ? object : null
443
+ if (e.kind !== 'member' && e.kind !== 'index-access') return null
444
+ const base = resolve(e.object, enclosing)
445
+ if (base === null) return null
446
+ // A read off a value that is not an object (`flags.label.length`) is
447
+ // left to the walk, which projects the inner read.
448
+ if (base.kind !== 'object-literal') return null
449
+ const values = literalValues(base)
450
+ const value = values === null ? undefined : e.kind === 'member' ? memberValue(values, e.property) : keyedValue(values, e.index, enclosing, ctx)
451
+ if (value === undefined) ok = false
452
+ // An index whose keys are not known reads the literal itself, which no
453
+ // template lowers: the adapter refuses it (BF101) instead of reading an
454
+ // unbound name.
455
+ if (value === UNPROVABLE_INDEX && e.kind === 'index-access') return { kind: 'index-access', object: base, index: e.index }
456
+ return value ?? null
457
+ }
458
+ const result = mapParsedExpr(expr, (e, enclosing) => {
459
+ const value = resolve(e, enclosing)
460
+ if (value === null) return null
461
+ // A value read where a callback param rebinds one of its names, or an
462
+ // object read whole, has no projection.
463
+ if (value.kind === 'object-literal' || [...enclosing].some(p => objectFree.has(p))) ok = false
464
+ return value
465
+ })
466
+ return ok ? foldUndefinedTests(result) : null
467
+ }
468
+
469
+ /**
470
+ * `expr` with each conditional whose test compares two operands known at
471
+ * compile time against `undefined` (`'x' === undefined`, `undefined ===
472
+ * undefined`) replaced by the branch it takes. A projected read of a key
473
+ * the literal does or does not list leaves exactly this behind in a
474
+ * destructure default (`conf.tone === undefined ? 'x' : conf.tone`), and a
475
+ * backend need not spell `undefined` the same in every position.
476
+ */
477
+ function foldUndefinedTests(expr: ParsedExpr): ParsedExpr {
478
+ return mapParsedExpr(expr, e => {
479
+ if (e.kind !== 'conditional' || e.test.kind !== 'binary' || (e.test.op !== '===' && e.test.op !== '!==')) return null
480
+ const equal = undefinedEquality(e.test.left, e.test.right)
481
+ if (equal === null) return null
482
+ return foldUndefinedTests((equal === (e.test.op === '===')) ? e.consequent : e.alternate)
483
+ })
484
+ }
485
+
486
+ /** Whether `a === b` holds, when one side is `undefined` and the other a literal or `undefined`; null otherwise. */
487
+ function undefinedEquality(a: ParsedExpr, b: ParsedExpr): boolean | null {
488
+ const isUndefined = (e: ParsedExpr) => e.kind === 'identifier' && e.name === 'undefined'
489
+ const known = (e: ParsedExpr) => isUndefined(e) || e.kind === 'literal'
490
+ if (!known(a) || !known(b) || (!isUndefined(a) && !isUndefined(b))) return null
491
+ return isUndefined(a) && isUndefined(b)
492
+ }
493
+
494
+ type ObjectLiteral = Extract<ParsedExpr, { kind: 'object-literal' }>
495
+
496
+ /** The value of each key `object` lists (the last one for a repeated key), or null when it spreads another object. */
497
+ function literalValues(object: ObjectLiteral): Map<string, ParsedExpr> | null {
498
+ const values = new Map<string, ParsedExpr>()
499
+ for (const p of object.properties) {
500
+ if (p.kind === 'spread') return null
501
+ values.set(p.key, p.value)
502
+ }
503
+ return values
504
+ }
505
+
506
+ /**
507
+ * What `object.<key>` reads: the value the literal gives `key`, and
508
+ * `undefined` for a key it does not list. `undefined` (no projection) for a
509
+ * key `Object.prototype` holds, which JS reads from there.
510
+ */
511
+ function memberValue(values: ReadonlyMap<string, ParsedExpr>, key: string): ParsedExpr | undefined {
512
+ const value = values.get(key)
513
+ if (value) return value
514
+ return key in Object.prototype ? undefined : { kind: 'identifier', name: 'undefined' }
515
+ }
516
+
517
+ /** {@link keyedValue}'s answer for an index whose keys are not all known. */
518
+ const UNPROVABLE_INDEX: ParsedExpr = { kind: 'unsupported', raw: '', reason: 'index keys not known at compile time' }
519
+
520
+ /**
521
+ * `values[index]` as a conditional over the keys the index can hold, with
522
+ * `undefined` for one the literal does not list ({@link projectObjectReads}).
523
+ * Sound only when every key the index can hold is known: its type is a
524
+ * union of string literals (plus `null` / `undefined`) — a prop typed
525
+ * `'ok' | 'err'` — so strict equality with each key is the property lookup
526
+ * JS does. {@link UNPROVABLE_INDEX} otherwise, and also when the index calls
527
+ * something other than a signal or memo getter (the conditional repeats
528
+ * it), when a key it can hold is inherited from `Object.prototype`
529
+ * (`labels['toString']` reads a function), or when it can be `null` /
530
+ * `undefined` and the literal lists `'null'` / `'undefined'`.
531
+ */
532
+ function keyedValue(
533
+ values: ReadonlyMap<string, ParsedExpr>,
534
+ index: ParsedExpr,
535
+ enclosing: ReadonlySet<string>,
536
+ ctx: ComputedConstContext,
537
+ ): ParsedExpr {
538
+ if (!readsOnly(index, ctx.getters)) return UNPROVABLE_INDEX
539
+ // A computed const in the index (`const variant = props.variant ?? 'x'`)
540
+ // is typed as what it holds.
541
+ const domain = indexKeyDomain(inlineComputedConsts(index, ctx), enclosing, ctx)
542
+ if (domain === null) return UNPROVABLE_INDEX
543
+ if (domain.keys.some(k => !values.has(k) && k in Object.prototype)) return UNPROVABLE_INDEX
544
+ if (domain.nullish.some(k => values.has(k))) return UNPROVABLE_INDEX
545
+ let result: ParsedExpr = { kind: 'identifier', name: 'undefined' }
546
+ for (const key of [...domain.keys].reverse()) {
547
+ const value = values.get(key)
548
+ if (!value) continue
549
+ result = {
550
+ kind: 'conditional',
551
+ test: { kind: 'binary', op: '===', left: index, right: { kind: 'literal', value: key, literalType: 'string' } },
552
+ consequent: value,
553
+ alternate: result,
554
+ }
555
+ }
556
+ return result
557
+ }
558
+
559
+ /** The keys an index can hold ({@link keyedValue}): string keys, and whether it can be `null` / `undefined`. */
560
+ interface KeyDomain {
561
+ keys: string[]
562
+ nullish: Array<'null' | 'undefined'>
563
+ }
564
+
565
+ /**
566
+ * The keys an index read can hold, from its declared type: a prop read
567
+ * (`kind`, `props.kind`) whose declared type admits only string literals,
568
+ * `null` and `undefined` (`ParamInfo.literalKeys`; an optional prop adds
569
+ * `undefined`), or `a ?? 'x'` over such a read. `null` for any other index, including a name a loop row or callback
570
+ * binds.
571
+ */
572
+ function indexKeyDomain(index: ParsedExpr, enclosing: ReadonlySet<string>, ctx: ComputedConstContext): KeyDomain | null {
573
+ if (index.kind === 'logical' && index.op === '??') {
574
+ const left = indexKeyDomain(index.left, enclosing, ctx)
575
+ const right = index.right.kind === 'literal' && typeof index.right.value === 'string' ? index.right.value : null
576
+ if (!left || right === null) return left === null || right === null ? null : left
577
+ return left.nullish.length === 0 ? left : { keys: [...new Set([...left.keys, right])], nullish: [] }
578
+ }
579
+ const param = indexPropParam(index, enclosing, ctx)
580
+ if (!param) return null
581
+ if (!param.literalKeys) return null
582
+ const domain: KeyDomain = { keys: [...param.literalKeys.keys], nullish: [...param.literalKeys.nullish] }
583
+ const readsDefault = index.kind === 'identifier' && param.defaultValue !== undefined
584
+ if (param.optional && !readsDefault && !domain.nullish.includes('undefined')) domain.nullish.push('undefined')
585
+ return domain
586
+ }
587
+
588
+ /** The prop param an index read reads whole (`kind`, `props.kind`), or undefined. */
589
+ function indexPropParam(index: ParsedExpr, enclosing: ReadonlySet<string>, ctx: ComputedConstContext): ParamInfo | undefined {
590
+ const visible = (n: string) => !enclosing.has(n) && !ctx.isShadowed(n)
591
+ const params = ctx.props.params.filter(p => !p.isRest)
592
+ if (index.kind === 'identifier') {
593
+ if (!visible(index.name)) return undefined
594
+ if (ctx.props.objectName !== null && !ctx.propsBindings.has(index.name)) return undefined
595
+ return params.find(p => p.name === index.name)
596
+ }
597
+ if (index.kind !== 'member' || index.object.kind !== 'identifier' || index.object.name !== ctx.props.objectName) return undefined
598
+ if (!visible(index.object.name)) return undefined
599
+ return params.find(p => p.sourceName === undefined && p.name === index.property)
600
+ }
601
+
602
+ /** Whether evaluating `expr` twice reads the same value: it calls nothing but signal and memo getters, and holds no function. */
603
+ function readsOnly(expr: ParsedExpr, getters: ReadonlySet<string>): boolean {
604
+ let ok = true
605
+ const visit = (node: unknown): void => {
606
+ if (!ok || node === null || typeof node !== 'object') return
607
+ if (Array.isArray(node)) {
608
+ node.forEach(visit)
609
+ return
610
+ }
611
+ const e = node as ParsedExpr
612
+ if (e.kind === 'arrow' || e.kind === 'unsupported') ok = false
613
+ else if (e.kind === 'call' && !(e.callee.kind === 'identifier' && e.args.length === 0 && getters.has(e.callee.name))) ok = false
614
+ else for (const value of Object.values(e)) visit(value)
615
+ }
616
+ visit(expr)
617
+ return ok
618
+ }
@@ -8,12 +8,16 @@
8
8
  import { augmentInheritedPropAccesses, collectModuleStringConsts } from '../augment-inherited-props.ts'
9
9
  import { buildImportAliasMap } from '../ir-to-client-js/component-scope.ts'
10
10
  import { prepareLoweringMatchers, type LoweringMatcher } from '../lowering-registry.ts'
11
+ import type { ParsedExpr } from '../expression-parser.ts'
11
12
  import {
12
13
  collectNullableSignalGetters,
13
14
  collectNullishAttrContext,
15
+ type ArithmeticCoercion,
14
16
  type NullishAttrContext,
15
17
  } from '../nullable-signal-attr.ts'
16
18
  import { BindingScope } from '../scope/binding-scope.ts'
19
+ import { declaredValueTypes, loopRowType, type DeclaredValueTypes } from './loop-row-type.ts'
20
+ import { collectOperandTyping, EMPTY_OPERAND_TYPING, type OperandTyping, type ScopedOperandTyping } from './operand-typing.ts'
17
21
  import { rootPropAliasesForLoop, rootPropAliasNames } from '../scope/root-prop-alias.ts'
18
22
  import type {
19
23
  CompilerError,
@@ -24,6 +28,13 @@ import type {
24
28
  IRMetadata,
25
29
  PreambleValueDeclaration,
26
30
  } from '../types.ts'
31
+ import {
32
+ arithmeticCoercionOrRefuse,
33
+ refuseAmbiguousNilArithmetic,
34
+ refuseAmbiguousNilMemoArithmetic,
35
+ type AmbiguousNilArithmeticSink,
36
+ } from './ambiguous-nil-arithmetic.ts'
37
+ import { refuseNonPrimitiveStrictEquality } from './non-primitive-equality.ts'
27
38
  import { collectImportedLoopChildComponentErrors } from './component-tree.ts'
28
39
  import { computedConstContext, type ComputedConstContext } from './computed-const.ts'
29
40
  import { searchParamsLocalNames } from './env-signal.ts'
@@ -120,6 +131,14 @@ export abstract class DslTemplateAdapter extends BaseAdapter {
120
131
  protected booleanTypedProps: Set<string> = new Set()
121
132
  /** Names (signal getters + props) whose value is a string (`stringValueNamesFor`). */
122
133
  protected stringValueNames: Set<string> = new Set()
134
+ /** The declared types a loop row's type is read from (`loopRowType`, #3762). */
135
+ protected declaredTypes: DeclaredValueTypes | null = null
136
+ /**
137
+ * The component's operand typing (`collectOperandTyping`), which the
138
+ * emitters' primitive plans read through the scope at the emission site
139
+ * (`operandTypingAt`, #3824).
140
+ */
141
+ protected operandTyping: OperandTyping = EMPTY_OPERAND_TYPING
123
142
  /**
124
143
  * Module-scope pure-string consts (`const x = 'literal'`), keyed by name →
125
144
  * unescaped value. A className template literal that references such a
@@ -213,6 +232,28 @@ export abstract class DslTemplateAdapter extends BaseAdapter {
213
232
  */
214
233
  protected resetAdapterState(_ir: ComponentIR): void {}
215
234
 
235
+ /**
236
+ * Whether `name` (a signal getter, prop, local constant or loop binding)
237
+ * holds a string value at `scope`, which picks the template's string
238
+ * concatenation for a JS `+` (`isStringConcatBinary`). A loop row or
239
+ * callback binding of the same name shadows the outer typing; a row field
240
+ * read (`path`: `row.id`) takes the row type's declared field type.
241
+ * `componentProperty`: read as `props.<name>`.
242
+ */
243
+ protected isStringValueNameAt(
244
+ name: string,
245
+ componentProperty = false,
246
+ path: readonly string[] = [],
247
+ scope: BindingScope = this.scope,
248
+ ): boolean {
249
+ return scope.isStringValueName(name, n => this.stringValueNames.has(n), componentProperty, path, this.declaredTypes?.namedFields)
250
+ }
251
+
252
+ /** The component's operand typing at `scope` (the emission site's, by default). */
253
+ protected operandTypingAt(scope: BindingScope = this.scope): ScopedOperandTyping {
254
+ return this.operandTyping.at(scope)
255
+ }
256
+
216
257
  /** `render()` under `scope`, the current scope restored afterwards. */
217
258
  protected renderInScope<T>(scope: BindingScope, render: () => T): T {
218
259
  const outer = this.scope
@@ -224,6 +265,36 @@ export abstract class DslTemplateAdapter extends BaseAdapter {
224
265
  }
225
266
  }
226
267
 
268
+ /**
269
+ * The coercion an arithmetic operand's emitter spells
270
+ * (`arithmeticOperandCoercion`), refusing an operand whose nil the
271
+ * declared type cannot classify (`arithmeticCoercionOrRefuse`, #3700).
272
+ * `isShadowed` is the adapter's scope test at the emission site.
273
+ */
274
+ protected arithmeticCoercion(
275
+ op: string,
276
+ operand: ParsedExpr,
277
+ other: ParsedExpr | undefined,
278
+ isShadowed: (name: string) => boolean,
279
+ ): ArithmeticCoercion {
280
+ return arithmeticCoercionOrRefuse(op, operand, other, this.nullishAttrCtx, isShadowed, this.ambiguousNilSink())
281
+ }
282
+
283
+ /**
284
+ * Refuse the ambiguous-nil arithmetic (#3700) in a whole expression the
285
+ * adapter lowers through its own renderer rather than per operator: a
286
+ * `.filter()` predicate, read in the current scope with the callback's
287
+ * own `params` (its parameter and block locals) entered as a callback
288
+ * frame.
289
+ */
290
+ protected refuseAmbiguousNilArithmeticIn(expr: ParsedExpr, params: readonly string[]): void {
291
+ refuseAmbiguousNilArithmetic(expr, this.nullishAttrCtx, this.scope.enterCallback(params), this.ambiguousNilSink())
292
+ }
293
+
294
+ private ambiguousNilSink(): AmbiguousNilArithmeticSink {
295
+ return { errors: this.errors, componentName: this.componentName }
296
+ }
297
+
227
298
  /** {@link planLoop} against the current scope and the component's constants. */
228
299
  protected loopPlanFor<Spelled>(loop: IRLoop, spelling: LoopPlanSpelling<Spelled>): LoopPlan<Spelled> {
229
300
  return planLoop(loop, { scope: this.scope, localConstants: this.localConstants ?? [], ...spelling })
@@ -279,7 +350,8 @@ export abstract class DslTemplateAdapter extends BaseAdapter {
279
350
  */
280
351
  protected renderLoopRow(loop: IRLoop, spelling: LoopRowSpelling): LoopRow {
281
352
  const outside = this.scope
282
- const row = outside.enterLoopRow(loop)
353
+ const rowType = this.declaredTypes ? loopRowType(this.declaredTypes, loop, outside) : null
354
+ const row = outside.enterLoopRow(rowType ? { ...loop, rowType } : loop)
283
355
  return this.renderInScope(row, () => {
284
356
  spelling.enter?.(row, outside)
285
357
  const preamble = (loop.preamble?.declarations ?? []).map(d => spelling.preamble(d))
@@ -366,11 +438,13 @@ export abstract class DslTemplateAdapter extends BaseAdapter {
366
438
  this.booleanTypedProps = collectBooleanTypedProps(ir)
367
439
  this.localConstants = ir.metadata.localConstants ?? []
368
440
  this.rootPropAliases = rootPropAliasNames(ir, this.propsParams.map(p => p.name))
369
- this.scope = BindingScope.EMPTY
441
+ this.scope = BindingScope.forComponent(this.propsObjectName)
370
442
  this.nullableOptionalProps = collectNullableOptionalProps(ir)
371
443
  this.nullableSignalGetters = collectNullableSignalGetters(ir)
372
444
  this.nullishAttrCtx = collectNullishAttrContext(ir)
373
445
  this.stringValueNames = this.stringValueNamesFor(ir)
446
+ this.declaredTypes = declaredValueTypes(ir)
447
+ this.operandTyping = collectOperandTyping(ir.metadata, { namedFields: this.declaredTypes.namedFields })
374
448
  this.moduleStringConsts = collectModuleStringConsts(ir.metadata.localConstants)
375
449
  this._searchParamsLocals = searchParamsLocalNames(ir.metadata)
376
450
  this._loweringMatchers = prepareLoweringMatchers(ir.metadata)
@@ -397,5 +471,8 @@ export abstract class DslTemplateAdapter extends BaseAdapter {
397
471
  if (!options?.siblingTemplatesRegistered) {
398
472
  this.errors.push(...collectImportedLoopChildComponentErrors(ir, this.componentName, this.loopChildDiagnosticName))
399
473
  }
474
+ refuseAmbiguousNilMemoArithmetic(ir.metadata.memos ?? [], this.nullishAttrCtx, this.ambiguousNilSink())
475
+ // `===` / `!==` over an object or array (#3774, #3824 step 8).
476
+ refuseNonPrimitiveStrictEquality(ir, this.operandTyping, this.ambiguousNilSink())
400
477
  }
401
478
  }
@@ -1,7 +1,15 @@
1
1
  /**
2
2
  * Every name a `.map()`/`.filter()` loop callback binds as its item or
3
3
  * index parameter, anywhere in a component's IR tree (#2212 review
4
- * finding). `isStringTypedOperand`'s identifier arm resolves a bare
4
+ * finding).
5
+ *
6
+ * The string-typing use described below is retired: every template adapter
7
+ * now resolves a name's string typing at the read through the shared
8
+ * `BindingScope` (#3762), and no longer subtracts this set. The remaining
9
+ * callers use it as a whole-component "may be shadowed somewhere" set
10
+ * (root prop aliases, Go's static loop sources, Xslate's memo seeds).
11
+ *
12
+ * Original rationale: `isStringTypedOperand`'s identifier arm resolves a bare
5
13
  * identifier against `collectStringValueNames`'s flat, scope-BLIND
6
14
  * `Set<string>` — so a loop callback whose param happens to reuse a
7
15
  * string prop's name (`items.map((name) => ... 1 + name ...)`, where the