@barefootjs/jsx 0.40.2 → 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 (88) hide show
  1. package/dist/adapters/callback-method.d.ts +8 -1
  2. package/dist/adapters/callback-method.d.ts.map +1 -1
  3. package/dist/adapters/component-props.d.ts +3 -4
  4. package/dist/adapters/component-props.d.ts.map +1 -1
  5. package/dist/adapters/dsl-template-adapter.d.ts +3 -12
  6. package/dist/adapters/dsl-template-adapter.d.ts.map +1 -1
  7. package/dist/adapters/loop-row-type.d.ts +7 -0
  8. package/dist/adapters/loop-row-type.d.ts.map +1 -1
  9. package/dist/adapters/nil-reading.d.ts +15 -20
  10. package/dist/adapters/nil-reading.d.ts.map +1 -1
  11. package/dist/adapters/non-primitive-equality.d.ts +1 -1
  12. package/dist/adapters/parsed-expr-emitter.d.ts +11 -1
  13. package/dist/adapters/parsed-expr-emitter.d.ts.map +1 -1
  14. package/dist/adapters/primitive-plan.d.ts +40 -11
  15. package/dist/adapters/primitive-plan.d.ts.map +1 -1
  16. package/dist/adapters/prop-classes.d.ts +5 -0
  17. package/dist/adapters/prop-classes.d.ts.map +1 -1
  18. package/dist/analyzer.d.ts.map +1 -1
  19. package/dist/index.d.ts +5 -6
  20. package/dist/index.d.ts.map +1 -1
  21. package/dist/index.js +390 -228
  22. package/dist/ir-to-client-js/child-props-object.d.ts +43 -1
  23. package/dist/ir-to-client-js/child-props-object.d.ts.map +1 -1
  24. package/dist/ir-to-client-js/collect-elements.d.ts.map +1 -1
  25. package/dist/ir-to-client-js/control-flow/plan/build-inner-loop.d.ts.map +1 -1
  26. package/dist/ir-to-client-js/control-flow/plan/build-loop-child-arm.d.ts.map +1 -1
  27. package/dist/ir-to-client-js/html-template.d.ts.map +1 -1
  28. package/dist/ir-to-client-js/imports.d.ts +2 -2
  29. package/dist/ir-to-client-js/imports.d.ts.map +1 -1
  30. package/dist/ir-to-client-js/phases/props-extraction.d.ts +3 -3
  31. package/dist/ir-to-client-js/plan/build-declaration-emit.d.ts.map +1 -1
  32. package/dist/ir-to-client-js/prune-unused-prop-extractions.d.ts +3 -1
  33. package/dist/ir-to-client-js/prune-unused-prop-extractions.d.ts.map +1 -1
  34. package/dist/jsx-to-ir.d.ts.map +1 -1
  35. package/dist/nullable-signal-attr.d.ts +4 -46
  36. package/dist/nullable-signal-attr.d.ts.map +1 -1
  37. package/dist/props-binding.d.ts +58 -13
  38. package/dist/props-binding.d.ts.map +1 -1
  39. package/dist/ssr-defaults.d.ts +39 -3
  40. package/dist/ssr-defaults.d.ts.map +1 -1
  41. package/package.json +2 -2
  42. package/src/__tests__/__snapshots__/doc-examples.test.ts.snap +6 -6
  43. package/src/__tests__/body-destructured-prop-default-arrow.test.ts +2 -2
  44. package/src/__tests__/body-destructured-props-live.test.ts +5 -5
  45. package/src/__tests__/client-js-generation.test.ts +3 -3
  46. package/src/__tests__/destructure-default-reads-earlier-param.test.ts +7 -7
  47. package/src/__tests__/destructured-props-live.test.ts +1 -1
  48. package/src/__tests__/issue-3861-object-spread-child.test.ts +102 -0
  49. package/src/__tests__/memo-body-expr.test.ts +2 -2
  50. package/src/__tests__/nil-reading.test.ts +3 -2
  51. package/src/__tests__/nullable-signal-attr.test.ts +30 -103
  52. package/src/__tests__/primitive-plan.test.ts +90 -12
  53. package/src/__tests__/prop-default-undefined-only.test.ts +115 -0
  54. package/src/__tests__/prop-references.test.ts +2 -2
  55. package/src/__tests__/props-destructuring.test.ts +17 -0
  56. package/src/__tests__/prune-unused-prop-extractions.test.ts +3 -3
  57. package/src/__tests__/renamed-body-destructure-template.test.ts +7 -7
  58. package/src/__tests__/rewrite-destructured-props.test.ts +1 -1
  59. package/src/__tests__/ssr-defaults.test.ts +113 -25
  60. package/src/__tests__/written-binding-substitution.test.ts +8 -8
  61. package/src/adapters/callback-method.ts +13 -5
  62. package/src/adapters/component-props.ts +3 -4
  63. package/src/adapters/dsl-template-adapter.ts +26 -28
  64. package/src/adapters/loop-row-type.ts +10 -0
  65. package/src/adapters/nil-reading.ts +23 -25
  66. package/src/adapters/non-primitive-equality.ts +1 -1
  67. package/src/adapters/parsed-expr-emitter.ts +31 -2
  68. package/src/adapters/primitive-plan.ts +84 -15
  69. package/src/adapters/prop-classes.ts +16 -3
  70. package/src/analyzer.ts +27 -7
  71. package/src/index.ts +4 -11
  72. package/src/ir-to-client-js/child-props-object.ts +140 -6
  73. package/src/ir-to-client-js/collect-elements.ts +7 -14
  74. package/src/ir-to-client-js/control-flow/plan/build-inner-loop.ts +4 -2
  75. package/src/ir-to-client-js/control-flow/plan/build-loop-child-arm.ts +4 -2
  76. package/src/ir-to-client-js/html-template.ts +18 -9
  77. package/src/ir-to-client-js/imports.ts +1 -1
  78. package/src/ir-to-client-js/phases/props-extraction.ts +11 -7
  79. package/src/ir-to-client-js/plan/build-declaration-emit.ts +40 -7
  80. package/src/ir-to-client-js/prune-unused-prop-extractions.ts +58 -5
  81. package/src/ir-to-client-js/rewrite-destructured-props.ts +31 -1
  82. package/src/jsx-to-ir.ts +15 -2
  83. package/src/nullable-signal-attr.ts +11 -138
  84. package/src/props-binding.ts +84 -19
  85. package/src/ssr-defaults.ts +100 -11
  86. package/dist/adapters/ambiguous-nil-arithmetic.d.ts +0 -42
  87. package/dist/adapters/ambiguous-nil-arithmetic.d.ts.map +0 -1
  88. package/src/adapters/ambiguous-nil-arithmetic.ts +0 -103
@@ -0,0 +1,115 @@
1
+ /**
2
+ * A destructure default applies to an absent or `undefined` prop only; an
3
+ * explicit `null` keeps `null` (`spec/js-undefined-value.md`, "Decisions"
4
+ * (6)). Every client-JS read of a defaulted prop is
5
+ * `_p.x === undefined ? d : _p.x`: the live reads in effects, the CSR
6
+ * template, a signal seed, a controlled signal's seed, a written prop's
7
+ * local, the `children` extraction and a body destructure of the props
8
+ * object. A compiler-supplied guard of a defaultless prop (`?? []` for a
9
+ * loop array) keeps replacing either nil.
10
+ */
11
+
12
+ import { describe, test, expect } from 'bun:test'
13
+ import { compileJSX } from '../compiler'
14
+ import { TestAdapter } from '../adapters/test-adapter'
15
+
16
+ function clientJs(source: string): string {
17
+ const result = compileJSX(source, 'Demo.tsx', { adapter: new TestAdapter() })
18
+ expect(result.errors.filter(e => e.severity === 'error')).toEqual([])
19
+ return result.files.find(f => f.type === 'clientJs')!.content
20
+ }
21
+
22
+ describe('a destructure default in client JS applies to undefined only', () => {
23
+ test('text, attribute, CSR template and signal seeds', () => {
24
+ const js = clientJs(`
25
+ 'use client'
26
+ import { createSignal } from '@barefootjs/client'
27
+ export function Demo({ label = 'D', start = 0 }: { label?: string | null; start?: number | null }) {
28
+ const [copy] = createSignal(label)
29
+ return <p title={label} data-s={start}>{label}{copy()}</p>
30
+ }
31
+ `)
32
+ expect(js).toContain("(_p.label === undefined ? 'D' : _p.label)")
33
+ expect(js).toContain("createSignal(_p.label === undefined ? 'D' : _p.label)")
34
+ expect(js).toContain('(_p.start === undefined ? 0 : _p.start)')
35
+ expect(js).not.toContain('_p.label ??')
36
+ expect(js).not.toContain('_p.start ??')
37
+ })
38
+
39
+ test('a body destructure of the props object and a written prop', () => {
40
+ const js = clientJs(`
41
+ 'use client'
42
+ export function Demo(props: { label?: string | null; n?: number | null }) {
43
+ const { label = 'D' } = props
44
+ return <p>{label}</p>
45
+ }
46
+ export function Counter({ n = 1 }: { n?: number | null }) {
47
+ n = n + 1
48
+ return <p>{n}</p>
49
+ }
50
+ `)
51
+ expect(js).toContain("(_p.label === undefined ? 'D' : _p.label)")
52
+ expect(js).toContain('let n = _p.n === undefined ? 1 : _p.n')
53
+ expect(js).not.toContain('_p.label ??')
54
+ expect(js).not.toContain('_p.n ??')
55
+ })
56
+
57
+ test('a default reading an earlier binding kept as a local reads that local', () => {
58
+ const js = clientJs(`
59
+ 'use client'
60
+ export function Demo(props: { a?: string[]; b?: string[] }) {
61
+ let { a = [], b = a } = props
62
+ a.push('x')
63
+ return <p>{b.length}</p>
64
+ }
65
+ export function Assigned(props: { a?: number; b?: number; c?: number }) {
66
+ let { a = 1, b = (a = 2), c = a } = props
67
+ return <p>{c}</p>
68
+ }
69
+ export function Kept(props: { a?: string[]; b?: string[] }) {
70
+ const { a = [], b = a } = props
71
+ a.push('x')
72
+ return <p>{b.length}</p>
73
+ }
74
+ `)
75
+ expect(js).toContain('let b = _p.b === undefined ? a : _p.b')
76
+ // An unread binding whose default assigns stays, so the assignment runs.
77
+ expect(js).toContain('let b = _p.b === undefined ? (a = 2) : _p.b')
78
+ expect(js).toContain('let c = _p.c === undefined ? a : _p.c')
79
+ expect(js).toContain('const b = _p.b === undefined ? a : _p.b')
80
+ expect(js).not.toContain('let b = _p.b === undefined ? (_p.a')
81
+ expect(js).not.toContain('const b = _p.b === undefined ? (_p.a')
82
+ })
83
+
84
+ test('an arrow default keeps its own parens', () => {
85
+ const js = clientJs(`
86
+ 'use client'
87
+ export function Demo({ fmt = (v: string) => v + '!' }: { fmt?: (v: string) => string }) {
88
+ return <p>{fmt('x')}</p>
89
+ }
90
+ `)
91
+ expect(js).toContain("(_p.fmt === undefined ? ((v) => v + '!') : _p.fmt)('x')")
92
+ })
93
+
94
+ test("an author's `??` over a prop keeps replacing null", () => {
95
+ const js = clientJs(`
96
+ 'use client'
97
+ export function Demo(props: { label?: string | null }) {
98
+ const label = props.label ?? 'x'
99
+ return <p>{label.toUpperCase()}</p>
100
+ }
101
+ `)
102
+ expect(js).toContain("(_p.label ?? 'x')")
103
+ expect(js).not.toContain('_p.label === undefined')
104
+ })
105
+
106
+ test('a defaultless loop array keeps its nil guard', () => {
107
+ const js = clientJs(`
108
+ 'use client'
109
+ export function Demo({ items }: { items?: string[] | null }) {
110
+ return <ul>{items.map(i => <li key={i}>{i}</li>)}</ul>
111
+ }
112
+ `)
113
+ expect(js).toContain('(_p.items ?? [])')
114
+ })
115
+ })
@@ -307,9 +307,9 @@ describe('ClientJS generation with semantic prop refs', () => {
307
307
  const clientJs = result.files.find((f) => f.type === 'clientJs')
308
308
  expect(clientJs).toBeDefined()
309
309
  // No captured-once local — the live read carries the default at the
310
- // read site itself: `(_p.open ?? false)`.
310
+ // read site itself: `(_p.open === undefined ? false : _p.open)`.
311
311
  expect(clientJs?.content).not.toContain('const open = ')
312
- expect(clientJs?.content).toMatch(/\(_p\.open \?\? false\)/)
312
+ expect(clientJs?.content).toMatch(/\(_p\.open === undefined \? false : _p\.open\)/)
313
313
  })
314
314
  })
315
315
 
@@ -210,6 +210,23 @@ describe('Destructured props keep their declared types (#2150)', () => {
210
210
  expect(typeOf(ctx, 'configs')).toEqual({ kind: 'unknown', raw: 'unknown' })
211
211
  })
212
212
 
213
+ test('resolves a structural member whose leaf is a nil union of a resolvable type; a top-level union still declines', () => {
214
+ const source = `
215
+ type Init = { label?: string | null; n: number | undefined }
216
+ type Props = { initial: Init; rows: { tag: string | null }[]; top: string | null }
217
+
218
+ export function Component({ initial, rows, top }: Props) {
219
+ return <div>{initial.label}{rows.length}{top}</div>
220
+ }
221
+ `
222
+
223
+ const ctx = analyzeComponent(source, 'Component.tsx')
224
+
225
+ expect(typeOf(ctx, 'initial')?.kind).toBe('interface')
226
+ expect(typeOf(ctx, 'rows')?.kind).toBe('array')
227
+ expect(typeOf(ctx, 'top')).toEqual({ kind: 'unknown', raw: 'unknown' })
228
+ })
229
+
213
230
  // A same-file object type referenced BY NAME resolves like its inline
214
231
  // spelling — the `props`-object form (`props: { initial: State }`) always
215
232
  // kept it; the destructured form declined it to `unknown`.
@@ -77,8 +77,8 @@ export { Widget }
77
77
  )
78
78
  expect(js).not.toContain('const config = ')
79
79
  expect(js).not.toContain('const items = ')
80
- expect(js).toContain('(_p.config ?? {}).startOpen')
81
- expect(js).toContain('(_p.items ?? []).length')
82
- expect(js).toContain('(_p.items ?? [])[0]')
80
+ expect(js).toContain('(_p.config === undefined ? {} : _p.config).startOpen')
81
+ expect(js).toContain('(_p.items === undefined ? [] : _p.items).length')
82
+ expect(js).toContain('(_p.items === undefined ? [] : _p.items)[0]')
83
83
  })
84
84
  })
@@ -4,7 +4,7 @@
4
4
  * like the parameter form (#3579). A binding that no longer holds the prop
5
5
  * (a `let` reassigned before the return, a folded reassignment, a value
6
6
  * mutated in place) stays a local: the template leaves its slot empty and
7
- * defers a child that receives it, instead of reading `_p.b ?? d`.
7
+ * defers a child that receives it, instead of reading `_p.b` with its default.
8
8
  *
9
9
  * The reassigned shapes have no conformance fixture: the reference adapter
10
10
  * itself drops the reassignment of a destructured binding, so these pin the
@@ -42,7 +42,7 @@ function templateOf(body: string, jsx: string, propsType = '{ b?: string[] | nul
42
42
  describe('renamed body destructure binding in the client template (#3579)', () => {
43
43
  test('a default holding a callback reads the prop with its default', () => {
44
44
  const t = templateOf("const { b: local = ['y', ''].filter((x) => x !== '') } = props", '<p>{local.length}</p>')
45
- expect(t).toContain("_p.b ?? (['y', ''].filter((x) => x !== ''))")
45
+ expect(t).toContain("_p.b === undefined ? (['y', ''].filter((x) => x !== '')) : _p.b")
46
46
  expect(t).not.toContain("${''}")
47
47
  })
48
48
 
@@ -55,23 +55,23 @@ describe('renamed body destructure binding in the client template (#3579)', () =
55
55
  test('a let reassigned before the return keeps the child deferred', () => {
56
56
  const t = templateOf("let { b: local = null } = props\n local = ['changed']", '<p><Child xs={local} /></p>')
57
57
  expect(t).toContain('data-bf-ph')
58
- expect(t).not.toContain('_p.b ?? null')
58
+ expect(t).not.toContain('_p.b === undefined ? ')
59
59
  })
60
60
 
61
61
  test('a let reassigned before the return is not read as the prop in text or an attribute', () => {
62
62
  const t = templateOf("let { b: local = 'x' } = props\n local = local + '!'", '<p data-v={local}>{local}</p>', '{ b?: string }')
63
- expect(t).not.toContain("_p.b ?? 'x'")
63
+ expect(t).not.toContain('_p.b === undefined ? ')
64
64
  })
65
65
 
66
66
  test('a folded conditional reassignment is not read as the prop', () => {
67
67
  const t = templateOf("let { b: local = 'x' } = props\n if (!local) local = 'y'", '<p>{local}</p>', '{ b?: string }')
68
- expect(t).not.toContain("_p.b ?? 'x'")
68
+ expect(t).not.toContain('_p.b === undefined ? ')
69
69
  })
70
70
 
71
71
  test('an un-renamed let reassigned before the return keeps the child deferred too', () => {
72
72
  const t = templateOf("let { b = null } = props\n b = ['changed']", '<p><Child xs={b} /></p>')
73
73
  expect(t).toContain('data-bf-ph')
74
- expect(t).not.toContain('_p.b ?? null')
74
+ expect(t).not.toContain('_p.b === undefined ? ')
75
75
  })
76
76
 
77
77
  test('an un-renamed binding with a callback default renders the child in place', () => {
@@ -81,6 +81,6 @@ describe('renamed body destructure binding in the client template (#3579)', () =
81
81
 
82
82
  test('a value mutated in place is not read as the prop', () => {
83
83
  const t = templateOf("const { b: local = ['x'] } = props\n local.push('y')", '<p>{local.length}</p>', '{ b?: string[] }')
84
- expect(t).not.toContain("_p.b ?? ['x']")
84
+ expect(t).not.toContain('_p.b === undefined ? ')
85
85
  })
86
86
  })
@@ -107,7 +107,7 @@ function Comp({ base, tag = 'all', page }: { base: string; tag?: string; page: s
107
107
  export { Comp }
108
108
  `
109
109
  const js = compileClientJs(source)
110
- expect(js).toContain("{ tag: (_p.tag ?? 'all'), page: _p.page ? _p.page : '' }")
110
+ expect(js).toContain("{ tag: (_p.tag === undefined ? 'all' : _p.tag), page: _p.page ? _p.page : '' }")
111
111
  expect(js).not.toContain("(_p.tag ?? 'all'):")
112
112
  })
113
113
 
@@ -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 },
@@ -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
 
@@ -104,6 +104,14 @@ export interface EvalBody {
104
104
  captured: CallbackCapture[]
105
105
  }
106
106
 
107
+ /**
108
+ * Where an evaluator body is read, for its nil-reading rewrite
109
+ * (`rewriteNilReadingsDeep`): the enclosing scope's operand typing.
110
+ */
111
+ export interface NilReadingSite {
112
+ readonly typing: ScopedOperandTyping
113
+ }
114
+
107
115
  /**
108
116
  * Serialize a callback body for the runtime evaluator, with the captures its
109
117
  * env needs; `null` when the body is outside the evaluator surface. `bound`
@@ -118,11 +126,11 @@ export interface EvalBody {
118
126
  * else. Capturing `props` whole would bind it to an undefined template
119
127
  * variable, and the predicate would read every `props.X` as `undefined`.
120
128
  */
121
- export function evalBody(body: ParsedExpr, bound: ReadonlySet<string>, propsObject: string, typing?: ScopedOperandTyping): EvalBody | null {
122
- // The evaluator reads every nil as `null`: with the enclosing scope's
123
- // typing, an operand whose nil Phase 1 reads is rewritten first (#3824
124
- // step 4a), for a caller that reaches here without `emitParsedExpr`.
125
- const read = typing ? rewriteNilReadingsDeep(body, typing.enterCallback([...bound])) : body
129
+ export function evalBody(body: ParsedExpr, bound: ReadonlySet<string>, propsObject: string, site?: NilReadingSite): EvalBody | null {
130
+ // With the enclosing scope's typing, an operand whose nil Phase 1 reads is
131
+ // rewritten first (#3824 step 4a), for a caller that reaches here without
132
+ // `emitParsedExpr`, as `emitParsedExpr` would.
133
+ const read = site ? rewriteNilReadingsDeep(body, site.typing.enterCallback([...bound])) : body
126
134
  const lifted = liftPropsReads(read, bound, propsObject)
127
135
  const json = serializeParsedExpr(lifted.body)
128
136
  if (json === null) return null
@@ -96,10 +96,9 @@ export interface EarlierComponentProps {
96
96
  * caller actually handed over, and every optional param is `'present'`:
97
97
  * an `'entry'` would hand the child the key even when the caller left it
98
98
  * out, and the child would then read it as passed (a nil overriding its
99
- * own earlier prop in a further `{...props}`). Without `callerKeys` (Go,
100
- * whose Input struct can't tell the two nils apart), "passed" is "not
101
- * nil", and an explicit nil keeps the earlier value (limitation
102
- * `props-spread-explicit-null-override`).
99
+ * own earlier prop in a further `{...props}`). Without `callerKeys`,
100
+ * "passed" is "not nil"; Go answers it from its own `bf.Opt[T]` Input
101
+ * field (`Passed()`) instead.
103
102
  */
104
103
  export function propsSpreadParam(
105
104
  param: ComponentPropsParam,