@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
@@ -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
  })
@@ -352,6 +352,89 @@ describe('extractSsrDefaults', () => {
352
352
  expect(defaults?.text).toEqual({ propName: 'text', value: null })
353
353
  })
354
354
 
355
+ test('bare-props-form BODY-destructured default (#2943) seeds the evaluated default, not null', () => {
356
+ // Before #2943, `extractPropsFromTypeMembers` built `propsParams` from
357
+ // the TYPE annotation alone, with no notion of a body destructure's
358
+ // own default — this entry seeded `value: null` regardless, and every
359
+ // non-Hono template adapter's presence-guard classification omitted
360
+ // the attribute entirely instead of falling back to `'none'`. The
361
+ // analyzer now overlays the default directly onto `propsParams`
362
+ // (`collectConstant`), so this is the SAME code path as the
363
+ // parameter-destructured "destructured prop defaults" test above —
364
+ // just reached through a body destructure instead.
365
+ const metadata = metadataFor(`
366
+ function Foo(props: { label?: string }) {
367
+ const { label = 'none' } = props
368
+ return <div data-label={label} />
369
+ }
370
+ `)
371
+ const defaults = extractSsrDefaults(metadata)
372
+ expect(defaults?.label).toEqual({ propName: 'label', value: 'none' })
373
+ })
374
+
375
+ test('bare-props-form BODY-destructured RENAMED default (#2943): two entries, each correctly classified', () => {
376
+ // `const { label: text = 'none' } = props` — `label` remains a real,
377
+ // separately-classified binding (no default of its own: a bare
378
+ // `props.label` read elsewhere in the same component still needs its
379
+ // own presence guard / stash entry), and `text` gets its OWN entry
380
+ // with `propName: 'label'` (the caller-facing key) and the evaluated
381
+ // default. `deriveStashFromDefaults` then seeds `text` from the
382
+ // caller's `label` when supplied, else `'none'` — never from `text`
383
+ // itself (`props` has no `text` key at all).
384
+ const metadata = metadataFor(`
385
+ function Foo(props: { label?: string }) {
386
+ const { label: text = 'none' } = props
387
+ return <div data-label={text} />
388
+ }
389
+ `)
390
+ const defaults = extractSsrDefaults(metadata)
391
+ expect(defaults?.label).toEqual({ propName: 'label', value: null })
392
+ expect(defaults?.text).toEqual({ propName: 'label', value: 'none' })
393
+
394
+ expect(deriveStashFromDefaults(defaults!, { label: 'named' })).toMatchObject({ text: 'named' })
395
+ expect(deriveStashFromDefaults(defaults!, {})).toMatchObject({ text: 'none' })
396
+ })
397
+
398
+ test('bare-props-form body-destructure rename (#2788) seeds the SSR stash under the LOCAL name', () => {
399
+ // `function Foo(props: Props) { const { children: kids } = props }` —
400
+ // propsParams here comes from the TYPE annotation and has no notion of
401
+ // the body-level rename, so the template-stash reads a LOCAL `kids`
402
+ // that pass-1 seeding would otherwise never populate. The safety-net
403
+ // loop in `extractSsrDefaults` (backed by `resolveBodyDestructuredPropAliases`)
404
+ // exists specifically to also seed the entry under `kids`.
405
+ const metadata = metadataFor(`
406
+ function Foo(props: { children?: string }) {
407
+ const { children: kids } = props
408
+ return <span>{kids}</span>
409
+ }
410
+ `)
411
+
412
+ const defaults = extractSsrDefaults(metadata)
413
+ expect(defaults?.children).toEqual({ propName: 'children', value: null })
414
+ expect(defaults?.kids).toEqual(defaults?.children)
415
+ })
416
+
417
+ // Pullfrog review (PR #2941): `resolveBodyDestructuredPropAliases` is now
418
+ // a filtered view over `resolveBodyPropAliases`, which excludes `let`
419
+ // bindings and mutated locals — a restriction that's correct for the
420
+ // LIVE client-JS rewrite (`rewriteBodyAliasReads`) but has no bearing on
421
+ // this SSR-stash safety net, which only needs the declaration-time
422
+ // local↔caller-key mapping. Without `requireLiveRewriteSafe: false`
423
+ // threaded through, a `let`-declared rename would silently lose its
424
+ // stash entry here — a reintroduction of #2788 for that one shape.
425
+ test('bare-props-form body-destructure rename via `let` (#2788 regression guard) still seeds the SSR stash', () => {
426
+ const metadata = metadataFor(`
427
+ function Foo(props: { children?: string }) {
428
+ let { children: kids } = props
429
+ return <span>{kids}</span>
430
+ }
431
+ `)
432
+
433
+ const defaults = extractSsrDefaults(metadata)
434
+ expect(defaults?.children).toEqual({ propName: 'children', value: null })
435
+ expect(defaults?.kids).toEqual(defaults?.children)
436
+ })
437
+
355
438
  test('memo derived from a signal evaluates through the chain', () => {
356
439
  const metadata = metadataFor(`
357
440
  'use client'
@@ -37,9 +37,16 @@ describe('Shadow guards: bare names that shadow props are NOT rewritten to _p.X'
37
37
  expect(initBody).not.toMatch(/_p\.count\(\)/)
38
38
  })
39
39
 
40
- test('earlier local const with default shadowing prop', () => {
41
- // `label` is a derived local. Even though props has a `label` field,
42
- // the bare reference inside subsequent locals resolves to the local.
40
+ // #2934: `label` here is a PURE alias of the `label` prop (the analyzer's
41
+ // IR can't distinguish `const label = props.label ?? 'fallback'` from a
42
+ // destructure default), not a genuinely distinct local shadowing an
43
+ // unrelated prop of the same name — so it is NOT a shadow-guard case
44
+ // after all. `resolveBodyPropAliases` now recognizes it, deletes its own
45
+ // extraction, and rewrites every reference (including from `upper`'s own
46
+ // initializer) to a live `_p.label` read, same as the parameter-
47
+ // destructured form. `upper` itself stays an ordinary once-evaluated
48
+ // local — `.toUpperCase()` is a real computation, not a passthrough.
49
+ test('a plain member-access prop alias is rewritten live, including from a dependent local', () => {
43
50
  const { initBody, errors } = compile(`
44
51
  'use client'
45
52
 
@@ -53,8 +60,8 @@ describe('Shadow guards: bare names that shadow props are NOT rewritten to _p.X'
53
60
  `)
54
61
 
55
62
  expect(errors).toEqual([])
56
- expect(initBody).toMatch(/upper\s*=\s*label\.toUpperCase\(\)/)
57
- expect(initBody).not.toMatch(/_p\.label\.toUpperCase/)
63
+ expect(initBody).not.toMatch(/const\s+label\s*=/)
64
+ expect(initBody).toMatch(/upper\s*=\s*\(_p\.label\s*\?\?\s*'fallback'\)\.toUpperCase\(\)/)
58
65
  })
59
66
 
60
67
  test('nested arrow param shadowing prop name', () => {
@@ -3,9 +3,10 @@ import { parseExpression } from '../expression-parser'
3
3
  import { evaluateStaticLiteral, isFullyStaticLiteral, resolveStaticLoopSource } from '../static-literal'
4
4
  import type { ConstantInfo } from '../types'
5
5
 
6
- // #2208: a function-scope local const whose initializer is fully known at
7
- // compile time (no prop/signal/function-call dependency) should bind as a
8
- // loop source the same way a module-scope const already does.
6
+ // #2208: a local const whose initializer is fully known at compile time (no
7
+ // prop/signal/function-call dependency) should bind as a loop source the
8
+ // same way an inline array literal does — module-scope and function-scope
9
+ // alike (#2946).
9
10
  describe('evaluateStaticLiteral (#2208)', () => {
10
11
  test('scalars', () => {
11
12
  expect(evaluateStaticLiteral(parseExpression("'Alpha'"))).toEqual({ value: 'Alpha' })
@@ -97,11 +98,45 @@ describe('resolveStaticLoopSource (#2208)', () => {
97
98
  expect(resolveStaticLoopSource(parseExpression('items'), locals)).toEqual([{ label: 'Alpha' }])
98
99
  })
99
100
 
100
- test('a MODULE-scope const is excluded (handled by the existing seeding path instead)', () => {
101
+ test('a MODULE-scope const with a static initializer resolves exactly like a function-scope one (#2946)', () => {
101
102
  const locals = [constant({ name: 'items', parsed: parseExpression("[{ label: 'Alpha' }]"), isModule: true })]
103
+ expect(resolveStaticLoopSource(parseExpression('items'), locals)).toEqual([{ label: 'Alpha' }])
104
+ })
105
+
106
+ test('a MODULE-scope const whose initializer is runtime-computed still refuses (#2946)', () => {
107
+ const locals = [constant({ name: 'items', parsed: parseExpression('buildItems()'), isModule: true })]
102
108
  expect(resolveStaticLoopSource(parseExpression('items'), locals)).toBeNull()
103
109
  })
104
110
 
111
+ test('a MODULE-scope const shadowed by an enclosing loop param is excluded via isNameShadowed (#2946)', () => {
112
+ const locals = [constant({ name: 'items', parsed: parseExpression("[{ label: 'Alpha' }]"), isModule: true })]
113
+ const result = resolveStaticLoopSource(parseExpression('items'), locals, {
114
+ isNameShadowed: name => name === 'items',
115
+ })
116
+ expect(result).toBeNull()
117
+ })
118
+
119
+ test('a const mutated after its declaration (#2910) refuses regardless of scope', () => {
120
+ const moduleLocals = [
121
+ constant({
122
+ name: 'items',
123
+ parsed: parseExpression("[{ label: 'Alpha' }]"),
124
+ isModule: true,
125
+ mutatedAfterDeclaration: true,
126
+ }),
127
+ ]
128
+ expect(resolveStaticLoopSource(parseExpression('items'), moduleLocals)).toBeNull()
129
+
130
+ const functionLocals = [
131
+ constant({
132
+ name: 'items',
133
+ parsed: parseExpression("[{ label: 'Alpha' }]"),
134
+ mutatedAfterDeclaration: true,
135
+ }),
136
+ ]
137
+ expect(resolveStaticLoopSource(parseExpression('items'), functionLocals)).toBeNull()
138
+ })
139
+
105
140
  test('a runtime-computed local const (#2069) still refuses', () => {
106
141
  const locals = [constant({ name: 'entries', parsed: parseExpression('Object.entries(props.tags)') })]
107
142
  expect(resolveStaticLoopSource(parseExpression('entries'), locals)).toBeNull()
@@ -29,12 +29,13 @@ import type { CallbackBodyAcceptor } from './adapters/interface.ts'
29
29
  import { nodeContainsJsx } from './reactivity-checker.ts'
30
30
 
31
31
  /**
32
- * Deferred info for BF043 (props destructuring warning).
33
- * Recorded during extractProps(), emitted only for stateful components in validateContext().
32
+ * The props destructuring pattern's own source location. Carries no
33
+ * diagnostic of its own — it is the more precise location other
34
+ * props-parameter diagnostics point at instead of the component root (see
35
+ * `compiler.ts`'s `checkRichTypePropSerialization`).
34
36
  */
35
37
  export interface PropsDestructuringInfo {
36
38
  loc: SourceLocation
37
- hasIgnoreDirective: boolean
38
39
  }
39
40
 
40
41
  /**
@@ -182,7 +183,7 @@ export interface AnalyzerContext {
182
183
  restPropsName: string | null
183
184
  /** Keys that can be statically expanded from rest props (closed type) */
184
185
  restPropsExpandedKeys: string[]
185
- /** Deferred BF043 info; emitted only for stateful components in validateContext() */
186
+ /** Set when the props parameter is a destructuring pattern — see `PropsDestructuringInfo`. */
186
187
  propsDestructuring: PropsDestructuringInfo | null
187
188
 
188
189
  // JSX return — widened to any `ts.Expression` so the Phase 1 dispatcher
@@ -322,9 +323,9 @@ export function createAnalyzerContext(
322
323
  // to compiles with no `error`-severity diagnostic: a compile that
323
324
  // already refused loudly may take degraded fallback paths whose
324
325
  // artifacts are gated by the error — the invariant this trips on is
325
- // the SILENT leak. A `warning` (e.g. BF043 props-destructuring) does
326
- // not gate anything, so it must not silently disarm this assertion too
327
- // (#2867) — only `error` severity does.
326
+ // the SILENT leak. A `warning`-severity diagnostic does not gate
327
+ // anything, so it must not silently disarm this assertion too (#2867)
328
+ // — only `error` severity does.
328
329
  if (
329
330
  process.env.BF_ASSERT_NO_JSX_IN_GETJS === '1' &&
330
331
  !this.errors.some((e) => e.severity === 'error') &&