@barefootjs/jsx 0.39.0 → 0.39.2

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 (74) hide show
  1. package/dist/adapters/interface.d.ts +19 -0
  2. package/dist/adapters/interface.d.ts.map +1 -1
  3. package/dist/adapters/jsx-adapter.d.ts.map +1 -1
  4. package/dist/adapters/parsed-expr-emitter.d.ts +2 -2
  5. package/dist/adapters/parsed-expr-emitter.d.ts.map +1 -1
  6. package/dist/analyzer.d.ts +19 -0
  7. package/dist/analyzer.d.ts.map +1 -1
  8. package/dist/compiler.d.ts.map +1 -1
  9. package/dist/debug.d.ts.map +1 -1
  10. package/dist/html-types.d.ts +5 -0
  11. package/dist/html-types.d.ts.map +1 -1
  12. package/dist/index.d.ts +2 -0
  13. package/dist/index.d.ts.map +1 -1
  14. package/dist/index.js +1455 -1139
  15. package/dist/ir-to-client-js/collect-elements.d.ts +17 -1
  16. package/dist/ir-to-client-js/collect-elements.d.ts.map +1 -1
  17. package/dist/ir-to-client-js/reactivity.d.ts +10 -2
  18. package/dist/ir-to-client-js/reactivity.d.ts.map +1 -1
  19. package/dist/ir-to-client-js/safe-html.d.ts +1 -1
  20. package/dist/ir-to-client-js/safe-html.d.ts.map +1 -1
  21. package/dist/ir-to-client-js/utils.d.ts +11 -7
  22. package/dist/ir-to-client-js/utils.d.ts.map +1 -1
  23. package/dist/jsx-to-ir.d.ts.map +1 -1
  24. package/dist/literal-member-index.d.ts +6 -0
  25. package/dist/literal-member-index.d.ts.map +1 -0
  26. package/dist/scope/binding-scope.d.ts +11 -0
  27. package/dist/scope/binding-scope.d.ts.map +1 -1
  28. package/dist/signal-prop-name-collision.d.ts +20 -0
  29. package/dist/signal-prop-name-collision.d.ts.map +1 -0
  30. package/dist/ssr-defaults.d.ts.map +1 -1
  31. package/dist/ssr-seed-plan.d.ts +3 -2
  32. package/dist/ssr-seed-plan.d.ts.map +1 -1
  33. package/dist/types.d.ts +44 -0
  34. package/dist/types.d.ts.map +1 -1
  35. package/package.json +2 -2
  36. package/src/__tests__/__snapshots__/doc-examples.test.ts.snap +4 -4
  37. package/src/__tests__/adapter-output.test.ts +142 -0
  38. package/src/__tests__/binding-scope.test.ts +27 -0
  39. package/src/__tests__/client-template-escape-soundness.test.ts +17 -0
  40. package/src/__tests__/conditional-nested-loop-bindings.test.ts +41 -0
  41. package/src/__tests__/create-mutation.test.ts +30 -0
  42. package/src/__tests__/create-query.test.ts +52 -0
  43. package/src/__tests__/debug.test.ts +83 -0
  44. package/src/__tests__/destructured-from-props-localconst-value.test.ts +3 -2
  45. package/src/__tests__/ir-fragment-transparency.test.ts +23 -0
  46. package/src/__tests__/issue-3240-nested-static-map-event-delegation.test.ts +245 -0
  47. package/src/__tests__/jsx-text-linebreak-whitespace.test.ts +80 -0
  48. package/src/__tests__/literal-member-index.test.ts +14 -0
  49. package/src/__tests__/loop-param-accessor-key-member-safety.test.ts +445 -0
  50. package/src/__tests__/signal-prop-name-collision.test.ts +171 -0
  51. package/src/__tests__/ssr-defaults.test.ts +6 -7
  52. package/src/__tests__/ssr-seed-plan.test.ts +23 -0
  53. package/src/__tests__/staged-ir/02-shadow-guards.test.ts +1 -1
  54. package/src/__tests__/staged-ir/08-relocate-unit.test.ts +6 -3
  55. package/src/adapters/interface.ts +19 -0
  56. package/src/adapters/jsx-adapter.ts +30 -20
  57. package/src/adapters/parsed-expr-emitter.ts +3 -3
  58. package/src/analyzer.ts +45 -11
  59. package/src/compiler.ts +78 -46
  60. package/src/debug.ts +34 -2
  61. package/src/html-types.ts +14 -0
  62. package/src/index.ts +2 -0
  63. package/src/ir-to-client-js/collect-elements.ts +72 -13
  64. package/src/ir-to-client-js/control-flow/stringify/event-delegation.ts +112 -3
  65. package/src/ir-to-client-js/reactivity.ts +31 -1
  66. package/src/ir-to-client-js/safe-html.ts +19 -6
  67. package/src/ir-to-client-js/utils.ts +130 -15
  68. package/src/jsx-to-ir.ts +89 -14
  69. package/src/literal-member-index.ts +12 -0
  70. package/src/scope/binding-scope.ts +31 -1
  71. package/src/signal-prop-name-collision.ts +164 -0
  72. package/src/ssr-defaults.ts +13 -5
  73. package/src/ssr-seed-plan.ts +26 -3
  74. package/src/types.ts +47 -0
@@ -9,10 +9,65 @@ import { describe, test, expect } from 'bun:test'
9
9
  import { compileJSX } from '../compiler'
10
10
  import { TestAdapter } from '../adapters/test-adapter'
11
11
  import { HonoAdapter } from '../../../../packages/adapter-hono/src/adapter/hono-adapter'
12
+ import { BaseAdapter } from '../adapters/interface'
13
+ import type { AdapterOutput, TemplateSections } from '../adapters/interface'
12
14
  import { resolve, dirname } from 'node:path'
13
15
 
14
16
  const adapter = new TestAdapter()
15
17
 
18
+ // Minimal stand-in for `@barefootjs/client`'s `CSRAdapter` — same shape
19
+ // (empty `generate()`, `emitsTemplates: false`) without pulling in the
20
+ // `@barefootjs/client` package, which `packages/jsx` does not (and must
21
+ // not) depend on. See `CSRAdapter`'s docstring for the full contract this
22
+ // mirrors.
23
+ const EMPTY_SECTIONS: TemplateSections = Object.freeze({
24
+ imports: '',
25
+ types: '',
26
+ component: '',
27
+ defaultExport: '',
28
+ })
29
+ const EMPTY_OUTPUT: AdapterOutput = Object.freeze({
30
+ template: '',
31
+ sections: EMPTY_SECTIONS,
32
+ extension: '.tsx',
33
+ })
34
+ class EmptyNoTemplateAdapter extends BaseAdapter {
35
+ name = 'empty-no-template'
36
+ extension = '.tsx'
37
+ emitsTemplates = false
38
+ acceptsTemplateCall = (): boolean => true
39
+ generate(): AdapterOutput {
40
+ return EMPTY_OUTPUT
41
+ }
42
+ renderNode(): string { return '' }
43
+ renderElement(): string { return '' }
44
+ renderExpression(): string { return '' }
45
+ renderConditional(): string { return '' }
46
+ renderLoop(): string { return '' }
47
+ renderComponent(): string { return '' }
48
+ renderScopeMarker(): string { return '' }
49
+ renderSlotMarker(): string { return '' }
50
+ renderCondMarker(): string { return '' }
51
+ }
52
+
53
+ // A hypothetical `emitsTemplates: false` adapter whose `generate()` (unlike
54
+ // `CSRAdapter`'s) returns non-empty `sections`. Nothing in the
55
+ // `TemplateAdapter` contract requires an `emitsTemplates: false` adapter's
56
+ // sections to be empty — `emitsTemplates` alone is what's supposed to
57
+ // suppress assembly. Used to pin that `compileMultipleComponents` enforces
58
+ // the same short-circuit as `compileJSX`'s single-component path, not just
59
+ // a `moduleExports`-only skip (#3234).
60
+ class LeakySectionsAdapter extends EmptyNoTemplateAdapter {
61
+ name = 'leaky-sections-no-template'
62
+ generate(): AdapterOutput {
63
+ return {
64
+ template: '',
65
+ sections: { imports: '', types: '', component: 'const LEAKED = 1;', defaultExport: '' },
66
+ extension: '.tsx',
67
+ }
68
+ }
69
+ }
70
+
16
71
  describe('Adapter output', () => {
17
72
  describe('real components', () => {
18
73
  test('compiles ButtonDemo component', async () => {
@@ -265,6 +320,93 @@ describe('Adapter output', () => {
265
320
  })
266
321
  })
267
322
 
323
+ describe('emitsTemplates: false adapters skip module-export assembly (#3234)', () => {
324
+ const emptyAdapter = new EmptyNoTemplateAdapter()
325
+
326
+ test('component with no value export: empty markedTemplate (baseline)', () => {
327
+ const source = `
328
+ 'use client'
329
+ export function Hello() { return <p>hi</p> }
330
+ `
331
+ const result = compileJSX(source, 'Hello.tsx', { adapter: emptyAdapter })
332
+ expect(result.errors).toHaveLength(0)
333
+ const template = result.files.find(f => f.type === 'markedTemplate')
334
+ expect(template?.content ?? '').toBe('')
335
+ })
336
+
337
+ test('component + export const: markedTemplate stays empty instead of becoming the export alone', () => {
338
+ const source = `
339
+ 'use client'
340
+ export const MAX = 3
341
+ export function Hello() { return <p>hi {MAX}</p> }
342
+ `
343
+ const result = compileJSX(source, 'Hello.tsx', { adapter: emptyAdapter })
344
+ expect(result.errors).toHaveLength(0)
345
+ const template = result.files.find(f => f.type === 'markedTemplate')
346
+ expect(template?.content ?? '').toBe('')
347
+ })
348
+
349
+ test('component + export function: markedTemplate stays empty', () => {
350
+ const source = `
351
+ 'use client'
352
+ export function helper() { return 1 }
353
+ export function Hello() { return <p>hi {helper()}</p> }
354
+ `
355
+ const result = compileJSX(source, 'Hello.tsx', { adapter: emptyAdapter })
356
+ expect(result.errors).toHaveLength(0)
357
+ const template = result.files.find(f => f.type === 'markedTemplate')
358
+ expect(template?.content ?? '').toBe('')
359
+ })
360
+
361
+ test('server component (no "use client") + export const: markedTemplate stays empty', () => {
362
+ const source = `
363
+ export const MAX = 3
364
+ export function Hello() { return <p>hi {MAX}</p> }
365
+ `
366
+ const result = compileJSX(source, 'Hello.tsx', { adapter: emptyAdapter })
367
+ expect(result.errors).toHaveLength(0)
368
+ const template = result.files.find(f => f.type === 'markedTemplate')
369
+ expect(template?.content ?? '').toBe('')
370
+ })
371
+
372
+ test('multi-component file + export const: markedTemplate stays empty (compileMultipleComponents path)', () => {
373
+ const source = `
374
+ 'use client'
375
+ export const MAX = 3
376
+ export function Hello() { return <p>hi {MAX}</p> }
377
+ export function World() { return <p>world</p> }
378
+ `
379
+ const result = compileJSX(source, 'Multi.tsx', { adapter: emptyAdapter })
380
+ expect(result.errors).toHaveLength(0)
381
+ const template = result.files.find(f => f.type === 'markedTemplate')
382
+ expect(template?.content ?? '').toBe('')
383
+ })
384
+
385
+ test('multi-component file: emitsTemplates:false still wins even when generate() returns non-empty sections', () => {
386
+ const source = `
387
+ 'use client'
388
+ export function Hello() { return <p>hi</p> }
389
+ export function World() { return <p>world</p> }
390
+ `
391
+ const result = compileJSX(source, 'Multi.tsx', { adapter: new LeakySectionsAdapter() })
392
+ expect(result.errors).toHaveLength(0)
393
+ const template = result.files.find(f => f.type === 'markedTemplate')
394
+ expect(template?.content ?? '').toBe('')
395
+ })
396
+
397
+ test('an adapter WITHOUT emitsTemplates: false still gets its value exports appended (regression guard)', () => {
398
+ const source = `
399
+ 'use client'
400
+ export const MAX = 3
401
+ export function Hello() { return <p>hi {MAX}</p> }
402
+ `
403
+ const result = compileJSX(source, 'Hello.tsx', { adapter })
404
+ expect(result.errors).toHaveLength(0)
405
+ const template = result.files.find(f => f.type === 'markedTemplate')!
406
+ expect(template.content).toContain('export const MAX = 3')
407
+ })
408
+ })
409
+
268
410
  describe('arrow function bodies preserved in SSR (#543)', () => {
269
411
  test('simple derived-state arrow function body is preserved in markedTemplate', () => {
270
412
  const honoAdapter = new HonoAdapter()
@@ -198,3 +198,30 @@ describe('BindingScope', () => {
198
198
  })
199
199
  })
200
200
  })
201
+
202
+ describe('scoped string value types', () => {
203
+ test('nested string rows retain outer types; numeric shadows and indexes do not inherit them', () => {
204
+ const outer = BindingScope.EMPTY.enterLoopRow({ param: 'item', itemType: { primitive: 'string' } })
205
+ const inner = outer.enterLoopRow({ param: 'choice', index: 'i', itemType: { primitive: 'string' } })
206
+ expect(inner.isStringValueName('item', () => false)).toBe(true)
207
+ expect(inner.isStringValueName('choice', () => false)).toBe(true)
208
+ expect(inner.isStringValueName('choice', () => false, true)).toBe(false)
209
+ expect(inner.isStringValueName('i', () => true)).toBe(false)
210
+ const shadow = inner.enterLoopRow({ param: 'item', itemType: { primitive: 'number' } })
211
+ expect(shadow.isStringValueName('item', () => true)).toBe(false)
212
+ expect(shadow.shadowedNames()).toEqual(['item'])
213
+ expect(inner.shadowedNames()).toEqual([])
214
+ expect(outer.isStringValueName('item', () => false)).toBe(true)
215
+ expect(inner.isStringValueName('title', () => true)).toBe(true)
216
+ })
217
+ test('a union of string literals is string-valued; mixed unions are not', () => {
218
+ const stringRow = BindingScope.EMPTY.enterLoopRow({ param: 'row', itemType: {
219
+ unionTypes: [{ primitive: 'string' }, { primitive: 'string' }],
220
+ } })
221
+ expect(stringRow.isStringValueName('row', () => false)).toBe(true)
222
+ const mixedRow = stringRow.enterLoopRow({ param: 'row', itemType: {
223
+ unionTypes: [{ primitive: 'string' }, { primitive: 'number' }],
224
+ } })
225
+ expect(mixedRow.isStringValueName('row', () => true)).toBe(false)
226
+ })
227
+ })
@@ -170,6 +170,23 @@ export function Box(props: { children?: any }) {
170
170
  }`,
171
171
  pin: (js) => expect(js).toContain('${markupOrEmpty((_p.children))}'),
172
172
  },
173
+ {
174
+ id: 'children-nullish-empty-fallback',
175
+ source: `
176
+ export function Box(props: { children?: unknown }) {
177
+ const { children: kids } = props
178
+ return <div>{(kids) ?? ''}</div>
179
+ }`,
180
+ pin: (js) => expect(js).toContain('markupOrEmpty('),
181
+ },
182
+ {
183
+ id: 'children-nullish-text-fallback',
184
+ source: `
185
+ export function Box(props: { children?: unknown }) {
186
+ return <div>{props.children ?? '<b>text</b>'}</div>
187
+ }`,
188
+ pin: (js) => expect(js).toContain('escapeText('),
189
+ },
173
190
  {
174
191
  // The author-facing escape hatch, by name.
175
192
  id: 'dangerously-set-inner-html',
@@ -0,0 +1,41 @@
1
+ import { describe, expect, test } from 'bun:test'
2
+ import { compileJSX } from '../compiler'
3
+ import { TestAdapter } from '../adapters/test-adapter'
4
+
5
+ // The branch collector must retain each inner row's own binding scope,
6
+ // independently of whether either source array is reactive.
7
+ describe('nested conditional-branch loop binding collection (#3274)', () => {
8
+ for (const signalOuter of [false, true]) {
9
+ for (const signalInner of [false, true]) {
10
+ test(`outer signal=${signalOuter}, inner signal=${signalInner}`, () => {
11
+ const source = `
12
+ 'use client'
13
+ import { createSignal } from '@barefootjs/client'
14
+ const GROUPS = ['a', 'b']
15
+ const CHOICES = ['1', '2']
16
+ export function BranchChoices() {
17
+ const [open] = createSignal(true)
18
+ const [picked] = createSignal('a1')
19
+ const [groups] = createSignal(GROUPS)
20
+ const [choices] = createSignal(CHOICES)
21
+ return <section>{open() ? <div>
22
+ {${signalOuter ? 'groups()' : 'GROUPS'}.map(group => <div key={group}>
23
+ {${signalInner ? 'choices()' : 'CHOICES'}.map(choice =>
24
+ <button key={choice} aria-checked={picked() === group + choice ? 'true' : 'false'}>
25
+ {picked() === group + choice ? 'on' : 'off'}
26
+ </button>)}
27
+ </div>)}
28
+ </div> : null}</section>
29
+ }
30
+ `
31
+ const result = compileJSX(source, 'BranchChoices.tsx', { adapter: new TestAdapter() })
32
+ expect(result.errors.filter(e => e.severity === 'error')).toEqual([])
33
+ const js = result.files.find(f => f.type === 'clientJs')!.content
34
+ expect(js).toContain('mapArray(() =>')
35
+ expect(js).toContain("setAttribute('aria-checked'")
36
+ expect(js).toContain("insert(__innerEl1_0, 's1', () => picked() === group() + choice()")
37
+ expect(js).toContain('group() + choice()')
38
+ })
39
+ }
40
+ }
41
+ })
@@ -103,6 +103,36 @@ export function C() {
103
103
  expect(codes).toEqual([])
104
104
  expect(initBody).toContain("const [, send] = createMutation(() => http.post('/api/ping'))")
105
105
  })
106
+
107
+ // #3245: the value-elided form synthesizes an internal getter name
108
+ // (`__bfGet_<action>`, analyzer.ts's `collectFactorySignal`) that nothing in
109
+ // the source ever references. It must not leak into any adapter's
110
+ // server-facing output — the SSR module, the SSR-defaults manifest, or a
111
+ // generated props struct/constructor.
112
+ test('an elided value never leaks `__bfGet_` into SSR-facing output', () => {
113
+ const source = `
114
+ 'use client'
115
+ import { createMutation, http } from '@barefootjs/client'
116
+ export function Save() {
117
+ const [, save] = createMutation(() => http.post('/api/items', {}))
118
+ return <button disabled={save.isPending()} onClick={() => save()}>Save</button>
119
+ }
120
+ `
121
+ const honoResult = compileJSX(source, 'Save.tsx', { adapter: new HonoAdapter() })
122
+ expect(honoResult.errors).toEqual([])
123
+ const ssr = honoResult.files.find((f) => f.type === 'markedTemplate')?.content ?? ''
124
+ expect(ssr).not.toContain('__bfGet_')
125
+ expect(ssr).toContain('Object.assign(() => {}, { isPending: () => false, error: () => undefined })')
126
+ const honoSsrDefaults = honoResult.files.find((f) => f.type === 'ssrDefaults')?.content ?? ''
127
+ expect(honoSsrDefaults).not.toContain('__bfGet_')
128
+
129
+ const goResult = compileJSX(source, 'Save.tsx', { adapter: new GoTemplateAdapter() })
130
+ expect(goResult.errors).toEqual([])
131
+ const goSsrDefaults = goResult.files.find((f) => f.type === 'ssrDefaults')?.content ?? ''
132
+ expect(goSsrDefaults).not.toContain('__bfGet_')
133
+ const goTypes = goResult.files.find((f) => f.type === 'types')?.content ?? ''
134
+ expect(goTypes).not.toContain('__bfGet_')
135
+ })
106
136
  })
107
137
 
108
138
  describe('createMutation action accessors (#3210, via #3166)', () => {
@@ -149,6 +149,58 @@ export function C() {
149
149
  expect(initBody).toContain("const [, fetchItems] = createQuery(() => http.get('/api/items'))")
150
150
  })
151
151
 
152
+ // #3245: the value-elided form synthesizes an internal getter name
153
+ // (`__bfGet_<action>`, analyzer.ts's `collectFactorySignal`) that nothing in
154
+ // the source ever references. It must not leak into any adapter's
155
+ // server-facing output — the SSR module, the SSR-defaults manifest, or a
156
+ // generated props struct/constructor.
157
+ test('an elided value never leaks `__bfGet_` into SSR-facing output', () => {
158
+ const source = `
159
+ 'use client'
160
+ import { createQuery, http } from '@barefootjs/client'
161
+ export function C() {
162
+ const [, fetchItems] = createQuery(() => http.get<string[]>('/api/items'))
163
+ return <button disabled={fetchItems.isPending()} onClick={() => fetchItems()}>load</button>
164
+ }
165
+ `
166
+ const honoResult = compileJSX(source, 'C.tsx', { adapter: new HonoAdapter() })
167
+ expect(honoResult.errors).toEqual([])
168
+ const ssr = honoResult.files.find((f) => f.type === 'markedTemplate')?.content ?? ''
169
+ expect(ssr).not.toContain('__bfGet_')
170
+ expect(ssr).toContain('Object.assign(() => {}, { isPending: () => false, error: () => undefined })')
171
+ const honoSsrDefaults = honoResult.files.find((f) => f.type === 'ssrDefaults')?.content ?? ''
172
+ expect(honoSsrDefaults).not.toContain('__bfGet_')
173
+
174
+ const goResult = compileJSX(source, 'C.tsx', { adapter: new GoTemplateAdapter() })
175
+ expect(goResult.errors).toEqual([])
176
+ const goSsrDefaults = goResult.files.find((f) => f.type === 'ssrDefaults')?.content ?? ''
177
+ expect(goSsrDefaults).not.toContain('__bfGet_')
178
+ const goTypes = goResult.files.find((f) => f.type === 'types')?.content ?? ''
179
+ expect(goTypes).not.toContain('__bfGet_')
180
+ })
181
+
182
+ // #3245 follow-up (Pullfrog): an untyped object-array `initial` makes the
183
+ // Go adapter synthesize a struct for the elided value's item shape
184
+ // (`emitSynthStructs`) even though the field/ctor-init that would
185
+ // reference it is already skipped — the struct itself still leaked the
186
+ // internal `__bfGet_<action>` name into `.types`. The previous test's
187
+ // `initial`-less repro can't catch this, since no object-array shape means
188
+ // no struct is synthesized either way.
189
+ test('an elided value with an object-array `initial` does not leak `__bfGet_` into a Go synth struct', () => {
190
+ const source = `
191
+ 'use client'
192
+ import { createQuery, http } from '@barefootjs/client'
193
+ export function C() {
194
+ const [, fetchItems] = createQuery(() => http.get('/api/items'), { initial: [{ id: 1, name: 'a' }] })
195
+ return <button disabled={fetchItems.isPending()} onClick={() => fetchItems()}>load</button>
196
+ }
197
+ `
198
+ const goResult = compileJSX(source, 'C.tsx', { adapter: new GoTemplateAdapter() })
199
+ expect(goResult.errors).toEqual([])
200
+ const goTypes = goResult.files.find((f) => f.type === 'types')?.content ?? ''
201
+ expect(goTypes).not.toContain('__bfGet_')
202
+ })
203
+
152
204
  test('`initial` absent seeds undefined; a shorthand `initial` is read structurally', () => {
153
205
  const absent = compile(`
154
206
  'use client'
@@ -502,6 +502,89 @@ describe('DomBinding classification (#944)', () => {
502
502
  expect(loop!.deps).toContain('items')
503
503
  })
504
504
 
505
+ test('filter().map() loop deps include signals read by the filter predicate (#3246)', () => {
506
+ // Repro from #3246: `filter` is only read inside the `.filter()`
507
+ // predicate, lifted off the chain into `IRLoop.filterPredicate` and kept
508
+ // separate from `array` (`items()`) by `jsx-to-ir.ts` — so it must still
509
+ // show up as a loop dependency, exactly as it does for the DOM
510
+ // bindings that live inside the loop body.
511
+ const source = `
512
+ 'use client'
513
+ import { createSignal } from '@barefootjs/client'
514
+
515
+ export function ListA() {
516
+ const [items] = createSignal([{ id: 1, done: false }])
517
+ const [filter, setFilter] = createSignal('all')
518
+ return (
519
+ <div>
520
+ <button onClick={() => setFilter('active')}>Active</button>
521
+ <ul>{items().filter(t => filter() === 'all' || !t.done).map(t => <li key={t.id}>{t.id}</li>)}</ul>
522
+ </div>
523
+ )
524
+ }
525
+ `
526
+ const graph = buildComponentGraph(source, 'ListA.tsx')
527
+ const loop = graph.domBindings.find(d => d.type === 'loop')
528
+ expect(loop).toBeDefined()
529
+ expect(loop!.deps).toContain('items')
530
+ expect(loop!.deps).toContain('filter')
531
+
532
+ // `bf debug trace ListA.tsx filter` must show `filter -> loop`.
533
+ const filterPath = traceUpdatePath(graph, 'filter')
534
+ expect(filterPath).not.toBeNull()
535
+ const loopDependent = filterPath!.dependents.find(d => d.kind === 'dom' && d.name === loop!.label)
536
+ expect(loopDependent).toBeDefined()
537
+ })
538
+
539
+ test('filter().map() loop deps include signals read by a block-bodied predicate (#3246)', () => {
540
+ const source = `
541
+ 'use client'
542
+ import { createSignal } from '@barefootjs/client'
543
+
544
+ export function ListB() {
545
+ const [items] = createSignal([{ id: 1, done: false }])
546
+ const [filter, setFilter] = createSignal('all')
547
+ return (
548
+ <div>
549
+ <button onClick={() => setFilter('active')}>Active</button>
550
+ <ul>{items().filter(t => { const f = filter(); return f === 'all' || !t.done }).map(t => <li key={t.id}>{t.id}</li>)}</ul>
551
+ </div>
552
+ )
553
+ }
554
+ `
555
+ const graph = buildComponentGraph(source, 'ListB.tsx')
556
+ const loop = graph.domBindings.find(d => d.type === 'loop')
557
+ expect(loop).toBeDefined()
558
+ expect(loop!.deps).toContain('filter')
559
+ })
560
+
561
+ test("filter predicate's own param is excluded from deps even when it shadows a signal name and is called as a function (#3246)", () => {
562
+ // The predicate's parameter is named `filter`, same as the unrelated
563
+ // outer `filter` signal, and — unlike the signal getter — is itself a
564
+ // function being invoked (`filter()`). Naive text matching on the raw
565
+ // predicate body would mistake that call for a read of the `filter`
566
+ // signal; the predicate's own param must be excluded first.
567
+ const source = `
568
+ 'use client'
569
+ import { createSignal } from '@barefootjs/client'
570
+
571
+ export function ListC() {
572
+ const [items] = createSignal([() => true, () => false])
573
+ const [filter, setFilter] = createSignal('all')
574
+ return (
575
+ <div>
576
+ <button onClick={() => setFilter('active')}>Active</button>
577
+ <ul>{items().filter(filter => filter()).map(fn => <li>{String(fn)}</li>)}</ul>
578
+ </div>
579
+ )
580
+ }
581
+ `
582
+ const graph = buildComponentGraph(source, 'ListC.tsx')
583
+ const loop = graph.domBindings.find(d => d.type === 'loop')
584
+ expect(loop).toBeDefined()
585
+ expect(loop!.deps).not.toContain('filter')
586
+ })
587
+
505
588
  test('opaque call in child-component prop is fallback (#944 concern 1)', () => {
506
589
  // `<Card title={formatTitle(page)} />` — the #942 motivating example.
507
590
  // The child-prop emitter wraps this in a reactive child-prop entry via
@@ -77,8 +77,9 @@ describe('destructured-from-props-object → localConstants value rewrite', () =
77
77
  const clientJs = result.files.find((f) => f.type === 'clientJs')
78
78
  const content = clientJs?.content ?? ''
79
79
 
80
- // `count` is the signal getter — must stay as `count()`, not `_p.count()`
81
- expect(content).toMatch(/const\s+doubled\s*=\s*count\(\)\s*\*\s*2/)
80
+ // The signal remains a local getter (now hygienically distinct from
81
+ // the bare prop), never a read/call of the caller's `_p.count`.
82
+ expect(content).toMatch(/const\s+doubled\s*=\s*bfSignal_count\(\)\s*\*\s*2/)
82
83
  expect(content).not.toMatch(/const\s+doubled\s*=\s*_p\.count\(\)/)
83
84
  })
84
85
 
@@ -92,6 +92,29 @@ describe('transparent fragment (Context Provider pattern)', () => {
92
92
  }
93
93
  })
94
94
 
95
+ test('does NOT mark <> {children} </> with single-line padding as transparent', () => {
96
+ // Unlike a text node split across a line break (cleans to ''), a
97
+ // same-line space around `{children}` is real, rendered text per
98
+ // `cleanJsxWhitespace` — so the fragment has three children, not one,
99
+ // and can't be a pure pass-through.
100
+ const source = `
101
+ 'use client'
102
+
103
+ export function DialogRoot({ children }) {
104
+ return <> {children} </>
105
+ }
106
+ `
107
+
108
+ const ctx = analyzeComponent(source, 'DialogRoot.tsx')
109
+ const ir = jsxToIR(ctx)
110
+
111
+ expect(ir).not.toBeNull()
112
+ expect(ir!.type).toBe('fragment')
113
+ if (ir!.type === 'fragment') {
114
+ expect(ir!.transparent).toBeFalsy()
115
+ }
116
+ })
117
+
95
118
  test('does NOT mark fragment with non-children expression as transparent', () => {
96
119
  const source = `
97
120
  'use client'