@barefootjs/jsx 0.40.1 → 0.41.0

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 (211) hide show
  1. package/dist/adapters/boolean-result.d.ts +32 -10
  2. package/dist/adapters/boolean-result.d.ts.map +1 -1
  3. package/dist/adapters/brace-delimiter-text.d.ts +18 -0
  4. package/dist/adapters/brace-delimiter-text.d.ts.map +1 -0
  5. package/dist/adapters/callback-method.d.ts +45 -5
  6. package/dist/adapters/callback-method.d.ts.map +1 -1
  7. package/dist/adapters/component-props.d.ts +3 -4
  8. package/dist/adapters/component-props.d.ts.map +1 -1
  9. package/dist/adapters/computed-const.d.ts +11 -1
  10. package/dist/adapters/computed-const.d.ts.map +1 -1
  11. package/dist/adapters/dsl-template-adapter.d.ts +24 -12
  12. package/dist/adapters/dsl-template-adapter.d.ts.map +1 -1
  13. package/dist/adapters/loop-bound-names.d.ts +9 -1
  14. package/dist/adapters/loop-bound-names.d.ts.map +1 -1
  15. package/dist/adapters/loop-row-type.d.ts +59 -0
  16. package/dist/adapters/loop-row-type.d.ts.map +1 -0
  17. package/dist/adapters/nil-reading.d.ts +63 -0
  18. package/dist/adapters/nil-reading.d.ts.map +1 -0
  19. package/dist/adapters/non-primitive-equality.d.ts +33 -0
  20. package/dist/adapters/non-primitive-equality.d.ts.map +1 -0
  21. package/dist/adapters/number-value.d.ts +5 -3
  22. package/dist/adapters/number-value.d.ts.map +1 -1
  23. package/dist/adapters/operand-typing.d.ts +126 -0
  24. package/dist/adapters/operand-typing.d.ts.map +1 -0
  25. package/dist/adapters/parsed-expr-emitter.d.ts +80 -12
  26. package/dist/adapters/parsed-expr-emitter.d.ts.map +1 -1
  27. package/dist/adapters/primitive-plan.d.ts +320 -0
  28. package/dist/adapters/primitive-plan.d.ts.map +1 -0
  29. package/dist/adapters/prop-classes.d.ts +5 -0
  30. package/dist/adapters/prop-classes.d.ts.map +1 -1
  31. package/dist/analyzer-context.d.ts +4 -0
  32. package/dist/analyzer-context.d.ts.map +1 -1
  33. package/dist/analyzer.d.ts.map +1 -1
  34. package/dist/augment-inherited-props.d.ts +63 -8
  35. package/dist/augment-inherited-props.d.ts.map +1 -1
  36. package/dist/compiler.d.ts.map +1 -1
  37. package/dist/event-handler-name.d.ts +12 -0
  38. package/dist/event-handler-name.d.ts.map +1 -1
  39. package/dist/expression-parser.d.ts +8 -0
  40. package/dist/expression-parser.d.ts.map +1 -1
  41. package/dist/index.d.ts +20 -11
  42. package/dist/index.d.ts.map +1 -1
  43. package/dist/index.js +4903 -2311
  44. package/dist/ir-to-client-js/build-references.d.ts.map +1 -1
  45. package/dist/ir-to-client-js/child-props-object.d.ts +106 -0
  46. package/dist/ir-to-client-js/child-props-object.d.ts.map +1 -0
  47. package/dist/ir-to-client-js/collect-elements.d.ts.map +1 -1
  48. package/dist/ir-to-client-js/control-flow/plan/build-inner-loop.d.ts.map +1 -1
  49. package/dist/ir-to-client-js/control-flow/plan/build-loop-child-arm.d.ts.map +1 -1
  50. package/dist/ir-to-client-js/control-flow/shared.d.ts.map +1 -1
  51. package/dist/ir-to-client-js/control-flow/stringify/claim-plan.d.ts +4 -2
  52. package/dist/ir-to-client-js/control-flow/stringify/claim-plan.d.ts.map +1 -1
  53. package/dist/ir-to-client-js/html-template.d.ts.map +1 -1
  54. package/dist/ir-to-client-js/imports.d.ts +2 -2
  55. package/dist/ir-to-client-js/imports.d.ts.map +1 -1
  56. package/dist/ir-to-client-js/index.d.ts +2 -6
  57. package/dist/ir-to-client-js/index.d.ts.map +1 -1
  58. package/dist/ir-to-client-js/phases/props-extraction.d.ts +3 -3
  59. package/dist/ir-to-client-js/plan/build-declaration-emit.d.ts.map +1 -1
  60. package/dist/ir-to-client-js/plan/build-static-array-child-init.d.ts.map +1 -1
  61. package/dist/ir-to-client-js/plan/static-array-child-init.d.ts +30 -18
  62. package/dist/ir-to-client-js/plan/static-array-child-init.d.ts.map +1 -1
  63. package/dist/ir-to-client-js/prop-handling.d.ts.map +1 -1
  64. package/dist/ir-to-client-js/prune-unused-prop-extractions.d.ts +3 -1
  65. package/dist/ir-to-client-js/prune-unused-prop-extractions.d.ts.map +1 -1
  66. package/dist/ir-to-client-js/stringify/static-array-child-init.d.ts +3 -2
  67. package/dist/ir-to-client-js/stringify/static-array-child-init.d.ts.map +1 -1
  68. package/dist/jsx-to-ir.d.ts +1 -0
  69. package/dist/jsx-to-ir.d.ts.map +1 -1
  70. package/dist/nullable-signal-attr.d.ts +51 -34
  71. package/dist/nullable-signal-attr.d.ts.map +1 -1
  72. package/dist/prop-rewrite.d.ts +7 -0
  73. package/dist/prop-rewrite.d.ts.map +1 -1
  74. package/dist/props-binding.d.ts +58 -13
  75. package/dist/props-binding.d.ts.map +1 -1
  76. package/dist/props-object-whole-read.d.ts +15 -0
  77. package/dist/props-object-whole-read.d.ts.map +1 -0
  78. package/dist/rich-type-refusal.d.ts.map +1 -1
  79. package/dist/scope/binding-scope.d.ts +85 -10
  80. package/dist/scope/binding-scope.d.ts.map +1 -1
  81. package/dist/scope/lexical-scope-walk.d.ts +3 -2
  82. package/dist/scope/lexical-scope-walk.d.ts.map +1 -1
  83. package/dist/scope/root-prop-alias.d.ts +10 -7
  84. package/dist/scope/root-prop-alias.d.ts.map +1 -1
  85. package/dist/ssr-defaults.d.ts +39 -3
  86. package/dist/ssr-defaults.d.ts.map +1 -1
  87. package/dist/strip-types.d.ts +13 -0
  88. package/dist/strip-types.d.ts.map +1 -1
  89. package/dist/template-position-walk.d.ts +21 -3
  90. package/dist/template-position-walk.d.ts.map +1 -1
  91. package/dist/types.d.ts +90 -0
  92. package/dist/types.d.ts.map +1 -1
  93. package/package.json +2 -2
  94. package/src/__tests__/__snapshots__/doc-examples.test.ts.snap +9 -9
  95. package/src/__tests__/binding-scope.test.ts +89 -1
  96. package/src/__tests__/body-destructure-props-object-alias.test.ts +123 -0
  97. package/src/__tests__/body-destructured-prop-default-arrow.test.ts +2 -2
  98. package/src/__tests__/body-destructured-props-live.test.ts +5 -5
  99. package/src/__tests__/boolean-result.test.ts +22 -5
  100. package/src/__tests__/brace-delimiter-text.test.ts +26 -0
  101. package/src/__tests__/callback-method.test.ts +62 -2
  102. package/src/__tests__/child-components-in-map.test.ts +1 -1
  103. package/src/__tests__/client-js-generation.test.ts +3 -3
  104. package/src/__tests__/computed-const.test.ts +103 -0
  105. package/src/__tests__/destructure-default-reads-earlier-param.test.ts +7 -7
  106. package/src/__tests__/destructured-props-live.test.ts +1 -1
  107. package/src/__tests__/emit-to-string-call.test.ts +2 -1
  108. package/src/__tests__/hydration-payload-analysis.test.ts +166 -0
  109. package/src/__tests__/issue-2724-prop-alias-loop-not-static.test.ts +7 -7
  110. package/src/__tests__/issue-2754-rest-spread-needs-slot.test.ts +5 -2
  111. package/src/__tests__/issue-2798-static-nested-loop-bindings.test.ts +1 -1
  112. package/src/__tests__/issue-2835-props-type-member-name-collision.test.ts +4 -4
  113. package/src/__tests__/issue-3044-nested-prop-object-array-not-static.test.ts +1 -1
  114. package/src/__tests__/issue-3688-props-spread-child-csr.test.ts +2 -1
  115. package/src/__tests__/issue-3713-props-spread-loop-row.test.ts +65 -0
  116. package/src/__tests__/issue-3861-object-spread-child.test.ts +102 -0
  117. package/src/__tests__/lookup-literal-const.test.ts +9 -3
  118. package/src/__tests__/loop-index-reactivity.test.ts +2 -2
  119. package/src/__tests__/loop-param-accessor-key-member-safety.test.ts +1 -1
  120. package/src/__tests__/loop-plan.test.ts +1 -1
  121. package/src/__tests__/loop-row-const-initializer-shadow.test.ts +146 -0
  122. package/src/__tests__/loop-row-type.test.ts +64 -0
  123. package/src/__tests__/lowering-value-position.test.ts +4 -0
  124. package/src/__tests__/memo-body-expr.test.ts +2 -2
  125. package/src/__tests__/module-const-destructure-default.test.ts +156 -0
  126. package/src/__tests__/nested-loop-index-param.test.ts +1 -1
  127. package/src/__tests__/nested-loop-reactive-attrs.test.ts +2 -2
  128. package/src/__tests__/nested-row-shadowing.test.ts +2 -2
  129. package/src/__tests__/nil-reading.test.ts +78 -0
  130. package/src/__tests__/nullable-signal-attr.test.ts +109 -48
  131. package/src/__tests__/primitive-plan.test.ts +494 -0
  132. package/src/__tests__/profile-loop-binding-ids.test.ts +2 -2
  133. package/src/__tests__/profile-nested-binding-ids.test.ts +2 -2
  134. package/src/__tests__/prop-default-undefined-only.test.ts +115 -0
  135. package/src/__tests__/prop-references.test.ts +2 -2
  136. package/src/__tests__/props-destructuring.test.ts +17 -0
  137. package/src/__tests__/props-object-whole-read.test.ts +40 -0
  138. package/src/__tests__/prune-unused-prop-extractions.test.ts +3 -3
  139. package/src/__tests__/reactive-attrs-in-map.test.ts +1 -1
  140. package/src/__tests__/reactive-factory-inlining.test.ts +4 -1
  141. package/src/__tests__/renamed-body-destructure-template.test.ts +7 -7
  142. package/src/__tests__/rest-binding-gaps.test.ts +192 -0
  143. package/src/__tests__/rewrite-destructured-props.test.ts +1 -1
  144. package/src/__tests__/root-prop-alias.test.ts +53 -8
  145. package/src/__tests__/ssr-defaults.test.ts +113 -25
  146. package/src/__tests__/static-loop-csr-materialize.test.ts +2 -2
  147. package/src/__tests__/static-record-literal-array.test.ts +171 -0
  148. package/src/__tests__/string-concat-identifier.test.ts +40 -1
  149. package/src/__tests__/written-binding-substitution.test.ts +8 -8
  150. package/src/adapters/boolean-result.ts +72 -66
  151. package/src/adapters/brace-delimiter-text.ts +25 -0
  152. package/src/adapters/callback-method.ts +159 -27
  153. package/src/adapters/component-props.ts +3 -4
  154. package/src/adapters/computed-const.ts +238 -4
  155. package/src/adapters/dsl-template-adapter.ts +62 -26
  156. package/src/adapters/loop-bound-names.ts +9 -1
  157. package/src/adapters/loop-plan.ts +1 -1
  158. package/src/adapters/loop-row-type.ts +149 -0
  159. package/src/adapters/nil-reading.ts +295 -0
  160. package/src/adapters/non-primitive-equality.ts +92 -0
  161. package/src/adapters/number-value.ts +17 -4
  162. package/src/adapters/operand-typing.ts +522 -0
  163. package/src/adapters/parsed-expr-emitter.ts +183 -19
  164. package/src/adapters/primitive-plan.ts +765 -0
  165. package/src/adapters/prop-classes.ts +16 -3
  166. package/src/analyzer-context.ts +6 -0
  167. package/src/analyzer.ts +532 -26
  168. package/src/augment-inherited-props.ts +108 -10
  169. package/src/compiler.ts +17 -0
  170. package/src/event-handler-name.ts +15 -0
  171. package/src/expression-parser.ts +70 -1
  172. package/src/index.ts +35 -16
  173. package/src/ir-to-client-js/build-references.ts +69 -0
  174. package/src/ir-to-client-js/child-props-object.ts +240 -0
  175. package/src/ir-to-client-js/collect-elements.ts +31 -63
  176. package/src/ir-to-client-js/control-flow/plan/build-inner-loop.ts +8 -1
  177. package/src/ir-to-client-js/control-flow/plan/build-loop-child-arm.ts +31 -28
  178. package/src/ir-to-client-js/control-flow/shared.ts +20 -22
  179. package/src/ir-to-client-js/control-flow/stringify/claim-plan.ts +5 -3
  180. package/src/ir-to-client-js/control-flow/stringify/inner-loop.ts +2 -2
  181. package/src/ir-to-client-js/control-flow/stringify/lazy-row.ts +1 -1
  182. package/src/ir-to-client-js/control-flow/stringify/loop-child-arm.ts +2 -2
  183. package/src/ir-to-client-js/control-flow/stringify/loop.ts +1 -1
  184. package/src/ir-to-client-js/control-flow/stringify/reactive-effects.ts +3 -3
  185. package/src/ir-to-client-js/html-template.ts +43 -17
  186. package/src/ir-to-client-js/imports.ts +2 -2
  187. package/src/ir-to-client-js/index.ts +53 -11
  188. package/src/ir-to-client-js/phases/props-extraction.ts +11 -7
  189. package/src/ir-to-client-js/plan/build-declaration-emit.ts +40 -7
  190. package/src/ir-to-client-js/plan/build-static-array-child-init.ts +31 -14
  191. package/src/ir-to-client-js/plan/static-array-child-init.ts +27 -18
  192. package/src/ir-to-client-js/prop-handling.ts +22 -3
  193. package/src/ir-to-client-js/prune-unused-prop-extractions.ts +58 -5
  194. package/src/ir-to-client-js/rewrite-destructured-props.ts +31 -1
  195. package/src/ir-to-client-js/stringify/static-array-child-init.ts +26 -10
  196. package/src/jsx-to-ir.ts +459 -37
  197. package/src/nullable-signal-attr.ts +200 -110
  198. package/src/prop-rewrite.ts +30 -6
  199. package/src/props-binding.ts +84 -19
  200. package/src/props-object-whole-read.ts +87 -0
  201. package/src/rich-type-refusal.ts +2 -1
  202. package/src/scope/binding-scope.ts +182 -18
  203. package/src/scope/lexical-scope-walk.ts +4 -3
  204. package/src/scope/root-prop-alias.ts +15 -8
  205. package/src/ssr-defaults.ts +100 -11
  206. package/src/strip-types.ts +31 -3
  207. package/src/template-position-walk.ts +57 -28
  208. package/src/types.ts +87 -0
  209. package/dist/adapters/ambiguous-nil-arithmetic.d.ts +0 -41
  210. package/dist/adapters/ambiguous-nil-arithmetic.d.ts.map +0 -1
  211. package/src/adapters/ambiguous-nil-arithmetic.ts +0 -94
@@ -13,7 +13,7 @@
13
13
  // computations that derive from those signals (`count() * 2`).
14
14
 
15
15
  import { describe, test, expect } from 'bun:test'
16
- import { extractSsrDefaults, deriveStashFromDefaults } from '../ssr-defaults'
16
+ import { extractSsrDefaults, deriveStashFromDefaults, encodeUndefinedMembers, decodeUndefinedMembers } from '../ssr-defaults'
17
17
  import type { SsrDefault } from '../ssr-defaults'
18
18
  import { analyzeComponent } from '../analyzer'
19
19
  import { buildMetadata } from '../compiler'
@@ -80,7 +80,24 @@ describe('extractSsrDefaults', () => {
80
80
  const defaults = extractSsrDefaults(metadata)
81
81
  expect(defaults?.count).toEqual({ value: 0 })
82
82
  expect(defaults?.doubled).toEqual({ value: 0 })
83
- expect(defaults?.initial).toEqual({ propName: 'initial', value: null })
83
+ expect(defaults?.initial).toEqual({ propName: 'initial' })
84
+ })
85
+
86
+ test('a prop with no default has no `value` key; one with a default keeps it, even when null (U1)', () => {
87
+ const metadata = metadataFor(`
88
+ 'use client'
89
+ function Chip({ c, size = 'md', none = null }: { c?: string; size?: string; none?: string | null }) {
90
+ return <p className={size}>{c}{none}</p>
91
+ }
92
+ `)
93
+ // The manifest text is what every runtime reads (`toEqual` would not tell
94
+ // a missing key from an `undefined` one).
95
+ expect(JSON.parse(JSON.stringify(extractSsrDefaults(metadata)))).toEqual({
96
+ c: { propName: 'c' },
97
+ size: { propName: 'size', value: 'md' },
98
+ none: { propName: 'none', value: null },
99
+ })
100
+ expect('value' in (extractSsrDefaults(metadata)?.c ?? {})).toBe(false)
84
101
  })
85
102
 
86
103
  test('seeds every declared bare-props prop, including direct template reads (#2126)', () => {
@@ -99,7 +116,7 @@ describe('extractSsrDefaults', () => {
99
116
  `)
100
117
 
101
118
  const defaults = extractSsrDefaults(metadata)
102
- expect(defaults?.label).toEqual({ propName: 'label', value: null })
119
+ expect(defaults?.label).toEqual({ propName: 'label' })
103
120
  expect(defaults?.n).toEqual({ value: 0 })
104
121
  })
105
122
 
@@ -129,7 +146,7 @@ describe('extractSsrDefaults', () => {
129
146
  `)
130
147
 
131
148
  const defaults = extractSsrDefaults(metadata)
132
- expect(defaults?.label).toEqual({ propName: 'label', value: null })
149
+ expect(defaults?.label).toEqual({ propName: 'label' })
133
150
  })
134
151
 
135
152
  test('self-derived signal collision (#2669, shape B): non-idempotent derivation must not seed the pre-fix double-applied value', () => {
@@ -137,7 +154,7 @@ describe('extractSsrDefaults', () => {
137
154
  // the pre-fix EVALUATED value (2, for no caller prop) makes the
138
155
  // template's own recompute apply the `* 2` a second time (`2 * 2 =
139
156
  // 4`) — wrong even with no caller props at all. Pin that the entry
140
- // is the RAW-prop shape (`value: null`), not `{ value: 2 }`.
157
+ // is the RAW-prop shape (no `value`), not `{ value: 2 }`.
141
158
  const metadata = metadataFor(`
142
159
  'use client'
143
160
  import { createSignal } from '@barefootjs/client'
@@ -148,7 +165,7 @@ describe('extractSsrDefaults', () => {
148
165
  `)
149
166
 
150
167
  const defaults = extractSsrDefaults(metadata)
151
- expect(defaults?.count).toEqual({ propName: 'count', value: null })
168
+ expect(defaults?.count).toEqual({ propName: 'count' })
152
169
  })
153
170
 
154
171
  test('self-derived memo collision (#2669): the same rule applies to a memo whose computation derives from a same-named prop', () => {
@@ -169,7 +186,7 @@ describe('extractSsrDefaults', () => {
169
186
  `)
170
187
 
171
188
  const defaults = extractSsrDefaults(metadata)
172
- expect(defaults?.label).toEqual({ propName: 'label', value: null })
189
+ expect(defaults?.label).toEqual({ propName: 'label' })
173
190
  expect(defaults?.n).toEqual({ value: 0 })
174
191
  })
175
192
 
@@ -190,7 +207,7 @@ describe('extractSsrDefaults', () => {
190
207
  `)
191
208
 
192
209
  const defaults = extractSsrDefaults(metadata)
193
- expect(defaults?.label).toEqual({ propName: 'label', value: null })
210
+ expect(defaults?.label).toEqual({ propName: 'label' })
194
211
  expect(defaults?.[metadata.signals[0].getter]).toEqual({ value: 'sig' })
195
212
  })
196
213
 
@@ -214,7 +231,7 @@ describe('extractSsrDefaults', () => {
214
231
  `)
215
232
 
216
233
  const defaults = extractSsrDefaults(metadata)
217
- expect(defaults?.label).toEqual({ propName: 'label', value: null })
234
+ expect(defaults?.label).toEqual({ propName: 'label' })
218
235
  })
219
236
 
220
237
  test('self-derived memo collision THROUGH a component-scope const (#2685 review)', () => {
@@ -229,7 +246,7 @@ describe('extractSsrDefaults', () => {
229
246
  `)
230
247
 
231
248
  const defaults = extractSsrDefaults(metadata)
232
- expect(defaults?.label).toEqual({ propName: 'label', value: null })
249
+ expect(defaults?.label).toEqual({ propName: 'label' })
233
250
  })
234
251
 
235
252
  test('multi-hop const chain resolves transitively (#2685 review): `const a = props.x; const b = a`', () => {
@@ -252,7 +269,7 @@ describe('extractSsrDefaults', () => {
252
269
 
253
270
  const defaults = extractSsrDefaults(metadata)
254
271
  expect(defaults?.count).toEqual({ value: 1 })
255
- expect(defaults?.x).toEqual({ propName: 'x', value: null })
272
+ expect(defaults?.x).toEqual({ propName: 'x' })
256
273
  })
257
274
 
258
275
  test('safety-net seeding sees a prop through a component-scope const (#2685 review)', () => {
@@ -276,7 +293,7 @@ describe('extractSsrDefaults', () => {
276
293
 
277
294
  const defaults = extractSsrDefaults(metadata)
278
295
  expect(defaults?.count).toEqual({ value: 0 })
279
- expect(defaults?.initial).toEqual({ propName: 'initial', value: null })
296
+ expect(defaults?.initial).toEqual({ propName: 'initial' })
280
297
  })
281
298
 
282
299
  test('NEGATIVE (#2685 review): a const NOT derived from props keeps the signal-wins behavior', () => {
@@ -308,7 +325,7 @@ describe('extractSsrDefaults', () => {
308
325
  // under its own name, and the prop keeps its prop entry.
309
326
  const defaults = extractSsrDefaults(metadata)
310
327
  expect(defaults?.bfSignal_label).toEqual({ value: null })
311
- expect(defaults?.label).toEqual({ propName: 'label', value: null })
328
+ expect(defaults?.label).toEqual({ propName: 'label' })
312
329
  })
313
330
 
314
331
  test('aliased destructured prop (#2460): `propName` is the CALLER-facing key, not the local binding', () => {
@@ -327,9 +344,9 @@ describe('extractSsrDefaults', () => {
327
344
  const defaults = extractSsrDefaults(metadata)
328
345
  expect(defaults).toBeDefined()
329
346
  // Keyed by the LOCAL binding (the template variable name)...
330
- expect(defaults?.count).toEqual({ propName: 'n', value: null })
347
+ expect(defaults?.count).toEqual({ propName: 'n' })
331
348
  // ...but `propName` is the CALLER-facing key.
332
- expect(defaults?.text).toEqual({ propName: 'text', value: null })
349
+ expect(defaults?.text).toEqual({ propName: 'text' })
333
350
  })
334
351
 
335
352
  test('aliased destructured prop with a default (#2460): `propName` still resolves to the source key', () => {
@@ -351,8 +368,8 @@ describe('extractSsrDefaults', () => {
351
368
  `)
352
369
 
353
370
  const defaults = extractSsrDefaults(metadata)
354
- expect(defaults?.n).toEqual({ propName: 'n', value: null })
355
- expect(defaults?.text).toEqual({ propName: 'text', value: null })
371
+ expect(defaults?.n).toEqual({ propName: 'n' })
372
+ expect(defaults?.text).toEqual({ propName: 'text' })
356
373
  })
357
374
 
358
375
  test('bare-props-form BODY-destructured default (#2943) seeds the evaluated default, not null', () => {
@@ -391,7 +408,7 @@ describe('extractSsrDefaults', () => {
391
408
  }
392
409
  `)
393
410
  const defaults = extractSsrDefaults(metadata)
394
- expect(defaults?.label).toEqual({ propName: 'label', value: null })
411
+ expect(defaults?.label).toEqual({ propName: 'label' })
395
412
  expect(defaults?.text).toEqual({ propName: 'label', value: 'none' })
396
413
 
397
414
  expect(deriveStashFromDefaults(defaults!, { label: 'named' })).toMatchObject({ text: 'named' })
@@ -413,7 +430,7 @@ describe('extractSsrDefaults', () => {
413
430
  `)
414
431
 
415
432
  const defaults = extractSsrDefaults(metadata)
416
- expect(defaults?.children).toEqual({ propName: 'children', value: null })
433
+ expect(defaults?.children).toEqual({ propName: 'children' })
417
434
  expect(defaults?.kids).toEqual(defaults?.children)
418
435
  })
419
436
 
@@ -434,7 +451,7 @@ describe('extractSsrDefaults', () => {
434
451
  `)
435
452
 
436
453
  const defaults = extractSsrDefaults(metadata)
437
- expect(defaults?.children).toEqual({ propName: 'children', value: null })
454
+ expect(defaults?.children).toEqual({ propName: 'children' })
438
455
  expect(defaults?.kids).toEqual(defaults?.children)
439
456
  })
440
457
 
@@ -581,9 +598,28 @@ describe('extractSsrDefaults', () => {
581
598
 
582
599
  const defaults = extractSsrDefaults(metadata)
583
600
  // Unlike the array case, a missing key on a plain object resolves that
584
- // ONE element to `undefined` (→ `null`) and the `.map()` keeps going —
585
- // it does not abort the whole computation.
586
- expect(defaults?.x).toEqual({ value: [1, null] })
601
+ // ONE element to `undefined` and the `.map()` keeps going — it does not
602
+ // abort the whole computation. The manifest spells the `undefined`
603
+ // element with the `{"$undef": true}` sentinel.
604
+ expect(defaults?.x).toEqual({ value: [1, { $undef: true }] })
605
+ })
606
+
607
+ test('an `undefined` array element or object member is the `$undef` sentinel, apart from `null`', () => {
608
+ const metadata = metadataFor(`
609
+ 'use client'
610
+ import { createSignal } from '@barefootjs/client'
611
+ function C() {
612
+ const [a] = createSignal([undefined, null, 'x'])
613
+ const [o] = createSignal({ a: null, b: undefined, n: { c: undefined } })
614
+ return <p>{a()}{o()}</p>
615
+ }
616
+ `)
617
+
618
+ const defaults = extractSsrDefaults(metadata)
619
+ expect(defaults?.a).toEqual({ value: [{ $undef: true }, null, 'x'] })
620
+ expect(defaults?.o).toEqual({ value: { a: null, b: { $undef: true }, n: { c: { $undef: true } } } })
621
+ // The manifest is JSON: the sentinel survives it, and a present key stays present.
622
+ expect(JSON.parse(JSON.stringify(defaults?.o))).toEqual({ value: { a: null, b: { $undef: true }, n: { c: { $undef: true } } } })
587
623
  })
588
624
 
589
625
  // #2813 (pullfrog nitpick on the PR fixing it): a bare local-const alias
@@ -641,10 +677,27 @@ describe('extractSsrDefaults', () => {
641
677
  `)
642
678
 
643
679
  const defaults = extractSsrDefaults(metadata)
644
- expect(defaults?.label).toEqual({ propName: 'label', value: null })
680
+ expect(defaults?.label).toEqual({ propName: 'label' })
645
681
  expect(defaults?.labelAlias).toBe(defaults?.label)
646
682
  })
647
683
 
684
+ test('a getter alias sharing its origin entry is encoded once', () => {
685
+ const metadata = metadataFor(`
686
+ 'use client'
687
+ import { createSignal } from '@barefootjs/client'
688
+ function C() {
689
+ const [value] = createSignal<Record<string, unknown>>({ gone: undefined, payload: { $undef: true } })
690
+ const alias = value
691
+ return <p>{JSON.stringify(alias())}</p>
692
+ }
693
+ `)
694
+
695
+ const defaults = extractSsrDefaults(metadata)
696
+ expect(defaults?.alias).toBe(defaults?.value)
697
+ expect(defaults?.value).toEqual({ value: { gone: { $undef: true }, payload: { $$undef: true } } })
698
+ expect(decodeUndefinedMembers(defaults?.alias?.value)).toEqual({ gone: undefined, payload: { $undef: true } })
699
+ })
700
+
648
701
  // #2924 review follow-up (pullfrog nitpick on the PR fixing the setter
649
702
  // case): the setter-symmetric shape of the #2813 getter-alias test above
650
703
  // — a bare local-const alias of a signal SETTER must be seeded under its
@@ -676,7 +729,7 @@ describe('extractSsrDefaults', () => {
676
729
  expect(defaults?.off).toEqual({ propName: 'off', value: false })
677
730
  // A static `!off` would read `true` and win over the in-template
678
731
  // `on ?? !off` whatever `off` the caller passed.
679
- expect(defaults?.on).toEqual({ propName: 'on', value: null })
732
+ expect(defaults?.on).toEqual({ propName: 'on' })
680
733
  })
681
734
  })
682
735
 
@@ -811,6 +864,41 @@ describe('deriveStashFromDefaults', () => {
811
864
  expect(deriveStashFromDefaults(defaults, {})).toEqual({ flag: null })
812
865
  })
813
866
 
867
+ test('an entry without `value` (a prop with no default) seeds null, as `value: null` did (U1)', () => {
868
+ const missing: Record<string, SsrDefault> = { n: { propName: 'n' }, rest: { isRestProps: true } }
869
+ const explicit: Record<string, SsrDefault> = { n: { propName: 'n', value: null }, rest: { isRestProps: true, value: null } }
870
+ for (const props of [{}, { n: null }, { n: 3 }, { rest: { a: 1 } }]) {
871
+ expect(deriveStashFromDefaults(missing, props)).toEqual(deriveStashFromDefaults(explicit, props))
872
+ }
873
+ expect(deriveStashFromDefaults(missing, {})).toEqual({ n: null, rest: null })
874
+ })
875
+
876
+ test('seed data shaped like the sentinel stays data: `$`-prefixed keys get one more `$`', () => {
877
+ const data = { payload: { $undef: true }, $$x: 1, list: [{ $undef: true }, undefined], gone: undefined }
878
+ const encoded = encodeUndefinedMembers(data)
879
+ expect(encoded).toEqual({
880
+ payload: { $$undef: true },
881
+ $$$x: 1,
882
+ list: [{ $$undef: true }, { $undef: true }],
883
+ gone: { $undef: true },
884
+ })
885
+ const decoded = decodeUndefinedMembers(JSON.parse(JSON.stringify(encoded))) as Record<string, unknown>
886
+ expect(decoded).toEqual(data)
887
+ expect('gone' in decoded).toBe(true)
888
+ expect((decoded.list as unknown[])[1]).toBeUndefined()
889
+ expect(decodeUndefinedMembers({ $undef: true })).toBeUndefined()
890
+ expect(decodeUndefinedMembers({ $undef: false })).toEqual({ $undef: false })
891
+ })
892
+
893
+ test('the static fallback decodes the `$undef` sentinel to `undefined`, keeping the key', () => {
894
+ const defaults: Record<string, SsrDefault> = { o: { value: { a: null, b: { $undef: true } } }, a: { value: [{ $undef: true }] } }
895
+ const extra = deriveStashFromDefaults(defaults, {})
896
+ expect(extra.a).toEqual([undefined])
897
+ expect('b' in (extra.o as object)).toBe(true)
898
+ expect((extra.o as { b: unknown }).b).toBeUndefined()
899
+ expect(JSON.stringify(extra.o)).toBe('{"a":null}')
900
+ })
901
+
814
902
  test('mixed defaults map resolves every entry kind independently', () => {
815
903
  const defaults: Record<string, SsrDefault> = {
816
904
  count: { propName: 'n', value: null },
@@ -250,10 +250,10 @@ describe('#1247 — static-loop CSR self-heal', () => {
250
250
  expect(clientJs).not.toMatch(/__bfItem\(\)/)
251
251
  // The `static-array-child-inits` phase still emits its `initChild`
252
252
  // pass — it runs after materialize, finds the cloned children via
253
- // `qsaChildScopes`, and wires them with the same prop getters as
253
+ // `childScopesBySlot`, and wires them with the same prop getters as
254
254
  // before. Pinning this here is a guard against an accidental
255
255
  // double-init by emitting renderChild AND createComponent.
256
- expect(clientJs).toMatch(/qsaChildScopes\(/)
256
+ expect(clientJs).toMatch(/childScopesBySlot\(/)
257
257
  expect(clientJs).toMatch(/initChild\('Tag',/)
258
258
  })
259
259
 
@@ -0,0 +1,171 @@
1
+ import { describe, expect, test } from 'bun:test'
2
+ import { lookupStaticArrayElement, lookupStaticRecordLiteral } from '../augment-inherited-props.ts'
3
+ import { parseExpression } from '../expression-parser.ts'
4
+ import { analyzeComponent } from '../analyzer.ts'
5
+ import { buildMetadata } from '../compiler.ts'
6
+ import type { ConstantInfo } from '../types.ts'
7
+
8
+ const loc = { file: 'c.tsx', start: { line: 1, column: 0 }, end: { line: 1, column: 0 } }
9
+
10
+ function moduleConst(name: string, value: string, extra: Partial<ConstantInfo> = {}): ConstantInfo {
11
+ return {
12
+ name,
13
+ value: value as ConstantInfo['value'],
14
+ parsed: parseExpression(value),
15
+ declarationKind: 'const',
16
+ isModule: true,
17
+ type: null,
18
+ loc,
19
+ ...extra,
20
+ }
21
+ }
22
+
23
+ const notShadowed = () => false
24
+ const num = (value: number) => ({ kind: 'literal', value, literalType: 'number', raw: String(value) })
25
+ const str = (value: string) => ({ kind: 'literal', value, literalType: 'string' })
26
+
27
+ describe('lookupStaticArrayElement', () => {
28
+ const QS = moduleConst('QS', `['a1', "b\\"c", \`m1\nm2\`, 1e3, 0x10, .5, -0, -1.5]`)
29
+ const read = (key: string) => lookupStaticArrayElement('QS', key, [QS], notShadowed)
30
+
31
+ test('a canonical index reads the element as a typed node', () => {
32
+ expect(read('0')).toEqual(str('a1'))
33
+ expect(read('1')).toEqual(str('b"c'))
34
+ expect(read('2')).toEqual(str('m1\nm2'))
35
+ expect(read('3')).toEqual(num(1000))
36
+ expect(read('4')).toEqual(num(16))
37
+ expect(read('5')).toEqual(num(0.5))
38
+ })
39
+
40
+ test('a negated element stays a unary minus, so -0 keeps its sign', () => {
41
+ expect(read('6')).toEqual({ kind: 'unary', op: '-', argument: num(0) })
42
+ expect(read('7')).toEqual({ kind: 'unary', op: '-', argument: num(1.5) })
43
+ })
44
+
45
+ test('length is the element count', () => {
46
+ expect(read('length')).toEqual(num(8))
47
+ })
48
+
49
+ test('a key that names no element falls back to the generic lowering', () => {
50
+ expect(read('01')).toBeNull()
51
+ expect(read('8')).toBeNull()
52
+ expect(read('-1')).toBeNull()
53
+ expect(read('x')).toBeNull()
54
+ })
55
+
56
+ test('a hole, a spread or a non-literal element is not resolved', () => {
57
+ const holes = moduleConst('H', `['a', , 'c']`)
58
+ expect(lookupStaticArrayElement('H', '0', [holes], notShadowed)).toEqual(str('a'))
59
+ expect(lookupStaticArrayElement('H', '2', [holes], notShadowed)).toBeNull()
60
+ expect(lookupStaticArrayElement('H', 'length', [holes], notShadowed)).toBeNull()
61
+ const spread = moduleConst('S', `[...xs, 'b']`)
62
+ expect(lookupStaticArrayElement('S', '1', [spread], notShadowed)).toBeNull()
63
+ const ref = moduleConst('R', `[other, 'b']`)
64
+ expect(lookupStaticArrayElement('R', '0', [ref], notShadowed)).toBeNull()
65
+ expect(lookupStaticArrayElement('R', '1', [ref], notShadowed)).toEqual(str('b'))
66
+ })
67
+
68
+ test('a loop binding, a component binding or a later mutation keeps the read live', () => {
69
+ expect(lookupStaticArrayElement('QS', '0', [QS], name => name === 'QS')).toBeNull()
70
+ const shadowed = moduleConst('QS', `['a1']`, { shadowedInComponent: true })
71
+ expect(lookupStaticArrayElement('QS', '0', [shadowed], notShadowed)).toBeNull()
72
+ const mutated = moduleConst('QS', `['a1']`, { mutatedAfterDeclaration: true })
73
+ expect(lookupStaticArrayElement('QS', 'length', [mutated], notShadowed)).toBeNull()
74
+ })
75
+
76
+ test('a record const is not an array, and the record lookup no longer reads arrays', () => {
77
+ const rec = moduleConst('REC', `{ lf: 'r1' }`)
78
+ expect(lookupStaticArrayElement('REC', 'lf', [rec], notShadowed)).toBeNull()
79
+ expect(lookupStaticRecordLiteral('QS', '0', [QS], notShadowed)).toBeNull()
80
+ })
81
+ })
82
+
83
+ describe('resolveStaticConstBinding: a component-local literal const', () => {
84
+ const constantsOf = (source: string) => buildMetadata(analyzeComponent(source, 'c.tsx')).localConstants
85
+ const element = (source: string, key = '0') => lookupStaticArrayElement('QS', key, constantsOf(source), notShadowed)
86
+ const member = (source: string, key = 'k') => lookupStaticRecordLiteral('REC', key, constantsOf(source), notShadowed)
87
+
88
+ test('a component-local array or record const resolves like a module const', () => {
89
+ const source = `export function C() {
90
+ const QS = ['a', 'b']
91
+ const REC = { k: 'v', n: 3 }
92
+ return <p>{QS[0]}{REC.k}</p>
93
+ }`
94
+ expect(element(source, '1')).toEqual(str('b'))
95
+ expect(element(source, 'length')).toEqual(num(2))
96
+ expect(member(source)).toEqual({ kind: 'string', text: 'v' })
97
+ expect(member(source, 'n')).toEqual({ kind: 'number', text: '3' })
98
+ })
99
+
100
+ test('a component-local const shadows the module const of the same name', () => {
101
+ const source = `const QS = ['module']
102
+ const REC = { k: 'module' }
103
+ export function C() {
104
+ const QS = ['local']
105
+ const REC = { k: 'local' }
106
+ return <p>{QS[0]}{REC.k}</p>
107
+ }`
108
+ expect(element(source)).toEqual(str('local'))
109
+ expect(member(source)).toEqual({ kind: 'string', text: 'local' })
110
+ })
111
+
112
+ test('a loop binding of the name keeps the read live', () => {
113
+ const constants = constantsOf(`export function C() {
114
+ const QS = ['a']
115
+ return <p>{QS[0]}</p>
116
+ }`)
117
+ expect(lookupStaticArrayElement('QS', '0', constants, name => name === 'QS')).toBeNull()
118
+ })
119
+
120
+ test('a const the component changes during render is not resolved, local or module', () => {
121
+ expect(element(`export function C() {
122
+ const QS = ['a']
123
+ QS.push('b')
124
+ return <p>{QS[1]}</p>
125
+ }`, '1')).toBeNull()
126
+ expect(member(`export function C() {
127
+ const REC = { k: 'v' }
128
+ REC.k = 'w'
129
+ return <p>{REC.k}</p>
130
+ }`)).toBeNull()
131
+ expect(member(`const REC = { k: 'v' }
132
+ export function C() {
133
+ REC.k = 'w'
134
+ return <p>{REC.k}</p>
135
+ }`)).toBeNull()
136
+ })
137
+
138
+ test('a let is not resolved', () => {
139
+ expect(element(`export function C() {
140
+ let QS = ['a']
141
+ return <p>{QS[0]}</p>
142
+ }`)).toBeNull()
143
+ })
144
+
145
+ test("an early-return branch's own const does not leak into the main return", () => {
146
+ const source = `export function C({ on }: { on: boolean }) {
147
+ if (on) {
148
+ const QS = ['inner']
149
+ return <p>{QS[0]}</p>
150
+ }
151
+ const QS = ['outer']
152
+ return <p>{QS[0]}</p>
153
+ }`
154
+ expect(element(source)).toEqual(str('outer'))
155
+ })
156
+
157
+ test('each component of a file reads its own declaration', () => {
158
+ const source = `export function A() {
159
+ const QS = ['a']
160
+ return <p>{QS[0]}</p>
161
+ }
162
+ export function B() {
163
+ const QS = ['b']
164
+ return <p>{QS[0]}</p>
165
+ }`
166
+ const read = (name: string) =>
167
+ lookupStaticArrayElement('QS', '0', buildMetadata(analyzeComponent(source, 'c.tsx', name)).localConstants, notShadowed)
168
+ expect(read('A')).toEqual(str('a'))
169
+ expect(read('B')).toEqual(str('b'))
170
+ })
171
+ })
@@ -1,5 +1,6 @@
1
1
  import { describe, test, expect } from 'bun:test'
2
- import { isStringTypedOperand, isStringConcatBinary } from '../adapters/parsed-expr-emitter'
2
+ import { isStringTypedOperand, isStringConcatBinary, type StringNameTest } from '../adapters/parsed-expr-emitter'
3
+ import { BindingScope } from '../scope/binding-scope'
3
4
  import { parseExpression } from '../expression-parser'
4
5
 
5
6
  // #2212: `isStringTypedOperand` gained a bare-`identifier` arm — previously
@@ -53,3 +54,41 @@ describe('isStringTypedOperand identifier arm (#2212)', () => {
53
54
  expect(isStringConcatBinary(parsed.op, parsed.left, parsed.right, isStr)).toBe(false)
54
55
  })
55
56
  })
57
+
58
+ // #3762: a field read (`row.id`) is string-typed when the binding's declared
59
+ // row type says the field is; a member of a string-typed name is not.
60
+ describe('isStringTypedOperand member arm (#3762)', () => {
61
+ const rowType = {
62
+ raw: 'Row',
63
+ properties: [
64
+ { name: 'id', type: { primitive: 'string' } },
65
+ { name: 'n', type: { primitive: 'number' } },
66
+ { name: 'meta', type: { properties: [{ name: 'label', type: { primitive: 'string' } }] } },
67
+ ],
68
+ }
69
+ const scope = BindingScope.EMPTY.enterLoopRow({ param: 'r', index: 'i', rowType })
70
+ const isStr: StringNameTest = (n, property, path) =>
71
+ scope.isStringValueName(n, name => name === 'label', property, path)
72
+ const concat = (source: string) => {
73
+ const parsed = parseExpression(source)
74
+ if (parsed.kind !== 'binary') throw new Error('expected binary')
75
+ return isStringConcatBinary(parsed.op, parsed.left, parsed.right, isStr)
76
+ }
77
+
78
+ test('a string row field, alone or nested, makes + a concatenation', () => {
79
+ expect(concat('r.id + i')).toBe(true)
80
+ expect(concat('r.n + r.id')).toBe(true)
81
+ expect(concat('r.meta.label + r.n')).toBe(true)
82
+ })
83
+
84
+ test('a numeric field, an unknown field and a member of a string name stay numeric', () => {
85
+ expect(concat('r.n + i')).toBe(false)
86
+ expect(concat('r.missing + 1')).toBe(false)
87
+ expect(concat('label.length + 1')).toBe(false)
88
+ })
89
+
90
+ test('a test that ignores the path never types a member as a string', () => {
91
+ const nameOnly: StringNameTest = n => n === 'label'
92
+ expect(isStringTypedOperand(parseExpression('label.length'), nameOnly)).toBe(false)
93
+ })
94
+ })
@@ -91,7 +91,7 @@ describe('a destructured prop the component writes is an init local', () => {
91
91
  return <div><button onClick={() => setItems([...items(), ++start])}>add</button><p>{items().join(',')}</p></div>`,
92
92
  P,
93
93
  )
94
- expect(js).toContain('let start = _p.start ?? 0')
94
+ expect(js).toContain('let start = _p.start === undefined ? 0 : _p.start')
95
95
  expect(js).toContain('++start')
96
96
  expect(js).not.toContain('++(_p.start')
97
97
  })
@@ -105,12 +105,12 @@ describe('a destructured prop the component writes is an init local', () => {
105
105
  )
106
106
  expect(js).toContain('const add = () => { start += 1; setItems([...items(), start]) }')
107
107
  // Until a handler runs, the binding holds the prop: the template reads it.
108
- expect(templateOf(js)).toContain('(_p.start ?? 0)')
108
+ expect(templateOf(js)).toContain('(_p.start === undefined ? 0 : _p.start)')
109
109
  })
110
110
 
111
111
  test('a top-level reassignment', () => {
112
112
  const js = clientJs(`start = start + 1\n return <p>{start}</p>`, P)
113
- expect(js).toContain('let start = _p.start ?? 0')
113
+ expect(js).toContain('let start = _p.start === undefined ? 0 : _p.start')
114
114
  expect(js).toContain('start = start + 1')
115
115
  })
116
116
 
@@ -122,7 +122,7 @@ describe('a destructured prop the component writes is an init local', () => {
122
122
  )
123
123
  expect(js).toContain('[a, b] = [b, a]')
124
124
  expect(js).toContain('for (k in')
125
- expect(js).toContain('let a = _p.a ?? 1')
125
+ expect(js).toContain('let a = _p.a === undefined ? 1 : _p.a')
126
126
  })
127
127
 
128
128
  test('a prop without a default no longer writes the props object', () => {
@@ -141,7 +141,7 @@ describe('a destructured prop the component writes is an init local', () => {
141
141
  return <div><button onClick={() => setItems([...items(), ++s])}>add</button><p>{items().join(',')}</p></div>`,
142
142
  '{ start: s = 0 }: { start?: number }',
143
143
  )
144
- expect(js).toContain('let s = _p.start ?? 0')
144
+ expect(js).toContain('let s = _p.start === undefined ? 0 : _p.start')
145
145
  expect(js).toContain('++s')
146
146
  })
147
147
 
@@ -166,7 +166,7 @@ describe('a `for (let …)` head shadows a prop of the same name', () => {
166
166
  return <div><button onClick={add}>go</button><p>{n()}</p></div>`,
167
167
  '{ i = 5 }: { i?: number }',
168
168
  )
169
- expect(js).toContain('for (let i = 0; i < 3; i++) t += i; setN(t + (_p.i ?? 5))')
169
+ expect(js).toContain('for (let i = 0; i < 3; i++) t += i; setN(t + (_p.i === undefined ? 5 : _p.i))')
170
170
  })
171
171
  })
172
172
 
@@ -207,7 +207,7 @@ describe('a written local in the client template', () => {
207
207
  describe('every template path leaves a write to init', () => {
208
208
  test('a stateless component writing a prop in a handler renders the prop from its template', () => {
209
209
  const js = clientJs(`return <button onClick={() => start++}>{start}</button>`, '{ start = 0 }: { start?: number }')
210
- expect(js).toContain('let start = _p.start ?? 0')
210
+ expect(js).toContain('let start = _p.start === undefined ? 0 : _p.start')
211
211
  expect(runTemplate(js, { start: 5 })).toContain('5')
212
212
  expect(runTemplate(js, {})).toContain('0')
213
213
  })
@@ -361,7 +361,7 @@ describe('BF065: a client component markup that writes a binding while it render
361
361
  CHILD,
362
362
  )
363
363
  expect(templateOf(js)).toContain('data-bf-ph')
364
- expect(js).toContain('let start = _p.start ?? 0')
364
+ expect(js).toContain('let start = _p.start === undefined ? 0 : _p.start')
365
365
  expect(js).toContain('return () => ++start')
366
366
  })
367
367