@barefootjs/jsx 0.35.5 → 0.35.7

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 (106) 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 +6745 -6488
  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/html-template.d.ts.map +1 -1
  29. package/dist/ir-to-client-js/index.d.ts +1 -0
  30. package/dist/ir-to-client-js/index.d.ts.map +1 -1
  31. package/dist/ir-to-client-js/phases/event-handlers.d.ts +9 -1
  32. package/dist/ir-to-client-js/phases/event-handlers.d.ts.map +1 -1
  33. package/dist/ir-to-client-js/phases/props-event-handlers.d.ts +5 -0
  34. package/dist/ir-to-client-js/phases/props-event-handlers.d.ts.map +1 -1
  35. package/dist/ir-to-client-js/phases/props-extraction.d.ts +15 -13
  36. package/dist/ir-to-client-js/phases/props-extraction.d.ts.map +1 -1
  37. package/dist/ir-to-client-js/phases.d.ts +12 -1
  38. package/dist/ir-to-client-js/phases.d.ts.map +1 -1
  39. package/dist/ir-to-client-js/plan/build-declaration-emit.d.ts.map +1 -1
  40. package/dist/ir-to-client-js/prune-unused-prop-extractions.d.ts +50 -0
  41. package/dist/ir-to-client-js/prune-unused-prop-extractions.d.ts.map +1 -1
  42. package/dist/ir-to-client-js/rewrite-destructured-props.d.ts +29 -0
  43. package/dist/ir-to-client-js/rewrite-destructured-props.d.ts.map +1 -0
  44. package/dist/ir-to-client-js/utils.d.ts +9 -0
  45. package/dist/ir-to-client-js/utils.d.ts.map +1 -1
  46. package/dist/jsx-to-ir.d.ts.map +1 -1
  47. package/dist/prop-rewrite.d.ts.map +1 -1
  48. package/dist/props-binding.d.ts +123 -1
  49. package/dist/props-binding.d.ts.map +1 -1
  50. package/dist/ssr-defaults.d.ts.map +1 -1
  51. package/dist/static-literal.d.ts +20 -8
  52. package/dist/static-literal.d.ts.map +1 -1
  53. package/dist/types.d.ts +7 -0
  54. package/dist/types.d.ts.map +1 -1
  55. package/package.json +2 -2
  56. package/src/__tests__/__snapshots__/doc-examples.test.ts.snap +31 -35
  57. package/src/__tests__/aliased-destructured-prop-csr.test.ts +19 -7
  58. package/src/__tests__/body-destructured-prop-default-arrow.test.ts +142 -0
  59. package/src/__tests__/body-destructured-prop-default-propsparams.test.ts +153 -0
  60. package/src/__tests__/body-destructured-props-live.test.ts +245 -0
  61. package/src/__tests__/client-js-generation.test.ts +11 -4
  62. package/src/__tests__/client-only-date-lowering.test.ts +5 -2
  63. package/src/__tests__/destructured-from-props-localconst-value.test.ts +17 -6
  64. package/src/__tests__/destructured-props-live.test.ts +167 -0
  65. package/src/__tests__/doc-examples.test.ts +2 -4
  66. package/src/__tests__/event-delegation-container-collision-2930.test.ts +197 -0
  67. package/src/__tests__/format-error.test.ts +5 -3
  68. package/src/__tests__/issue-2960-multi-root-cond-same-tag.test.ts +141 -0
  69. package/src/__tests__/live-only-props.test.ts +160 -0
  70. package/src/__tests__/prop-references.test.ts +26 -17
  71. package/src/__tests__/props-destructuring.test.ts +6 -275
  72. package/src/__tests__/prune-unused-prop-extractions.test.ts +11 -5
  73. package/src/__tests__/signal-getter-not-called.test.ts +5 -0
  74. package/src/__tests__/ssr-defaults.test.ts +83 -0
  75. package/src/__tests__/staged-ir/02-shadow-guards.test.ts +12 -5
  76. package/src/__tests__/static-literal.test.ts +39 -4
  77. package/src/analyzer-context.ts +8 -7
  78. package/src/analyzer.ts +88 -89
  79. package/src/errors.ts +7 -8
  80. package/src/ir-to-client-js/compute-prop-usage.ts +19 -0
  81. package/src/ir-to-client-js/control-flow/plan/build-event-delegation.ts +5 -0
  82. package/src/ir-to-client-js/control-flow/plan/build-loop.ts +27 -11
  83. package/src/ir-to-client-js/control-flow/plan/event-collision.ts +55 -0
  84. package/src/ir-to-client-js/control-flow/plan/event-delegation.ts +13 -0
  85. package/src/ir-to-client-js/control-flow/plan/loop-delegation-index.ts +79 -0
  86. package/src/ir-to-client-js/control-flow/plan/types.ts +2 -0
  87. package/src/ir-to-client-js/control-flow/stringify/event-delegation.ts +50 -10
  88. package/src/ir-to-client-js/control-flow.ts +68 -31
  89. package/src/ir-to-client-js/emit-reactive.ts +12 -8
  90. package/src/ir-to-client-js/generate-init.ts +6 -0
  91. package/src/ir-to-client-js/html-template.ts +65 -9
  92. package/src/ir-to-client-js/index.ts +45 -3
  93. package/src/ir-to-client-js/phases/event-handlers.ts +10 -0
  94. package/src/ir-to-client-js/phases/props-event-handlers.ts +6 -0
  95. package/src/ir-to-client-js/phases/props-extraction.ts +29 -48
  96. package/src/ir-to-client-js/phases.ts +17 -3
  97. package/src/ir-to-client-js/plan/build-declaration-emit.ts +6 -5
  98. package/src/ir-to-client-js/prune-unused-prop-extractions.ts +31 -10
  99. package/src/ir-to-client-js/rewrite-destructured-props.ts +222 -0
  100. package/src/ir-to-client-js/utils.ts +14 -0
  101. package/src/jsx-to-ir.ts +96 -48
  102. package/src/prop-rewrite.ts +11 -0
  103. package/src/props-binding.ts +185 -6
  104. package/src/ssr-defaults.ts +10 -5
  105. package/src/static-literal.ts +21 -9
  106. package/src/types.ts +7 -0
@@ -0,0 +1,160 @@
1
+ /**
2
+ * `liveOnlyProps` classification (Move C, Prop Boundary Contract).
3
+ *
4
+ * `computeLiveOnlyProps` (`ir-to-client-js/index.ts`) marks which props the
5
+ * client code CALLS rather than reads, so they cannot arrive as JSON. It
6
+ * only classifies — whether that matters for a given mount is decided at
7
+ * render time by the Hono adapter's gated `serializeHydrationProps` call
8
+ * (`serialize-hydration-props.test.ts` covers that half).
9
+ */
10
+
11
+ import { describe, test, expect } from 'bun:test'
12
+ import { analyzeComponent } from '../analyzer'
13
+ import { jsxToIR } from '../jsx-to-ir'
14
+ import { buildMetadata } from '../compiler'
15
+ import { analyzeClientNeeds } from '../ir-to-client-js'
16
+ import type { ComponentIR } from '../types'
17
+
18
+ function analyze(source: string): ReturnType<typeof analyzeClientNeeds> {
19
+ const ctx = analyzeComponent(source, 'Test.tsx')
20
+ const ir = jsxToIR(ctx)
21
+ expect(ir).not.toBeNull()
22
+ const componentIR: ComponentIR = {
23
+ version: '0.1',
24
+ metadata: buildMetadata(ctx),
25
+ root: ir!,
26
+ errors: [],
27
+ }
28
+ return analyzeClientNeeds(componentIR)
29
+ }
30
+
31
+ describe('liveOnlyProps — fires', () => {
32
+ test('a function-typed prop actually called by client code lands in liveOnlyProps', () => {
33
+ const analysis = analyze(`
34
+ 'use client'
35
+ export function Display({ value }: { value: () => number }) {
36
+ return <button onClick={() => console.log(value())}>{value()}</button>
37
+ }
38
+ `)
39
+ expect(analysis.needsInit).toBe(true)
40
+ expect(analysis.usedProps).toContain('value')
41
+ expect(Object.keys(analysis.liveOnlyProps)).toContain('value')
42
+ expect(analysis.liveOnlyProps.value).toBe('() => number')
43
+ })
44
+
45
+ test('object-form Function-typed prop actually called by client code also lands in liveOnlyProps', () => {
46
+ const analysis = analyze(`
47
+ 'use client'
48
+ export function Foo({ cb }: { cb: Function }) {
49
+ return <button onClick={() => cb()}>go</button>
50
+ }
51
+ `)
52
+ expect(Object.keys(analysis.liveOnlyProps)).toContain('cb')
53
+ expect(analysis.liveOnlyProps.cb).toBe('Function')
54
+ })
55
+
56
+ test('renamed destructured prop is keyed by its caller-facing (source) name, not the local binding', () => {
57
+ const analysis = analyze(`
58
+ 'use client'
59
+ export function Display({ value: getValue }: { value: () => number }) {
60
+ return <button onClick={() => console.log(getValue())}>go</button>
61
+ }
62
+ `)
63
+ expect(Object.keys(analysis.liveOnlyProps)).toContain('value')
64
+ expect(analysis.liveOnlyProps).not.toHaveProperty('getValue')
65
+ })
66
+
67
+ test('an OPTIONAL function-typed prop still resolves (stripUnion drops the undefined arm)', () => {
68
+ const analysis = analyze(`
69
+ 'use client'
70
+ export function Display({ value }: { value?: () => number }) {
71
+ return <button onClick={() => console.log(value?.())}>go</button>
72
+ }
73
+ `)
74
+ expect(Object.keys(analysis.liveOnlyProps)).toContain('value')
75
+ })
76
+
77
+ test('props-object mode (props.value) resolves the same way', () => {
78
+ const analysis = analyze(`
79
+ 'use client'
80
+ export function Display(props: { value: () => number }) {
81
+ return <button onClick={() => console.log(props.value())}>go</button>
82
+ }
83
+ `)
84
+ expect(Object.keys(analysis.liveOnlyProps)).toContain('value')
85
+ })
86
+ })
87
+
88
+ describe('liveOnlyProps — silent', () => {
89
+ test('a function-typed prop declared but never read by client code is not classified', () => {
90
+ // `usedProps` filtering already excludes it upstream (never even
91
+ // reaches the client init), so it can't land in liveOnlyProps either.
92
+ const analysis = analyze(`
93
+ 'use client'
94
+ export function Display({ value, label }: { value: () => number; label: string }) {
95
+ return <button onClick={() => console.log(label)}>{label}</button>
96
+ }
97
+ `)
98
+ expect(analysis.usedProps).not.toContain('value')
99
+ expect(analysis.liveOnlyProps).not.toHaveProperty('value')
100
+ })
101
+
102
+ test('onClick-shaped (event-handler-convention) prop is excluded even though it is function-typed', () => {
103
+ const analysis = analyze(`
104
+ interface Props { onClick: () => void }
105
+ export function Clickable({ onClick }: Props) {
106
+ return <div onClick={onClick}>Click me</div>
107
+ }
108
+ `)
109
+ expect(analysis.liveOnlyProps).not.toHaveProperty('onClick')
110
+ })
111
+
112
+ test('__-prefixed internal prop is excluded even though it is function-typed', () => {
113
+ const analysis = analyze(`
114
+ 'use client'
115
+ export function Internal({ __cb }: { __cb: () => void }) {
116
+ return <button onClick={() => __cb()}>go</button>
117
+ }
118
+ `)
119
+ expect(analysis.liveOnlyProps).not.toHaveProperty('__cb')
120
+ })
121
+
122
+ test('a non-function-typed prop (number) is never in liveOnlyProps', () => {
123
+ const analysis = analyze(`
124
+ 'use client'
125
+ export function Counter({ value }: { value: number }) {
126
+ return <button onClick={() => console.log(value)}>{value}</button>
127
+ }
128
+ `)
129
+ expect(analysis.usedProps).toContain('value')
130
+ expect(analysis.liveOnlyProps).not.toHaveProperty('value')
131
+ })
132
+
133
+ test('an ALIASED function type is a known conservative miss, not a classification', () => {
134
+ // `typeNodeToTypeInfo` lowers a named type reference to
135
+ // `{ kind: 'interface', raw: 'Filter' }` with no member walk, so the
136
+ // function shape behind the alias is invisible here and the prop keeps
137
+ // the pre-Move-C silent drop. BF049 has the same blind spot for aliased
138
+ // rich types. Pinned so a future alias-resolution change is a deliberate
139
+ // flip of this expectation, not an accident.
140
+ const analysis = analyze(`
141
+ 'use client'
142
+ type Filter = (s: string) => boolean
143
+ export function Display({ filter }: { filter: Filter }) {
144
+ return <button onClick={() => console.log(filter('x'))}>go</button>
145
+ }
146
+ `)
147
+ expect(analysis.usedProps).toContain('filter')
148
+ expect(analysis.liveOnlyProps).not.toHaveProperty('filter')
149
+ })
150
+
151
+ test('a static (non-client) component has no clientAnalysis needs at all — liveOnlyProps is empty', () => {
152
+ const analysis = analyze(`
153
+ export function Static({ value }: { value: () => number }) {
154
+ return <span>static</span>
155
+ }
156
+ `)
157
+ expect(analysis.needsInit).toBe(false)
158
+ expect(analysis.liveOnlyProps).toEqual({})
159
+ })
160
+ })
@@ -212,7 +212,7 @@ describe('PropReference extraction', () => {
212
212
  })
213
213
 
214
214
  describe('ClientJS generation with semantic prop refs', () => {
215
- test('destructured props are captured once, NOT transformed in createEffect', () => {
215
+ test('destructured props compile to a live _p.open read, no captured-once local', () => {
216
216
  const source = `
217
217
  'use client'
218
218
 
@@ -231,10 +231,10 @@ describe('ClientJS generation with semantic prop refs', () => {
231
231
 
232
232
  const clientJs = result.files.find((f) => f.type === 'clientJs')
233
233
  expect(clientJs).toBeDefined()
234
- // Should have capture: const open = props.open
235
- expect(clientJs?.content).toContain('const open = _p.open')
236
- // createEffect should use 'open' directly, NOT 'props.open'
237
- // (destructured props are static, captured once)
234
+ // No captured-once local: the conditional reads `_p.open` live.
235
+ expect(clientJs?.content).not.toContain('const open = ')
236
+ expect(clientJs?.content).toContain('insert(__scope, \'s0\', () => _p.open,')
237
+ // Never a stale `props.` prefix either.
238
238
  expect(clientJs?.content).not.toMatch(/insert\([^)]*props\.open/)
239
239
  })
240
240
 
@@ -287,7 +287,7 @@ describe('ClientJS generation with semantic prop refs', () => {
287
287
  expect(clientJs?.content).not.toContain('window.props.open')
288
288
  })
289
289
 
290
- test('destructured props with default value are captured once', () => {
290
+ test('destructured props with default value read live, with the default applied at every read', () => {
291
291
  const source = `
292
292
  'use client'
293
293
 
@@ -306,8 +306,10 @@ describe('ClientJS generation with semantic prop refs', () => {
306
306
 
307
307
  const clientJs = result.files.find((f) => f.type === 'clientJs')
308
308
  expect(clientJs).toBeDefined()
309
- // Should capture with default value: const open = props.open ?? false
310
- expect(clientJs?.content).toMatch(/const open = _p\.open \?\? false/)
309
+ // No captured-once local — the live read carries the default at the
310
+ // read site itself: `(_p.open ?? false)`.
311
+ expect(clientJs?.content).not.toContain('const open = ')
312
+ expect(clientJs?.content).toMatch(/\(_p\.open \?\? false\)/)
311
313
  })
312
314
  })
313
315
 
@@ -319,8 +321,13 @@ describe('ClientJS generation with semantic prop refs', () => {
319
321
  // reachable), but was never wired to `ctx.clientOnlyElements` either, so no
320
322
  // edge of ANY kind reached `neededProps` and `emitPropsExtraction` had no
321
323
  // evidence the prop was used at all.
324
+ //
325
+ // The bug class is now structurally impossible for a destructured prop:
326
+ // `rewriteDestructuredPropReads` walks the joined init body and consults
327
+ // neither `neededProps` nor the reference graph, so there is no edge left
328
+ // for an emitter to forget to wire up.
322
329
  describe('Issue #2634 regression', () => {
323
- test('a destructured prop used only inside /* @client */ is extracted from _p', () => {
330
+ test('a destructured prop used only inside /* @client */ reads _p.label directly (no unbound identifier)', () => {
324
331
  const source = `
325
332
  interface Props {
326
333
  label: string
@@ -336,11 +343,11 @@ describe('Issue #2634 regression', () => {
336
343
  expect(result.errors).toHaveLength(0)
337
344
  const clientJs = result.files.find((f) => f.type === 'clientJs')
338
345
  expect(clientJs).toBeDefined()
339
- // The prop must be bound before the createEffect body reads it.
340
- expect(clientJs?.content).toContain('const label = _p.label')
341
- // A bare `label` reference with no preceding binding is exactly the
342
- // unbound-identifier shape that threw ReferenceError at hydrate.
343
- expect(clientJs?.content).toMatch(/const label = _p\.label[\s\S]*label\.toUpperCase\(\)/)
346
+ // A bare, unbound `label` is the shape that threw ReferenceError at
347
+ // hydrate pre-#2634; the live `_p.label` read is what replaces both
348
+ // that bug and its original captured-once fix.
349
+ expect(clientJs?.content).not.toContain('const label = ')
350
+ expect(clientJs?.content).toContain('_p.label.toUpperCase()')
344
351
  })
345
352
 
346
353
  test('a props-object member used only inside /* @client */ needs no extraction (already _p.x)', () => {
@@ -362,7 +369,7 @@ describe('Issue #2634 regression', () => {
362
369
  expect(clientJs?.content).toContain('_p.label.toUpperCase()')
363
370
  })
364
371
 
365
- test('a prop used both in a normal reactive position AND inside /* @client */ is still extracted once', () => {
372
+ test('a prop used both in a normal reactive position AND inside /* @client */ reads _p.label live at BOTH sites (no extraction)', () => {
366
373
  const source = `
367
374
  interface Props {
368
375
  label: string
@@ -378,8 +385,10 @@ describe('Issue #2634 regression', () => {
378
385
  expect(result.errors).toHaveLength(0)
379
386
  const clientJs = result.files.find((f) => f.type === 'clientJs')
380
387
  expect(clientJs).toBeDefined()
381
- const matches = clientJs?.content.match(/const label = _p\.label/g) ?? []
382
- expect(matches).toHaveLength(1)
388
+ // Each of the two reference sites reads `_p.label` live, independently.
389
+ expect(clientJs?.content).not.toContain('const label = ')
390
+ const matches = clientJs?.content.match(/_p\.label/g) ?? []
391
+ expect(matches.length).toBeGreaterThanOrEqual(2)
383
392
  })
384
393
  })
385
394
 
@@ -1,285 +1,16 @@
1
1
  /**
2
- * Props Destructuring Warning Tests
2
+ * Destructured-Props Type Resolution Tests
3
3
  *
4
- * Tests for BF043: Props destructuring in function parameters breaks reactivity.
5
- * BF043 is only emitted for stateful components (with signals/memos/effects).
6
- * Stateless components can safely destructure props.
4
+ * Pins that a destructured prop's declared TYPE resolves from the param's
5
+ * type annotation (#2150). The reactivity half of this file is gone: BF043
6
+ * ("props destructuring breaks reactivity") is retired, and the live-read
7
+ * rewrite that replaced it is covered by `destructured-props-live.test.ts`.
7
8
  */
8
9
 
9
10
  import { describe, test, expect } from 'bun:test'
10
11
  import { analyzeComponent } from '../analyzer'
11
- import { ErrorCodes } from '../errors'
12
12
 
13
- describe('Props Destructuring Warning (BF043)', () => {
14
- test('warns on destructured props in stateful component', () => {
15
- const source = `
16
- 'use client'
17
- import { createSignal } from '@barefootjs/client'
18
-
19
- interface Props {
20
- checked: boolean
21
- }
22
-
23
- export function Component({ checked }: Props) {
24
- const [count, setCount] = createSignal(0)
25
- return <div>{checked}{count()}</div>
26
- }
27
- `
28
-
29
- const ctx = analyzeComponent(source, 'Component.tsx')
30
-
31
- const propsWarnings = ctx.errors.filter((e) => e.code === ErrorCodes.PROPS_DESTRUCTURING)
32
- expect(propsWarnings).toHaveLength(1)
33
- expect(propsWarnings[0].severity).toBe('warning')
34
- expect(propsWarnings[0].suggestion?.message).toContain('props object')
35
- })
36
-
37
- test('no warning on destructured props in stateless component', () => {
38
- const source = `
39
- interface Props {
40
- checked: boolean
41
- }
42
-
43
- export function Component({ checked }: Props) {
44
- return <div>{checked}</div>
45
- }
46
- `
47
-
48
- const ctx = analyzeComponent(source, 'Component.tsx')
49
-
50
- const propsWarnings = ctx.errors.filter((e) => e.code === ErrorCodes.PROPS_DESTRUCTURING)
51
- expect(propsWarnings).toHaveLength(0)
52
- })
53
-
54
- test('warns on rest props in stateful component', () => {
55
- const source = `
56
- 'use client'
57
- import { createSignal } from '@barefootjs/client'
58
-
59
- interface Props {
60
- checked: boolean
61
- }
62
-
63
- export function Component({ ...props }: Props) {
64
- const [count, setCount] = createSignal(0)
65
- return <div>{props.checked}{count()}</div>
66
- }
67
- `
68
-
69
- const ctx = analyzeComponent(source, 'Component.tsx')
70
-
71
- const propsWarnings = ctx.errors.filter((e) => e.code === ErrorCodes.PROPS_DESTRUCTURING)
72
- expect(propsWarnings).toHaveLength(1)
73
- })
74
-
75
- test('warns on partial destructuring with rest props in stateful component', () => {
76
- const source = `
77
- 'use client'
78
- import { createSignal } from '@barefootjs/client'
79
-
80
- interface Props {
81
- onClick: () => void
82
- checked: boolean
83
- }
84
-
85
- export function Component({ onClick, ...rest }: Props) {
86
- const [count, setCount] = createSignal(0)
87
- return <div onClick={onClick}>{rest.checked}{count()}</div>
88
- }
89
- `
90
-
91
- const ctx = analyzeComponent(source, 'Component.tsx')
92
-
93
- const propsWarnings = ctx.errors.filter((e) => e.code === ErrorCodes.PROPS_DESTRUCTURING)
94
- expect(propsWarnings).toHaveLength(1)
95
- })
96
-
97
- test('no warning with @bf-ignore props-destructuring', () => {
98
- const source = `
99
- 'use client'
100
- import { createSignal } from '@barefootjs/client'
101
-
102
- interface Props {
103
- checked: boolean
104
- }
105
-
106
- // @bf-ignore props-destructuring
107
- export function Component({ checked }: Props) {
108
- const [count, setCount] = createSignal(0)
109
- return <div>{checked}{count()}</div>
110
- }
111
- `
112
-
113
- const ctx = analyzeComponent(source, 'Component.tsx')
114
-
115
- const propsWarnings = ctx.errors.filter((e) => e.code === ErrorCodes.PROPS_DESTRUCTURING)
116
- expect(propsWarnings).toHaveLength(0)
117
- })
118
-
119
- test('no warning when props object is used', () => {
120
- const source = `
121
- 'use client'
122
- import { createSignal } from '@barefootjs/client'
123
-
124
- interface Props {
125
- checked: boolean
126
- }
127
-
128
- export function Component(props: Props) {
129
- const [count, setCount] = createSignal(0)
130
- return <div>{props.checked}{count()}</div>
131
- }
132
- `
133
-
134
- const ctx = analyzeComponent(source, 'Component.tsx')
135
-
136
- const propsWarnings = ctx.errors.filter((e) => e.code === ErrorCodes.PROPS_DESTRUCTURING)
137
- expect(propsWarnings).toHaveLength(0)
138
- })
139
-
140
- test('no warning when no props parameter', () => {
141
- const source = `
142
- 'use client'
143
-
144
- export function Component() {
145
- return <div>Hello</div>
146
- }
147
- `
148
-
149
- const ctx = analyzeComponent(source, 'Component.tsx')
150
-
151
- const propsWarnings = ctx.errors.filter((e) => e.code === ErrorCodes.PROPS_DESTRUCTURING)
152
- expect(propsWarnings).toHaveLength(0)
153
- })
154
-
155
- test('warns on arrow function component with destructuring when stateful', () => {
156
- const source = `
157
- 'use client'
158
- import { createSignal } from '@barefootjs/client'
159
-
160
- interface Props {
161
- checked: boolean
162
- }
163
-
164
- export const Component = ({ checked }: Props) => {
165
- const [count, setCount] = createSignal(0)
166
- return <div>{checked}{count()}</div>
167
- }
168
- `
169
-
170
- const ctx = analyzeComponent(source, 'Component.tsx')
171
-
172
- const propsWarnings = ctx.errors.filter((e) => e.code === ErrorCodes.PROPS_DESTRUCTURING)
173
- expect(propsWarnings).toHaveLength(1)
174
- })
175
-
176
- test('no warning on arrow function with @bf-ignore', () => {
177
- const source = `
178
- 'use client'
179
- import { createSignal } from '@barefootjs/client'
180
-
181
- interface Props {
182
- checked: boolean
183
- }
184
-
185
- // @bf-ignore props-destructuring
186
- export const Component = ({ checked }: Props) => {
187
- const [count, setCount] = createSignal(0)
188
- return <div>{checked}{count()}</div>
189
- }
190
- `
191
-
192
- const ctx = analyzeComponent(source, 'Component.tsx')
193
-
194
- const propsWarnings = ctx.errors.filter((e) => e.code === ErrorCodes.PROPS_DESTRUCTURING)
195
- expect(propsWarnings).toHaveLength(0)
196
- })
197
-
198
- test('warns on multiple destructured props in stateful component', () => {
199
- const source = `
200
- 'use client'
201
- import { createSignal } from '@barefootjs/client'
202
-
203
- interface Props {
204
- checked: boolean
205
- onChange: () => void
206
- label: string
207
- }
208
-
209
- export function Component({ checked, onChange, label }: Props) {
210
- const [count, setCount] = createSignal(0)
211
- return <div onClick={onChange}>{label}: {checked}{count()}</div>
212
- }
213
- `
214
-
215
- const ctx = analyzeComponent(source, 'Component.tsx')
216
-
217
- const propsWarnings = ctx.errors.filter((e) => e.code === ErrorCodes.PROPS_DESTRUCTURING)
218
- expect(propsWarnings).toHaveLength(1) // One warning per component, not per prop
219
- })
220
-
221
- test('warns when component has memos (stateful)', () => {
222
- const source = `
223
- 'use client'
224
- import { createMemo } from '@barefootjs/client'
225
-
226
- interface Props {
227
- value: number
228
- }
229
-
230
- export function Component({ value }: Props) {
231
- const doubled = createMemo(() => value * 2)
232
- return <div>{doubled()}</div>
233
- }
234
- `
235
-
236
- const ctx = analyzeComponent(source, 'Component.tsx')
237
-
238
- const propsWarnings = ctx.errors.filter((e) => e.code === ErrorCodes.PROPS_DESTRUCTURING)
239
- expect(propsWarnings).toHaveLength(1)
240
- })
241
-
242
- test('warns when component has effects (stateful)', () => {
243
- const source = `
244
- 'use client'
245
- import { createEffect } from '@barefootjs/client'
246
-
247
- interface Props {
248
- value: number
249
- }
250
-
251
- export function Component({ value }: Props) {
252
- createEffect(() => console.log(value))
253
- return <div>{value}</div>
254
- }
255
- `
256
-
257
- const ctx = analyzeComponent(source, 'Component.tsx')
258
-
259
- const propsWarnings = ctx.errors.filter((e) => e.code === ErrorCodes.PROPS_DESTRUCTURING)
260
- expect(propsWarnings).toHaveLength(1)
261
- })
262
-
263
- test('no warning on stateless arrow function with destructuring', () => {
264
- const source = `
265
- interface Props {
266
- className: string
267
- variant: string
268
- }
269
-
270
- export const Button = ({ className, variant }: Props) => {
271
- return <button className={className}>{variant}</button>
272
- }
273
- `
274
-
275
- const ctx = analyzeComponent(source, 'Button.tsx')
276
-
277
- const propsWarnings = ctx.errors.filter((e) => e.code === ErrorCodes.PROPS_DESTRUCTURING)
278
- expect(propsWarnings).toHaveLength(0)
279
- })
280
- })
281
-
282
- describe('Destructured props keep their declared types (BF043 fixture #2150)', () => {
13
+ describe('Destructured props keep their declared types (#2150)', () => {
283
14
  const typeOf = (ctx: ReturnType<typeof analyzeComponent>, name: string) =>
284
15
  ctx.propsParams.find((p) => p.name === name)?.type
285
16
 
@@ -52,9 +52,12 @@ export { Wrap }
52
52
  expect(js).not.toContain('const children = _p.children')
53
53
  })
54
54
 
55
- test('props the init genuinely reads keep their extraction', () => {
56
- // `config` is read by a handler, `items` by an init-scope constant —
57
- // both local bindings are real and must survive the prune.
55
+ test('props the init genuinely reads compile to live `_p.x` reads, with no extraction to prune at all', () => {
56
+ // `config` is read by a handler, `items` by an init-scope constant.
57
+ // Neither produces an extraction for this pruner to decide about any
58
+ // more: both read live, with the same `?? {}` / `?? []` fallback at
59
+ // each read site. Only `children` (the test above) still goes through
60
+ // the pruner.
58
61
  const js = clientJsOf(
59
62
  `"use client"
60
63
 
@@ -72,7 +75,10 @@ export { Widget }
72
75
  `,
73
76
  '/virtual/widget.tsx',
74
77
  )
75
- expect(js).toContain('const config = _p.config ?? {}')
76
- expect(js).toContain('const items = _p.items ?? []')
78
+ expect(js).not.toContain('const config = ')
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]')
77
83
  })
78
84
  })
@@ -327,6 +327,11 @@ describe('Signal Getter Not Called (BF044)', () => {
327
327
  ['component prop, object literal member', '<Child value={{ x: count }} />'],
328
328
  ['component prop, ternary', '<Child value={count ? 1 : 2} />'],
329
329
  ['component prop, call argument', '<Child value={String(count)} />'],
330
+ // #2760: a bare getter passed DIRECTLY to a component prop is the
331
+ // same idiom as the object-literal-wrapped form above, not a
332
+ // forgotten `()` — the two forms are one decision, not an
333
+ // inconsistency to resolve by tightening the direct one.
334
+ ['component prop, bare getter', '<Child value={count} />'],
330
335
  ])('%s', (_label, body) => {
331
336
  expect(bf044Of(body)).toHaveLength(0)
332
337
  })