@barefootjs/jsx 0.35.5 → 0.35.6

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 (102) hide show
  1. package/dist/analyzer-context.d.ts +5 -4
  2. package/dist/analyzer-context.d.ts.map +1 -1
  3. package/dist/analyzer.d.ts.map +1 -1
  4. package/dist/errors.d.ts +0 -1
  5. package/dist/errors.d.ts.map +1 -1
  6. package/dist/index.js +6711 -6471
  7. package/dist/ir-to-client-js/compute-prop-usage.d.ts +6 -0
  8. package/dist/ir-to-client-js/compute-prop-usage.d.ts.map +1 -1
  9. package/dist/ir-to-client-js/control-flow/plan/build-event-delegation.d.ts +3 -2
  10. package/dist/ir-to-client-js/control-flow/plan/build-event-delegation.d.ts.map +1 -1
  11. package/dist/ir-to-client-js/control-flow/plan/build-loop.d.ts +12 -2
  12. package/dist/ir-to-client-js/control-flow/plan/build-loop.d.ts.map +1 -1
  13. package/dist/ir-to-client-js/control-flow/plan/event-collision.d.ts +40 -0
  14. package/dist/ir-to-client-js/control-flow/plan/event-collision.d.ts.map +1 -0
  15. package/dist/ir-to-client-js/control-flow/plan/event-delegation.d.ts +13 -0
  16. package/dist/ir-to-client-js/control-flow/plan/event-delegation.d.ts.map +1 -1
  17. package/dist/ir-to-client-js/control-flow/plan/loop-delegation-index.d.ts +45 -0
  18. package/dist/ir-to-client-js/control-flow/plan/loop-delegation-index.d.ts.map +1 -0
  19. package/dist/ir-to-client-js/control-flow/plan/types.d.ts +2 -0
  20. package/dist/ir-to-client-js/control-flow/plan/types.d.ts.map +1 -1
  21. package/dist/ir-to-client-js/control-flow/stringify/event-delegation.d.ts +12 -0
  22. package/dist/ir-to-client-js/control-flow/stringify/event-delegation.d.ts.map +1 -1
  23. package/dist/ir-to-client-js/control-flow.d.ts +2 -1
  24. package/dist/ir-to-client-js/control-flow.d.ts.map +1 -1
  25. package/dist/ir-to-client-js/emit-reactive.d.ts +7 -3
  26. package/dist/ir-to-client-js/emit-reactive.d.ts.map +1 -1
  27. package/dist/ir-to-client-js/generate-init.d.ts.map +1 -1
  28. package/dist/ir-to-client-js/index.d.ts +1 -0
  29. package/dist/ir-to-client-js/index.d.ts.map +1 -1
  30. package/dist/ir-to-client-js/phases/event-handlers.d.ts +9 -1
  31. package/dist/ir-to-client-js/phases/event-handlers.d.ts.map +1 -1
  32. package/dist/ir-to-client-js/phases/props-event-handlers.d.ts +5 -0
  33. package/dist/ir-to-client-js/phases/props-event-handlers.d.ts.map +1 -1
  34. package/dist/ir-to-client-js/phases/props-extraction.d.ts +15 -13
  35. package/dist/ir-to-client-js/phases/props-extraction.d.ts.map +1 -1
  36. package/dist/ir-to-client-js/phases.d.ts +12 -1
  37. package/dist/ir-to-client-js/phases.d.ts.map +1 -1
  38. package/dist/ir-to-client-js/plan/build-declaration-emit.d.ts.map +1 -1
  39. package/dist/ir-to-client-js/prune-unused-prop-extractions.d.ts +50 -0
  40. package/dist/ir-to-client-js/prune-unused-prop-extractions.d.ts.map +1 -1
  41. package/dist/ir-to-client-js/rewrite-destructured-props.d.ts +29 -0
  42. package/dist/ir-to-client-js/rewrite-destructured-props.d.ts.map +1 -0
  43. package/dist/ir-to-client-js/utils.d.ts +9 -0
  44. package/dist/ir-to-client-js/utils.d.ts.map +1 -1
  45. package/dist/jsx-to-ir.d.ts.map +1 -1
  46. package/dist/prop-rewrite.d.ts.map +1 -1
  47. package/dist/props-binding.d.ts +112 -1
  48. package/dist/props-binding.d.ts.map +1 -1
  49. package/dist/ssr-defaults.d.ts.map +1 -1
  50. package/dist/static-literal.d.ts +20 -8
  51. package/dist/static-literal.d.ts.map +1 -1
  52. package/dist/types.d.ts +7 -0
  53. package/dist/types.d.ts.map +1 -1
  54. package/package.json +2 -2
  55. package/src/__tests__/__snapshots__/doc-examples.test.ts.snap +31 -35
  56. package/src/__tests__/aliased-destructured-prop-csr.test.ts +19 -7
  57. package/src/__tests__/body-destructured-prop-default-propsparams.test.ts +153 -0
  58. package/src/__tests__/body-destructured-props-live.test.ts +245 -0
  59. package/src/__tests__/client-js-generation.test.ts +11 -4
  60. package/src/__tests__/client-only-date-lowering.test.ts +5 -2
  61. package/src/__tests__/destructured-from-props-localconst-value.test.ts +17 -6
  62. package/src/__tests__/destructured-props-live.test.ts +167 -0
  63. package/src/__tests__/doc-examples.test.ts +2 -4
  64. package/src/__tests__/event-delegation-container-collision-2930.test.ts +197 -0
  65. package/src/__tests__/format-error.test.ts +5 -3
  66. package/src/__tests__/live-only-props.test.ts +160 -0
  67. package/src/__tests__/prop-references.test.ts +26 -17
  68. package/src/__tests__/props-destructuring.test.ts +6 -275
  69. package/src/__tests__/prune-unused-prop-extractions.test.ts +11 -5
  70. package/src/__tests__/signal-getter-not-called.test.ts +5 -0
  71. package/src/__tests__/ssr-defaults.test.ts +83 -0
  72. package/src/__tests__/staged-ir/02-shadow-guards.test.ts +12 -5
  73. package/src/__tests__/static-literal.test.ts +39 -4
  74. package/src/analyzer-context.ts +8 -7
  75. package/src/analyzer.ts +76 -84
  76. package/src/errors.ts +7 -8
  77. package/src/ir-to-client-js/compute-prop-usage.ts +19 -0
  78. package/src/ir-to-client-js/control-flow/plan/build-event-delegation.ts +5 -0
  79. package/src/ir-to-client-js/control-flow/plan/build-loop.ts +27 -11
  80. package/src/ir-to-client-js/control-flow/plan/event-collision.ts +55 -0
  81. package/src/ir-to-client-js/control-flow/plan/event-delegation.ts +13 -0
  82. package/src/ir-to-client-js/control-flow/plan/loop-delegation-index.ts +79 -0
  83. package/src/ir-to-client-js/control-flow/plan/types.ts +2 -0
  84. package/src/ir-to-client-js/control-flow/stringify/event-delegation.ts +50 -10
  85. package/src/ir-to-client-js/control-flow.ts +68 -31
  86. package/src/ir-to-client-js/emit-reactive.ts +12 -8
  87. package/src/ir-to-client-js/generate-init.ts +6 -0
  88. package/src/ir-to-client-js/index.ts +45 -3
  89. package/src/ir-to-client-js/phases/event-handlers.ts +10 -0
  90. package/src/ir-to-client-js/phases/props-event-handlers.ts +6 -0
  91. package/src/ir-to-client-js/phases/props-extraction.ts +29 -48
  92. package/src/ir-to-client-js/phases.ts +17 -3
  93. package/src/ir-to-client-js/plan/build-declaration-emit.ts +6 -5
  94. package/src/ir-to-client-js/prune-unused-prop-extractions.ts +31 -10
  95. package/src/ir-to-client-js/rewrite-destructured-props.ts +210 -0
  96. package/src/ir-to-client-js/utils.ts +14 -0
  97. package/src/jsx-to-ir.ts +96 -48
  98. package/src/prop-rewrite.ts +11 -0
  99. package/src/props-binding.ts +171 -6
  100. package/src/ssr-defaults.ts +10 -5
  101. package/src/static-literal.ts +21 -9
  102. package/src/types.ts +7 -0
@@ -9,8 +9,12 @@
9
9
  * (the caller passes `n`) and the local binding hydrated to `undefined`.
10
10
  *
11
11
  * Mirrors `ssr-defaults.test.ts`'s aliased-prop describes (#2460) for the
12
- * SSR-defaults half; this covers the generated `initXxx` extraction and
13
- * the CSR `template:` lambda.
12
+ * SSR-defaults half; this covers the generated `initXxx` body and the CSR
13
+ * `template:` lambda.
14
+ *
15
+ * The rule pinned here is the caller-facing key: `_p` is keyed by
16
+ * `sourceName ?? name`, read at every reference site (there is no
17
+ * captured-once `const <local> = _p.<callerKey>` extraction).
14
18
  */
15
19
 
16
20
  import { describe, test, expect } from 'bun:test'
@@ -37,10 +41,11 @@ describe('aliased destructured props reach client JS under the caller-facing key
37
41
 
38
42
  const clientJs = result.files.find((f) => f.type === 'clientJs')
39
43
  expect(clientJs).toBeDefined()
40
- // `initBadge` extracts the local binding `count` from the
41
- // CALLER-facing key `n` — never the local key `count`.
42
- expect(clientJs!.content).toContain('const count = _p.n')
44
+ // Every reference reads the CALLER-facing key `n`, never the local
45
+ // key `count`, and no local binding is introduced for it.
46
+ expect(clientJs!.content).not.toContain('const count = ')
43
47
  expect(clientJs!.content).not.toContain('_p.count')
48
+ expect(clientJs!.content).toContain('console.log(_p.n)')
44
49
  // The CSR `template:` lambda (module-scope SSR fallback) reads the
45
50
  // same caller-facing key.
46
51
  // `escapeTextOrMarkup`, not bare `escapeText` — this slot is
@@ -68,7 +73,11 @@ describe('aliased destructured props reach client JS under the caller-facing key
68
73
 
69
74
  const clientJs = result.files.find((f) => f.type === 'clientJs')
70
75
  expect(clientJs).toBeDefined()
71
- expect(clientJs!.content).toContain('const n = _p.n')
76
+ // `sourceName ?? name` is an identity for an un-aliased prop, so this
77
+ // is indistinguishable from the aliased case above once the
78
+ // caller-facing key is substituted.
79
+ expect(clientJs!.content).not.toContain('const n = ')
80
+ expect(clientJs!.content).toContain('console.log(_p.n)')
72
81
  // `escapeTextOrMarkup`, not bare `escapeText` — this slot is
73
82
  // claim-plan `kind: 'markup'` (#2651), unrelated to the #2524 aliasing
74
83
  // concern this test pins; only the escape call's name changed.
@@ -112,7 +121,10 @@ describe('aliased destructured props reach client JS under the caller-facing key
112
121
 
113
122
  const clientJs = result.files.find((f) => f.type === 'clientJs')
114
123
  expect(clientJs).toBeDefined()
115
- expect(clientJs!.content).toContain('const handlePress = _p.onPress')
124
+ // The handler reference reads the CALLER-facing key `onPress`, never
125
+ // the local key `handlePress`.
126
+ expect(clientJs!.content).not.toContain('const handlePress = ')
127
+ expect(clientJs!.content).toContain('_p.onPress')
116
128
  expect(clientJs!.content).not.toContain('_p.handlePress')
117
129
  })
118
130
  })
@@ -0,0 +1,153 @@
1
+ /**
2
+ * Pins #2943's fix: a BODY-destructured prop's default (`const { label =
3
+ * 'none' } = props`) is now visible on `ir.metadata.propsParams` itself —
4
+ * the SAME shared `ParamInfo` a parameter-destructured default
5
+ * (`function Foo({ label = 'none' })`) already populated via
6
+ * `extractPropsFromTypeMembers`'s sibling path. Before this fix,
7
+ * `extractPropsFromTypeMembers` built `propsParams` purely from the TYPE
8
+ * annotation, with no notion of a body destructure's own default — every
9
+ * downstream SSR consumer of `ParamInfo.defaultValue`/`.optional` (each
10
+ * template adapter's presence-guard classification, `extractSsrDefaults`'s
11
+ * stash seed) then treated the prop as defaultless, guarding the attribute
12
+ * and omitting it entirely instead of falling back to the default the way
13
+ * Hono's real JS destructuring naturally does.
14
+ *
15
+ * See `analyzer.ts`'s `collectConstant` (the body-destructure branch) and
16
+ * `bindingElementDefaultFields` (the helper it now shares with the
17
+ * parameter-destructured path in `extractProps`).
18
+ */
19
+
20
+ import { describe, test, expect } from 'bun:test'
21
+ import { analyzeComponent } from '../analyzer'
22
+ import { buildMetadata } from '../compiler'
23
+
24
+ function propsParamsFor(source: string) {
25
+ const ctx = analyzeComponent(source, 'test.tsx')
26
+ return buildMetadata(ctx).propsParams
27
+ }
28
+
29
+ describe('body-destructured prop defaults overlay onto propsParams (#2943)', () => {
30
+ test('unrenamed default: the type-member entry gets defaultValue/parsed/optional', () => {
31
+ const propsParams = propsParamsFor(`
32
+ function Foo(props: { label?: string }) {
33
+ const { label = 'none' } = props
34
+ return <div data-label={label} />
35
+ }
36
+ `)
37
+ expect(propsParams).toEqual([
38
+ {
39
+ name: 'label',
40
+ type: { kind: 'primitive', raw: 'string', primitive: 'string' },
41
+ optional: true,
42
+ defaultValue: "'none'",
43
+ parsed: { kind: 'literal', value: 'none', literalType: 'string' },
44
+ },
45
+ ])
46
+ })
47
+
48
+ test('renamed default: ADDS a second entry (sourceName-bearing) rather than replacing the original', () => {
49
+ // `label` itself stays a real, separately-classified binding (no
50
+ // default of its own — a bare `props.label` read elsewhere is still
51
+ // correctly guarded/stash-seeded), and `text` carries `sourceName:
52
+ // 'label'` so every `sourceName ?? name` consumer resolves the
53
+ // caller-facing key.
54
+ const propsParams = propsParamsFor(`
55
+ function Foo(props: { label?: string }) {
56
+ const { label: text = 'none' } = props
57
+ return <div data-label={text} />
58
+ }
59
+ `)
60
+ expect(propsParams).toHaveLength(2)
61
+ expect(propsParams.find(p => p.name === 'label')).toEqual({
62
+ name: 'label',
63
+ type: { kind: 'primitive', raw: 'string', primitive: 'string' },
64
+ optional: true,
65
+ })
66
+ expect(propsParams.find(p => p.name === 'text')).toEqual({
67
+ name: 'text',
68
+ type: { kind: 'primitive', raw: 'string', primitive: 'string' },
69
+ optional: true,
70
+ sourceName: 'label',
71
+ defaultValue: "'none'",
72
+ parsed: { kind: 'literal', value: 'none', literalType: 'string' },
73
+ })
74
+ })
75
+
76
+ test('untyped `props` param: synthesizes a propsParams entry with `type: unknown` (matching the parameter form\'s own fallback)', () => {
77
+ const propsParams = propsParamsFor(`
78
+ function Foo(props) {
79
+ const { label = 'none' } = props
80
+ return <div data-label={label} />
81
+ }
82
+ `)
83
+ expect(propsParams).toEqual([
84
+ {
85
+ name: 'label',
86
+ type: { kind: 'unknown', raw: 'unknown' },
87
+ optional: true,
88
+ defaultValue: "'none'",
89
+ parsed: { kind: 'literal', value: 'none', literalType: 'string' },
90
+ },
91
+ ])
92
+ })
93
+
94
+ test('arrow-function default (#2940): defaultContainsArrow is set and `parsed` is a real structured arrow, not a truncated re-parse', () => {
95
+ const propsParams = propsParamsFor(`
96
+ function Foo(props: { fmt?: (v: number) => string }) {
97
+ const { fmt = (v) => 'v' + v } = props
98
+ return <div>{fmt(1)}</div>
99
+ }
100
+ `)
101
+ expect(propsParams).toHaveLength(1)
102
+ const fmt = propsParams[0]!
103
+ expect(fmt.name).toBe('fmt')
104
+ expect(fmt.optional).toBe(true)
105
+ expect(fmt.defaultValue).toBe("(v) => 'v' + v")
106
+ expect(fmt.defaultContainsArrow).toBe(true)
107
+ expect(fmt.parsed?.kind).toBe('arrow')
108
+ })
109
+
110
+ test('renamed, NO default (#2788 shape, unaffected): still just one propsParams entry — no `kids` synthesized', () => {
111
+ // Defaultless renames stay on the pre-existing #2788 path
112
+ // (`resolveBodyDestructuredPropAliases`'s SSR-stash local-name-seeding
113
+ // safety net) — this fix's overlay only fires when `el.initializer`
114
+ // is present, so it must never duplicate that mechanism's work.
115
+ const propsParams = propsParamsFor(`
116
+ function Foo(props: { children?: string }) {
117
+ const { children: kids } = props
118
+ return <span>{kids}</span>
119
+ }
120
+ `)
121
+ expect(propsParams).toEqual([
122
+ {
123
+ name: 'children',
124
+ type: { kind: 'primitive', raw: 'string', primitive: 'string' },
125
+ optional: true,
126
+ },
127
+ ])
128
+ })
129
+
130
+ test('a `let` binding still gets the default overlaid — the default is a declaration-time fact, independent of live-rewrite safety', () => {
131
+ // Unlike `resolveBodyPropAliases`'s `requireLiveRewriteSafe` gate
132
+ // (which excludes `let`/mutated locals because turning them into a
133
+ // LIVE `_p.X` read could silently write through to the caller's
134
+ // prop), a static SSR default has no such hazard — it describes what
135
+ // the source looked like at its own declaration line, nothing more.
136
+ const propsParams = propsParamsFor(`
137
+ function Foo(props: { label?: string }) {
138
+ let { label = 'none' } = props
139
+ label = label.toUpperCase()
140
+ return <div data-label={label} />
141
+ }
142
+ `)
143
+ expect(propsParams).toEqual([
144
+ {
145
+ name: 'label',
146
+ type: { kind: 'primitive', raw: 'string', primitive: 'string' },
147
+ optional: true,
148
+ defaultValue: "'none'",
149
+ parsed: { kind: 'literal', value: 'none', literalType: 'string' },
150
+ },
151
+ ])
152
+ })
153
+ })
@@ -0,0 +1,245 @@
1
+ /**
2
+ * Body-destructured (or plain member-access alias) props stay reactive too
3
+ * (#2934) — the body-destructure twin of `destructured-props-live.test.ts`.
4
+ * A pure single-prop passthrough local in a bare-props-form component
5
+ * (`function Foo(props) { const { value } = props; ... }`, or the
6
+ * equivalent `const value = props.value`) has its own extraction dropped
7
+ * and every reference rewritten to a live `_p.<key>` read (or
8
+ * `(_p.<key> ?? <fallback>)`), same as `props.xxx` access and parameter
9
+ * destructuring. See `props-binding.ts`'s `resolveBodyPropAliases` and
10
+ * `ir-to-client-js/rewrite-destructured-props.ts`'s `rewriteBodyAliasReads`.
11
+ */
12
+
13
+ import { describe, test, expect } from 'bun:test'
14
+ import { compileJSX } from '../compiler'
15
+ import { TestAdapter } from '../adapters/test-adapter'
16
+
17
+ const adapter = new TestAdapter()
18
+
19
+ function compileClientJs(source: string, filename = 'Component.tsx') {
20
+ const result = compileJSX(source, filename, { adapter })
21
+ const errors = result.errors.filter((e) => e.severity === 'error')
22
+ expect(errors).toEqual([])
23
+ const clientJs = result.files.find((f) => f.type === 'clientJs')
24
+ expect(clientJs).toBeDefined()
25
+ return { content: clientJs!.content, result }
26
+ }
27
+
28
+ describe('body-destructured props compile to live reads', () => {
29
+ test('a body-destructured prop no longer gets a captured-once extraction line', () => {
30
+ const source = `
31
+ 'use client'
32
+ import { createSignal, createMemo, createEffect } from '@barefootjs/client'
33
+
34
+ function Child(props: {
35
+ value: number
36
+ onClick: () => void
37
+ label?: string
38
+ size?: string
39
+ items?: string[]
40
+ }) {
41
+ const { value, onClick, label = 'n', size = 'md', items = [] } = props
42
+ const doubled = createMemo(() => value * 2)
43
+ const [local, setLocal] = createSignal(value)
44
+ createEffect(() => {
45
+ console.log('value is', value)
46
+ })
47
+ return (
48
+ <div className={size}>
49
+ <span data-label={label}>{value}</span>
50
+ <span>{doubled()}</span>
51
+ <span>{items.length}</span>
52
+ <button onClick={() => { setLocal(value); onClick() }}>click</button>
53
+ </div>
54
+ )
55
+ }
56
+ `
57
+ const { content } = compileClientJs(source, 'Child.tsx')
58
+
59
+ // No captured-once local for any body-destructured prop.
60
+ expect(content).not.toMatch(/const value = /)
61
+ expect(content).not.toMatch(/const onClick = /)
62
+ expect(content).not.toMatch(/const label = /)
63
+ expect(content).not.toMatch(/const size = /)
64
+ expect(content).not.toMatch(/const items = /)
65
+
66
+ // Memo computation reads the live prop directly.
67
+ expect(content).toMatch(/createMemo\(\(\) => _p\.value \* 2\)/)
68
+
69
+ // The user effect reads the live prop, not a captured local.
70
+ expect(content).toContain("console.log('value is', _p.value)")
71
+
72
+ // The handler reads the live prop for both the signal update and the
73
+ // callback-prop invocation.
74
+ expect(content).toContain('_p.onClick()')
75
+ expect(content).toContain('setLocal(_p.value)')
76
+
77
+ // `items`'s destructure default survives as a live fallback, not a
78
+ // one-time extraction.
79
+ expect(content).toContain('(_p.items ?? []).length')
80
+ })
81
+
82
+ test('the CSR template lambda also reads a defaulted body alias live, matching the parameter form (#2934)', () => {
83
+ // This is the sibling bug the init-body fix alone doesn't cover: the
84
+ // CSR `template:` lambda (used for a fresh client-side mount with no
85
+ // SSR markup) is built at Phase 1 from `ctx.analyzer.propsParams`
86
+ // (via `jsx-to-ir.ts`'s `_destructuredPropInfoByName` cache), which
87
+ // for a props-object-mode component used to hold only type-member
88
+ // info with no default of its own — so `data-label={label}` compiled
89
+ // to a bare `_p.label` there, omitting the attribute entirely on a
90
+ // CSR-fresh mount where `_p.label` is `undefined`, instead of
91
+ // applying the `'none'` default like the parameter-destructured form
92
+ // already did. Fixed at the source (#2943): the analyzer now overlays
93
+ // a body-destructure default directly onto `propsParams` itself
94
+ // (`collectConstant`, `analyzer.ts`) — the SAME shared `ParamInfo`
95
+ // every other consumer (SSR prop classification, `extractSsrDefaults`)
96
+ // reads, so this CSR cache needs no separate default-resolution logic
97
+ // of its own anymore.
98
+ const source = `
99
+ 'use client'
100
+ function Child(props: { label?: string }) {
101
+ const { label = 'none' } = props
102
+ return <div data-label={label}>{label}</div>
103
+ }
104
+ `
105
+ const { content } = compileClientJs(source, 'Child.tsx')
106
+ expect(content).not.toMatch(/const label = /)
107
+ expect(content).toContain("escapeAttr((_p.label ?? 'none'))")
108
+ expect(content).toContain("escapeTextOrMarkup((_p.label ?? 'none'))")
109
+ // Never the bare, default-dropping form.
110
+ expect(content).not.toMatch(/\(_p\.label\) != null/)
111
+ })
112
+
113
+ test('a RENAMED body-destructured prop WITH A DEFAULT (`label: text = "none"`) applies the default in the CSR template lambda too (#2943)', () => {
114
+ // The renamed twin of the unrenamed test above. Before #2943 this
115
+ // combination had no fixture and no dedicated check — the CSR
116
+ // template lambda's default application only ever reached an
117
+ // UNRENAMED alias.
118
+ const source = `
119
+ 'use client'
120
+ function Child(props: { label?: string }) {
121
+ const { label: text = 'none' } = props
122
+ return <div data-label={text}>{text}</div>
123
+ }
124
+ `
125
+ const { content } = compileClientJs(source, 'Child.tsx')
126
+ expect(content).not.toMatch(/const text = /)
127
+ expect(content).toContain("escapeAttr((_p.label ?? 'none'))")
128
+ expect(content).toContain("escapeTextOrMarkup((_p.label ?? 'none'))")
129
+ })
130
+
131
+ test('a renamed body-destructured prop (`onPick: pick`) reads the caller-facing key live everywhere', () => {
132
+ const source = `
133
+ 'use client'
134
+ import { createEffect } from '@barefootjs/client'
135
+ function Badge(props: { text: string; n: number }) {
136
+ const { text, n: count } = props
137
+ createEffect(() => {
138
+ console.log(count)
139
+ })
140
+ return <span>{text}:{count}</span>
141
+ }
142
+ `
143
+ const { content } = compileClientJs(source, 'Badge.tsx')
144
+ expect(content).not.toMatch(/const count = /)
145
+ expect(content).not.toContain('_p.count')
146
+ expect(content).toContain('console.log(_p.n)')
147
+ })
148
+
149
+ test('a plain member-access alias (`const label = props.label`, no destructure) gets identical treatment', () => {
150
+ const source = `
151
+ 'use client'
152
+ import { createEffect } from '@barefootjs/client'
153
+ function Child(props: { label: string }) {
154
+ const label = props.label
155
+ createEffect(() => {
156
+ console.log(label)
157
+ })
158
+ return <span>{label}</span>
159
+ }
160
+ `
161
+ const { content } = compileClientJs(source, 'Child.tsx')
162
+ expect(content).not.toMatch(/const label = /)
163
+ expect(content).toContain('console.log(_p.label)')
164
+ })
165
+
166
+ test('a computation derived from a body-destructured prop stays an ordinary once-evaluated local', () => {
167
+ const source = `
168
+ 'use client'
169
+ function Child(props: { value: number }) {
170
+ const { value } = props
171
+ const doubled = value * 2
172
+ return <span>{doubled}</span>
173
+ }
174
+ `
175
+ const { content } = compileClientJs(source, 'Child.tsx')
176
+ expect(content).toContain('const doubled = _p.value * 2')
177
+ })
178
+
179
+ test('a `let` body destructure is never treated as a live alias (reassignment stays a real local)', () => {
180
+ const source = `
181
+ 'use client'
182
+ import { createEffect } from '@barefootjs/client'
183
+ function Child(props: { count: number }) {
184
+ let { count } = props
185
+ count += 1
186
+ createEffect(() => {
187
+ console.log(count)
188
+ })
189
+ return <span>{count}</span>
190
+ }
191
+ `
192
+ const { content } = compileClientJs(source, 'Child.tsx')
193
+ expect(content).toMatch(/let count = _p\.count/)
194
+ expect(content).toContain('count += 1')
195
+ })
196
+
197
+ test('shadowing is preserved: a `.map()` callback param and a handler-local both keep their own binding', () => {
198
+ const source = `
199
+ 'use client'
200
+ import { createSignal } from '@barefootjs/client'
201
+ function List(props: { title: string; items: { a: string }[] }) {
202
+ const { title, items } = props
203
+ const [count, setCount] = createSignal(0)
204
+ return (
205
+ <div>
206
+ <span>{title}</span>
207
+ <ul>
208
+ {items.map((title) => <li key={title.a}>{title.a}</li>)}
209
+ </ul>
210
+ <button onClick={() => {
211
+ const title = 'local'
212
+ console.log(title)
213
+ setCount(count() + 1)
214
+ }}>click</button>
215
+ </div>
216
+ )
217
+ }
218
+ `
219
+ const { content } = compileClientJs(source, 'List.tsx')
220
+ // The outer `title` prop is rewritten wherever it is a free reference.
221
+ expect(content).toContain('_p.title')
222
+ // The `.map()` callback's OWN `title` parameter must never be rewritten
223
+ // — `(_p.title) => _p.title.a` would be invalid JS.
224
+ expect(content).not.toMatch(/\(_p\.title\)\s*=>/)
225
+ expect(content).toMatch(/\(title\)\s*=>[\s\S]*?title\.a/)
226
+ // The handler-local `const title = 'local'` shadows the prop for the
227
+ // rest of that handler — its own reference must stay bare.
228
+ expect(content).toContain("const title = 'local'")
229
+ expect(content).toContain('console.log(title)')
230
+ })
231
+
232
+ test('`children` keeps its one-time captured-once extraction (not rewritten live)', () => {
233
+ const source = `
234
+ 'use client'
235
+ import { createSignal } from '@barefootjs/client'
236
+ function Wrapper(props: { children: unknown }) {
237
+ const { children } = props
238
+ const [open, setOpen] = createSignal(true)
239
+ return <div onClick={() => setOpen(!open())}>{open() ? children : null}</div>
240
+ }
241
+ `
242
+ const { content } = compileClientJs(source, 'Wrapper.tsx')
243
+ expect(content).toContain('const children = _p.children')
244
+ })
245
+ })
@@ -301,9 +301,12 @@ describe('Client JS generation', () => {
301
301
  expect(clientJs).toBeDefined()
302
302
  const content = clientJs!.content
303
303
 
304
- // Props used as conditional guards should NOT get ?? {} default
305
- expect(content).toContain('const prev = _p.prev\n')
306
- expect(content).toContain('const next = _p.next\n')
304
+ // Props used as conditional guards must NOT get a `?? {}` default,
305
+ // at the live read sites they now compile to.
306
+ expect(content).not.toContain('const prev = ')
307
+ expect(content).not.toContain('const next = ')
308
+ expect(content).toContain('() => _p.prev,')
309
+ expect(content).toContain('() => _p.next,')
307
310
  expect(content).not.toContain('_p.prev ?? {}')
308
311
  expect(content).not.toContain('_p.next ?? {}')
309
312
  })
@@ -2874,7 +2877,11 @@ describe('Client JS generation', () => {
2874
2877
  const result = compileJSX(source, 'Probe.tsx', { adapter })
2875
2878
  expect(result.errors.filter(e => e.severity === 'error')).toHaveLength(0)
2876
2879
  const js = result.files.find(f => f.type === 'clientJs')!.content
2877
- expect(js).toContain('const size = _p.size')
2880
+ // The bare `size` inside the user's own `size ?? 1` reads live as
2881
+ // `_p.size`, keeping their `?? 1` default exactly as written — the
2882
+ // compiler must not synthesize a competing one.
2883
+ expect(js).not.toContain('const size = ')
2884
+ expect(js).toContain('createSignal(_p.size ?? 1)')
2878
2885
  expect(js).not.toContain('_p.size ?? 0')
2879
2886
  })
2880
2887
 
@@ -70,7 +70,9 @@ describe('#2640 — /* @client */ text expressions route catalogued calls throug
70
70
  }
71
71
  `)
72
72
  expect(bf021).toHaveLength(0)
73
- expect(clientJs).toContain('date(createdAt, "toISOString")')
73
+ // The receiver is a destructured prop, so it reads live as
74
+ // `_p.createdAt`; the catalogued-call lowering itself is unaffected.
75
+ expect(clientJs).toContain('date(_p.createdAt, "toISOString")')
74
76
  expect(clientJs).not.toContain('createdAt.toISOString()')
75
77
  expect(clientJs).toMatch(/import\s*\{[^}]*\bdate\b[^}]*\}\s*from\s*'@barefootjs\/client\/runtime'/)
76
78
  })
@@ -82,7 +84,8 @@ describe('#2640 — /* @client */ text expressions route catalogued calls throug
82
84
  }
83
85
  `)
84
86
  expect(bf021).toHaveLength(0)
85
- expect(clientJs).toContain('formatDate(createdAt, "YYYY/M/D", "UTC")')
87
+ // Same live-receiver rewrite as the zero-arg case above.
88
+ expect(clientJs).toContain('formatDate(_p.createdAt, "YYYY/M/D", "UTC")')
86
89
  expect(clientJs).not.toContain(".toLocaleDateString('ja-JP'")
87
90
  })
88
91
 
@@ -82,7 +82,17 @@ describe('destructured-from-props-object → localConstants value rewrite', () =
82
82
  expect(content).not.toMatch(/const\s+doubled\s*=\s*_p\.count\(\)/)
83
83
  })
84
84
 
85
- test('shadow guard: earlier local that shadows a prop is NOT rewritten', () => {
85
+ // #2934: `const label = props.label ?? 'fallback'` is a PURE single-prop
86
+ // alias — the analyzer's IR can't distinguish it from a destructure
87
+ // (`const { label = 'fallback' } = props`), and `resolveBodyPropAliases`
88
+ // deliberately treats both identically (see its docstring). So `label`'s
89
+ // own declaration is now removed and every reference to it — including
90
+ // from a DEPENDENT local's own initializer, `upper` here — becomes a
91
+ // live `_p.label` read. This used to be named a "shadow guard" test, back
92
+ // when `label` was expected to stay a captured-once local distinct from
93
+ // the prop; that framing no longer applies now that a same-named pure
94
+ // alias IS made live rather than left as its own local.
95
+ test('a plain member-access prop alias is rewritten live, including from a dependent local', () => {
86
96
  const source = `
87
97
  'use client'
88
98
 
@@ -102,10 +112,11 @@ describe('destructured-from-props-object → localConstants value rewrite', () =
102
112
  const clientJs = result.files.find((f) => f.type === 'clientJs')
103
113
  const content = clientJs?.content ?? ''
104
114
 
105
- // `label` here is the local const (shadowing the prop). The init body
106
- // emits `const label = _p.label ?? 'fallback'` (late-stage rename),
107
- // and `upper` should reference the LOCAL `label`, not `_p.label`.
108
- expect(content).toMatch(/const\s+upper\s*=\s*label\.toUpperCase\(\)/)
109
- expect(content).not.toMatch(/const\s+upper\s*=\s*_p\.label\.toUpperCase\(\)/)
115
+ // `label`'s own extraction is gone — it was a pure alias, not a real
116
+ // computation of its own.
117
+ expect(content).not.toMatch(/const\s+label\s*=/)
118
+ // `upper` (still a real once-evaluated local — `.toUpperCase()` is a
119
+ // computation) now sources its value directly from the live prop read.
120
+ expect(content).toMatch(/const\s+upper\s*=\s*\(_p\.label\s*\?\?\s*'fallback'\)\.toUpperCase\(\)/)
110
121
  })
111
122
  })