@barefootjs/jsx 0.35.2 → 0.35.4

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 (30) hide show
  1. package/dist/debug.d.ts +33 -3
  2. package/dist/debug.d.ts.map +1 -1
  3. package/dist/index.js +2995 -2851
  4. package/dist/ir-to-client-js/collect-elements.d.ts.map +1 -1
  5. package/dist/ir-to-client-js/plan/build-static-array-child-init.d.ts.map +1 -1
  6. package/dist/ir-to-client-js/plan/static-array-child-init.d.ts +19 -1
  7. package/dist/ir-to-client-js/plan/static-array-child-init.d.ts.map +1 -1
  8. package/dist/ir-to-client-js/stringify/static-array-child-init.d.ts.map +1 -1
  9. package/dist/ir-to-client-js/types.d.ts +25 -0
  10. package/dist/ir-to-client-js/types.d.ts.map +1 -1
  11. package/dist/jsx-to-ir.d.ts.map +1 -1
  12. package/dist/prop-rewrite.d.ts +26 -0
  13. package/dist/prop-rewrite.d.ts.map +1 -1
  14. package/package.json +2 -2
  15. package/src/__tests__/branch-local-in-attr-position.test.ts +24 -12
  16. package/src/__tests__/client-only-date-lowering.test.ts +29 -1
  17. package/src/__tests__/debug.test.ts +246 -0
  18. package/src/__tests__/issue-2798-static-nested-loop-bindings.test.ts +127 -0
  19. package/src/__tests__/issue-2856-branch-local-shorthand.test.ts +86 -0
  20. package/src/__tests__/issue-2897-static-loop-conditional.test.ts +340 -0
  21. package/src/__tests__/lazy-conditional.test.ts +1 -0
  22. package/src/__tests__/rewrite-destructured-props.test.ts +10 -5
  23. package/src/debug.ts +214 -84
  24. package/src/ir-to-client-js/collect-elements.ts +83 -3
  25. package/src/ir-to-client-js/plan/build-static-array-child-init.ts +59 -19
  26. package/src/ir-to-client-js/plan/static-array-child-init.ts +19 -1
  27. package/src/ir-to-client-js/stringify/static-array-child-init.ts +39 -0
  28. package/src/ir-to-client-js/types.ts +37 -1
  29. package/src/jsx-to-ir.ts +16 -4
  30. package/src/prop-rewrite.ts +74 -33
@@ -0,0 +1,127 @@
1
+ /**
2
+ * #2798: a static (non-signal) array's `.map()` faithfully invokes a
3
+ * `ref` callback, and reactively updates a signal-derived text, on the
4
+ * TOP-LEVEL row (`buildStaticLoopPlan`'s `childRefs`/`texts`). But a
5
+ * nested `.map()` INSIDE a static outer row's item — a plain element,
6
+ * not a child component — reached `elem.innerLoops` processing only
7
+ * when it had matching depth-N CHILD COMPONENTS
8
+ * (`buildStaticArrayChildInitsPlan`'s `innerComps.length === 0`
9
+ * skip). A plain-element inner loop under a static outer array had
10
+ * NOTHING wired: no ref invocation, no reactive-text/attr effect — the
11
+ * whole row was silently frozen at its SSR-baked value.
12
+ *
13
+ * (The issue's own repro — a TOP-LEVEL static loop with a `ref` — was
14
+ * already fixed by the time this was investigated; that shape is
15
+ * pinned here too as regression armor against the issue's own
16
+ * misdiagnosis being reintroduced.)
17
+ */
18
+ import { describe, test, expect } from 'bun:test'
19
+ import { compileJSX } from '../index'
20
+ import { HonoAdapter } from '../../../adapter-hono/src/adapter/index'
21
+
22
+ function compileClientJs(source: string): string {
23
+ const result = compileJSX(source, 'test.tsx', { adapter: new HonoAdapter() })
24
+ expect(result.errors.filter(e => e.severity === 'error')).toHaveLength(0)
25
+ const clientJs = result.files.find(f => f.type === 'clientJs')
26
+ if (!clientJs) throw new Error('No client JS emitted')
27
+ return clientJs.content
28
+ }
29
+
30
+ describe('static array ref/reactive bindings (#2798)', () => {
31
+ test('top-level static loop still invokes a ref on each row (regression armor)', () => {
32
+ const source = `
33
+ 'use client'
34
+ export function StaticRefCase() {
35
+ const items = [{ id: 1 }, { id: 2 }]
36
+ const trackMount = (el: Element) => { el.setAttribute('data-tracked', '1') }
37
+ return (
38
+ <ul>
39
+ {items.map(item => (
40
+ <li key={item.id} ref={trackMount}>{item.id}</li>
41
+ ))}
42
+ </ul>
43
+ )
44
+ }
45
+ `
46
+ const js = compileClientJs(source)
47
+ expect(js).toContain('(trackMount)(')
48
+ })
49
+
50
+ test('a static outer loop with a nested .map() invokes the inner ref on each row', () => {
51
+ const source = `
52
+ 'use client'
53
+ export function StaticNestedRefCase() {
54
+ const items = [{ id: 1, children: [{ id: 11 }, { id: 12 }] }]
55
+ const trackMount = (el: Element) => { el.setAttribute('data-tracked', '1') }
56
+ return (
57
+ <ul>
58
+ {items.map(item => (
59
+ <li key={item.id}>
60
+ {item.children.map(child => (
61
+ <span key={child.id} ref={trackMount}>{child.id}</span>
62
+ ))}
63
+ </li>
64
+ ))}
65
+ </ul>
66
+ )
67
+ }
68
+ `
69
+ const js = compileClientJs(source)
70
+ // Double forEach (outer item, inner child), with the ref invoked
71
+ // inside the inner one.
72
+ expect(js).toContain('items.forEach((item, __idx) => {')
73
+ expect(js).toContain('item.children.forEach((child, __innerIdx) => {')
74
+ expect(js).toContain('(trackMount)(')
75
+ })
76
+
77
+ test('a static outer loop with a nested .map() reactively updates a signal-derived inner text', () => {
78
+ const source = `
79
+ 'use client'
80
+ import { createSignal } from '@barefootjs/client'
81
+ export function StaticNestedSignalCase() {
82
+ const items = [{ id: 1, children: [{ id: 11 }, { id: 12 }] }]
83
+ const [count] = createSignal(0)
84
+ return (
85
+ <ul>
86
+ {items.map(item => (
87
+ <li key={item.id}>
88
+ {item.children.map(child => (
89
+ <span key={child.id}>{child.id}:{count()}</span>
90
+ ))}
91
+ </li>
92
+ ))}
93
+ </ul>
94
+ )
95
+ }
96
+ `
97
+ const js = compileClientJs(source)
98
+ // Pre-fix, this text was frozen at its SSR-baked value — no
99
+ // `createEffect` at all inside the inner forEach body.
100
+ expect(js).toMatch(/createEffect\(\(\) => \{ __bfw_\w+\('s\d+', String\(count\(\)\)\) \}\)/)
101
+ })
102
+
103
+ test('a static outer loop with a nested .map() wires a reactive attr on the inner element', () => {
104
+ const source = `
105
+ 'use client'
106
+ import { createSignal } from '@barefootjs/client'
107
+ export function StaticNestedAttrCase() {
108
+ const items = [{ id: 1, children: [{ id: 11 }, { id: 12 }] }]
109
+ const [sel] = createSignal(11)
110
+ return (
111
+ <ul>
112
+ {items.map(item => (
113
+ <li key={item.id}>
114
+ {item.children.map(child => (
115
+ <span key={child.id} data-active={child.id === sel()}>{child.id}</span>
116
+ ))}
117
+ </li>
118
+ ))}
119
+ </ul>
120
+ )
121
+ }
122
+ `
123
+ const js = compileClientJs(source)
124
+ expect(js).toContain('data-active')
125
+ expect(js).toMatch(/createEffect\(\(\) => \{/)
126
+ })
127
+ })
@@ -0,0 +1,86 @@
1
+ /**
2
+ * #2856: `replaceBranchLocalRefs` (jsx-to-ir.ts) used to substitute a
3
+ * branch-local's occurrences via a plain regex token scanner
4
+ * (`replaceInExprContexts`), which has no notion of AST position. An
5
+ * object-literal shorthand property (`{ local }`, simultaneously the
6
+ * key and the value) got its substitution wrapped in parens with the
7
+ * key silently dropped — `{ (_p.tag) }` — invalid JS that broke the
8
+ * whole client bundle's parse at runtime with no compile-time
9
+ * diagnostic.
10
+ *
11
+ * The fix routes both call sites through `rewriteScopedValueRefs`
12
+ * (`prop-rewrite.ts`), the same AST-based, scope-aware walk that
13
+ * already handled this exact key/value duality for destructured props
14
+ * (#2828/#2853). These tests pin the general mechanism directly
15
+ * (`rewriteScopedValueRefs`) — shorthand expansion, and the three
16
+ * sibling positions a naive scanner conflates with a value reference:
17
+ * a member-access name, an explicit object-literal key, and a name
18
+ * shadowed by an inner binding. An end-to-end compiler regression for
19
+ * the issue's own repro lives in
20
+ * `rewrite-destructured-props.test.ts` ("branch-local transitive
21
+ * prop-dep via shorthand reference").
22
+ */
23
+ import { describe, test, expect } from 'bun:test'
24
+ import { rewriteScopedValueRefs } from '../prop-rewrite.ts'
25
+
26
+ describe('rewriteScopedValueRefs (#2856)', () => {
27
+ test('expands an object-literal shorthand property to `name: value`', () => {
28
+ const out = rewriteScopedValueRefs('{ local }', new Set(['local']), () => '(_p.tag)')
29
+ expect(out).toBe('{ local: (_p.tag) }')
30
+ })
31
+
32
+ test('does not touch a member-access name that merely shares the branch-local name', () => {
33
+ const out = rewriteScopedValueRefs('obj.local', new Set(['local']), () => '(_p.tag)')
34
+ expect(out).toBe('obj.local')
35
+ })
36
+
37
+ test('does not touch an explicit object-literal key', () => {
38
+ const out = rewriteScopedValueRefs('{ local: 1 }', new Set(['local']), () => '(_p.tag)')
39
+ expect(out).toBe('{ local: 1 }')
40
+ })
41
+
42
+ test('does not substitute a name shadowed by an inner arrow parameter', () => {
43
+ const out = rewriteScopedValueRefs('[1, 2, 3].map((local) => local)', new Set(['local']), () => '(_p.tag)')
44
+ expect(out).toBe('[1, 2, 3].map((local) => local)')
45
+ })
46
+
47
+ test('substitutes a real value reference alongside an unrelated shadowed one', () => {
48
+ const out = rewriteScopedValueRefs(
49
+ 'local + [1, 2, 3].map((local) => local).join(",")',
50
+ new Set(['local']),
51
+ () => '(_p.tag)',
52
+ )
53
+ expect(out).toBe('(_p.tag) + [1, 2, 3].map((local) => local).join(",")')
54
+ })
55
+
56
+ test('does not touch a destructuring declaration\'s source key (pullfrog review, #2889)', () => {
57
+ // `{ local: renamed } = obj` -- `local` here is the SOURCE key of a
58
+ // renamed destructuring binding, not a value reference. Distinct from
59
+ // the shorthand case above: a renamed destructuring pattern has BOTH
60
+ // `propertyName` (the source key) and `name` (the local binding), and
61
+ // only the latter was excluded pre-fix.
62
+ const out = rewriteScopedValueRefs(
63
+ '(el) => { const { local: renamed } = obj; use(renamed) }',
64
+ new Set(['local']),
65
+ () => '(_p.tag)',
66
+ )
67
+ expect(out).toBe('(el) => { const { local: renamed } = obj; use(renamed) }')
68
+ })
69
+
70
+ test('resolves inside a template-literal interpolation hole, leaving the cooked text alone', () => {
71
+ const out = rewriteScopedValueRefs('`label:local=${local}`', new Set(['local']), () => '(_p.tag)')
72
+ expect(out).toBe('`label:local=${(_p.tag)}`')
73
+ })
74
+
75
+ test('returns null for text that does not parse as an expression when allowStatements is not set', () => {
76
+ const out = rewriteScopedValueRefs('const x = local', new Set(['local']), () => '(_p.tag)')
77
+ expect(out).toBeNull()
78
+ })
79
+
80
+ test('with allowStatements, resolves a value reference in statement-shaped text', () => {
81
+ const out = rewriteScopedValueRefs('const x = local', new Set(['local']), () => '(_p.tag)', {
82
+ allowStatements: true,
83
+ })
84
+ expect(out).toBe('const x = (_p.tag)')
85
+ })
86
+ })
@@ -0,0 +1,340 @@
1
+ /**
2
+ * #2897 — a conditional (`{cond ? A : B}`) inside a STATIC (non-signal)
3
+ * array's `.map()` row was never wired reactively: neither the top-level
4
+ * static forEach bake nor the depth-1 `inner-loop-nested` clone-and-wire
5
+ * architecture (#2798) has any conditional-handling machinery, so the
6
+ * condition's INITIAL value baked into the per-row template at compile
7
+ * time and never updated again.
8
+ *
9
+ * `elem.bodyIsItemConditional` (#1665) already carved out ONE narrow shape
10
+ * of this — the row's entire body is a single conditional with at least one
11
+ * empty branch — by routing it through the plain dynamic path regardless of
12
+ * `isStaticArray`. This fix widens the same idea: a derived client-side
13
+ * `isStaticArray` (`collect-elements.ts`) goes false whenever a conditional
14
+ * is present anywhere in the row tree (this row's own bindings, or any
15
+ * depth-1 inner loop's), falling through to the plain/composite dynamic
16
+ * path — which already wires a conditional's live branch-swap correctly on
17
+ * a signal-backed array — instead of the static fast path that has no
18
+ * conditional support to add.
19
+ *
20
+ * Only ROUTING/EMISSION is pinned here (compiler-unit speed); the actual
21
+ * reactive behavior (does the branch really swap after a click) is a
22
+ * `fixture-hydrate.playwright.ts` fixture, since CSR conformance only
23
+ * observes the initial mount — which already matches SSR's baked branch
24
+ * either way, so it can't see this bug.
25
+ */
26
+ import { describe, test, expect } from 'bun:test'
27
+ import { compileJSX } from '../compiler'
28
+ import { TestAdapter } from '../adapters/test-adapter'
29
+
30
+ const adapter = new TestAdapter()
31
+
32
+ function compile(source: string): string {
33
+ const result = compileJSX(source.trimStart(), 'C.tsx', { adapter })
34
+ expect(result.errors).toHaveLength(0)
35
+ return result.files.find((f) => f.type === 'clientJs')!.content
36
+ }
37
+
38
+ const usesStaticForEach = (js: string) => /\.forEach\(\(?\w+, __idx\)? =>/.test(js)
39
+ const usesReconciliation = (js: string) => js.includes('mapArray(') || js.includes('mapArrayLazy(') || js.includes('mapArrayAnchored(')
40
+
41
+ describe('#2897 — top-level: static array with a conditional alongside static siblings', () => {
42
+ const source = `
43
+ 'use client'
44
+ import { createSignal } from '@barefootjs/client'
45
+ export function C() {
46
+ const items = [{ id: 1, label: 'Alpha' }]
47
+ const [flag] = createSignal(true)
48
+ return (
49
+ <ul>
50
+ {items.map(item => (
51
+ <li key={item.id}>
52
+ <span>{item.label}</span>
53
+ {flag() ? <b>Yes</b> : <i>No</i>}
54
+ </li>
55
+ ))}
56
+ </ul>
57
+ )
58
+ }
59
+ `
60
+
61
+ test('routes through reconciliation (mapArray family), not the static forEach bake', () => {
62
+ const js = compile(source)
63
+ expect(usesReconciliation(js)).toBe(true)
64
+ expect(usesStaticForEach(js)).toBe(false)
65
+ })
66
+
67
+ test('createRow/applyOuter read flag() live, not just the SSR-matching bootstrap template', () => {
68
+ const js = compile(source)
69
+ // The `hydrate(...).template` bootstrap legitimately bakes the signal's
70
+ // INITIAL value (it only needs to match SSR's first render — the same
71
+ // shape the dynamic-array control produces, see the module docstring).
72
+ // What must NOT happen is EVERY occurrence being baked: `applyOuter`'s
73
+ // own re-evaluation (`flag()` called bare, to track the dependency) is
74
+ // the actual regression pin — pre-fix, this function never existed at
75
+ // all for a static array.
76
+ expect(js).toContain('applyOuter')
77
+ expect(js).toMatch(/applyOuter:\s*\(__es, __seed\) => {\s*flag\(\)/)
78
+ })
79
+ })
80
+
81
+ describe('#2897 — top-level: static array, whole-row ternary between two elements (both arms render)', () => {
82
+ // `bodyIsItemConditional` (#1665) only carves out a WHOLE-row conditional
83
+ // with at least one EMPTY branch — a ternary where BOTH arms render an
84
+ // element evades that narrower gate too, and needs the same widened fix.
85
+ const source = `
86
+ 'use client'
87
+ import { createSignal } from '@barefootjs/client'
88
+ export function C() {
89
+ const items = [{ id: 1 }]
90
+ const [flag] = createSignal(true)
91
+ return (
92
+ <ul>
93
+ {items.map(item => flag() ? <li key={item.id}>Active</li> : <li key={item.id}>Inactive</li>)}
94
+ </ul>
95
+ )
96
+ }
97
+ `
98
+
99
+ test('routes through reconciliation, not the static forEach bake', () => {
100
+ const js = compile(source)
101
+ expect(usesReconciliation(js)).toBe(true)
102
+ expect(usesStaticForEach(js)).toBe(false)
103
+ })
104
+ })
105
+
106
+ describe('#2897 — nested: static outer array + depth-1 inner loop whose row has a conditional', () => {
107
+ const source = `
108
+ 'use client'
109
+ import { createSignal } from '@barefootjs/client'
110
+ export function C() {
111
+ const items = [{ id: 1, children: [{ id: 11 }] }]
112
+ const [flag] = createSignal(true)
113
+ return (
114
+ <ul>
115
+ {items.map(item => (
116
+ <li key={item.id}>
117
+ {item.children.map(child => (
118
+ <span key={child.id}>{flag() ? <b>Yes</b> : <i>No</i>}</span>
119
+ ))}
120
+ </li>
121
+ ))}
122
+ </ul>
123
+ )
124
+ }
125
+ `
126
+
127
+ test('escalates to composite element reconciliation for BOTH loops, not the #2798 static clone-and-wire path', () => {
128
+ const js = compile(source)
129
+ expect(usesReconciliation(js)).toBe(true)
130
+ expect(usesStaticForEach(js)).toBe(false)
131
+ // The #2798 static-nested machinery's own signature (a plain
132
+ // `_sN.children[__idx]` walk feeding `createEffect`, no `insert()`) must
133
+ // not appear alongside the escalated path.
134
+ expect(js).not.toContain('Initialize inner-loop components in static array')
135
+ })
136
+ })
137
+
138
+ describe('#2897 follow-up — static array, own-row conditional escalates the row, sibling inner loop has a ref binding', () => {
139
+ // Pullfrog review on #2899: an own-row conditional escalates
140
+ // `clientIsStaticArray` to false regardless of any inner loop, but
141
+ // `useElementReconciliation` previously escalated ONLY on an
142
+ // inner-loop's OWN conditional (`staticInnerLoopHasConditional`). A row
143
+ // whose OWN conditional escalates it, with a SIBLING inner loop that has
144
+ // no conditional of its own but DOES have a ref/reactive-attr/reactive-text
145
+ // binding, fell through to `buildPlainLoopPlan` — which never reads
146
+ // `TopLevelLoop.innerLoops` at all — silently dropping that inner loop's
147
+ // binding with no compile error. Confirmed by compiling this exact shape
148
+ // pre-fix: the `ref` callback never appeared anywhere in the emitted JS.
149
+ const source = `
150
+ 'use client'
151
+ import { createSignal } from '@barefootjs/client'
152
+ export function C() {
153
+ const items = [{ id: 1, children: [{ id: 11 }] }]
154
+ const [flag] = createSignal(true)
155
+ return (
156
+ <ul>
157
+ {items.map(item => (
158
+ <li key={item.id}>
159
+ {flag() ? <b>Yes</b> : <i>No</i>}
160
+ {item.children.map(child => (
161
+ <span key={child.id} ref={(el) => console.log(el, child.id)}>{child.id}</span>
162
+ ))}
163
+ </li>
164
+ ))}
165
+ </ul>
166
+ )
167
+ }
168
+ `
169
+
170
+ test('escalates to composite element reconciliation so the inner loop\'s ref binding is not dropped', () => {
171
+ const js = compile(source)
172
+ expect(usesReconciliation(js)).toBe(true)
173
+ expect(usesStaticForEach(js)).toBe(false)
174
+ // The regression itself: the ref callback's body must appear somewhere
175
+ // in the emitted JS, wired to the inner loop's row element.
176
+ expect(js).toContain('console.log(el')
177
+ })
178
+ })
179
+
180
+ describe('#2897 follow-up — static array, own-row conditional reading ONLY the loop item, child-component branch', () => {
181
+ // `SocialShell` (site/ui) shape: `item.key === 'messages'` is a
182
+ // `classifyReactivity` `'loop-param'` verdict (every loop-param-referencing
183
+ // condition is, regardless of array static-ness — see `reactiveBeyondLoopScope`'s
184
+ // doc comment on `LoopChildConditional`), so `bindings.conditionals` is
185
+ // non-empty here too. For a STATIC array the row item never changes after
186
+ // first render, so this decision is exactly as compile-time-bakeable as a
187
+ // bare-element conditional — escalating it is unnecessary and (via the
188
+ // composite/`insert()` path) previously double-mounted the child component.
189
+ const source = `
190
+ 'use client'
191
+ import { createSignal } from '@barefootjs/client'
192
+ function Badge() { return <span className="badge">B</span> }
193
+ export function C() {
194
+ const items = [{ id: 1, key: 'other' }, { id: 2, key: 'messages' }]
195
+ return (
196
+ <ul>
197
+ {items.map(item => (
198
+ <li key={item.id}>
199
+ {item.key === 'messages' ? <Badge /> : null}
200
+ </li>
201
+ ))}
202
+ </ul>
203
+ )
204
+ }
205
+ `
206
+
207
+ test('stays on the static forEach + initChild path, no reconciliation', () => {
208
+ const js = compile(source)
209
+ expect(usesStaticForEach(js)).toBe(true)
210
+ expect(usesReconciliation(js)).toBe(false)
211
+ })
212
+ })
213
+
214
+ describe('#2897 follow-up — static array, own-row conditional whose CONDITION reads a signal, child-component branch', () => {
215
+ // Same branch shape as above, but the condition itself (`flag()`) can
216
+ // change after first render — this is the case #2897 actually fixes, and
217
+ // must still escalate regardless of what the branches contain.
218
+ const source = `
219
+ 'use client'
220
+ import { createSignal } from '@barefootjs/client'
221
+ function Badge() { return <span className="badge">B</span> }
222
+ export function C() {
223
+ const items = [{ id: 1 }]
224
+ const [flag] = createSignal(true)
225
+ return (
226
+ <ul>
227
+ {items.map(item => (
228
+ <li key={item.id}>
229
+ {flag() ? <Badge /> : null}
230
+ </li>
231
+ ))}
232
+ </ul>
233
+ )
234
+ }
235
+ `
236
+
237
+ test('routes through reconciliation, not the static forEach bake', () => {
238
+ const js = compile(source)
239
+ expect(usesReconciliation(js)).toBe(true)
240
+ expect(usesStaticForEach(js)).toBe(false)
241
+ })
242
+ })
243
+
244
+ describe('#2897 follow-up — static array, own-row condition mixing an item read and a signal read', () => {
245
+ // `classifyReactivity` reports `'loop-param'` (not `'signal-or-memo-or-prop'`)
246
+ // for `item.x && flag()` because it checks loop-bound names FIRST — that
247
+ // precedence is deliberate and must not change (two other, typed callers
248
+ // depend on it). `reactiveBeyondLoopScope` must still escalate this,
249
+ // independently of that `kind`, since the value CAN change after first
250
+ // render (`flag()`).
251
+ const source = `
252
+ 'use client'
253
+ import { createSignal } from '@barefootjs/client'
254
+ export function C() {
255
+ const items = [{ id: 1, x: true }]
256
+ const [flag] = createSignal(true)
257
+ return (
258
+ <ul>
259
+ {items.map(item => (
260
+ <li key={item.id}>
261
+ {item.x && flag() ? <b>Yes</b> : <i>No</i>}
262
+ </li>
263
+ ))}
264
+ </ul>
265
+ )
266
+ }
267
+ `
268
+
269
+ test('routes through reconciliation, not the static forEach bake', () => {
270
+ const js = compile(source)
271
+ expect(usesReconciliation(js)).toBe(true)
272
+ expect(usesStaticForEach(js)).toBe(false)
273
+ })
274
+ })
275
+
276
+ describe('#2897 follow-up — static array, own-row conditional reading ONLY the loop item, bare-element branches', () => {
277
+ // The item-only-condition control for a BARE-element branch (as opposed
278
+ // to the child-component branch above) — both must stay static; content
279
+ // of the branches plays no part in the escalation decision, only whether
280
+ // the condition itself can change. `ref` gives the row #2798's own
281
+ // static-forEach wiring to check against (a fully inert row — no
282
+ // ref/text/attr/childComponent needing a runtime touch at all — emits NO
283
+ // loop wiring in the first place, which would make `usesStaticForEach`
284
+ // vacuously false here regardless of this fix; a click handler alone
285
+ // doesn't count either — events use container-level delegation, not
286
+ // per-row forEach).
287
+ const source = `
288
+ 'use client'
289
+ export function C() {
290
+ const items = [{ id: 1, done: true }, { id: 2, done: false }]
291
+ return (
292
+ <ul>
293
+ {items.map(item => (
294
+ <li key={item.id} ref={(el) => console.log(el, item.id)}>
295
+ {item.done ? <b>Yes</b> : <i>No</i>}
296
+ </li>
297
+ ))}
298
+ </ul>
299
+ )
300
+ }
301
+ `
302
+
303
+ test('stays on the static forEach + createEffect path, no reconciliation', () => {
304
+ const js = compile(source)
305
+ expect(usesStaticForEach(js)).toBe(true)
306
+ expect(usesReconciliation(js)).toBe(false)
307
+ })
308
+ })
309
+
310
+ describe('#2897 — control: static outer + depth-1 inner loop with NO conditional stays on the #2798 fast path', () => {
311
+ // Regression armor: the escalation must be conditional-triggered only —
312
+ // a nested static loop with ordinary ref/text/attr bindings and no
313
+ // conditional anywhere must keep taking #2798's static clone-and-wire
314
+ // path, not silently lose that optimization.
315
+ const source = `
316
+ 'use client'
317
+ import { createSignal } from '@barefootjs/client'
318
+ export function C() {
319
+ const items = [{ id: 1, children: [{ id: 11 }] }]
320
+ const [count] = createSignal(0)
321
+ return (
322
+ <ul>
323
+ {items.map(item => (
324
+ <li key={item.id}>
325
+ {item.children.map(child => (
326
+ <span key={child.id}>{child.id}:{count()}</span>
327
+ ))}
328
+ </li>
329
+ ))}
330
+ </ul>
331
+ )
332
+ }
333
+ `
334
+
335
+ test('stays on the static forEach + createEffect path, no reconciliation', () => {
336
+ const js = compile(source)
337
+ expect(usesStaticForEach(js)).toBe(true)
338
+ expect(usesReconciliation(js)).toBe(false)
339
+ })
340
+ })
@@ -30,6 +30,7 @@ function cond(over: Partial<LoopChildConditional> = {}): LoopChildConditional {
30
30
  whenTrue: bare(),
31
31
  whenFalse: bare(),
32
32
  conditionFreeIdentifiers: new Set(['row']),
33
+ reactiveBeyondLoopScope: true,
33
34
  ...over,
34
35
  }
35
36
  }
@@ -1,4 +1,5 @@
1
1
  import { describe, test, expect } from 'bun:test'
2
+ import ts from 'typescript'
2
3
  import { compileJSX } from '../index'
3
4
  import { HonoAdapter } from '../../../adapter-hono/src/adapter/index'
4
5
 
@@ -153,11 +154,15 @@ export function Comp({ tag }: { tag: string }) {
153
154
  // Pre-fix: the hydrate template's module-scope lambda kept a bare
154
155
  // `tag` reference (no binding at that scope -- ReferenceError at pure
155
156
  // CSR mount). Post-fix: it resolves through `_p.tag` like every other
156
- // prop reference. (The surrounding `{ (_p.tag) }` shape -- the branch-
157
- // local substitution dropping the shorthand's own key -- is a
158
- // separate, pre-existing defect tracked independently; this test pins
159
- // only the prop-dependency question #2828's follow-up fixed.)
157
+ // prop reference, and the shorthand key survives the substitution
158
+ // (#2856 -- the branch-local substitution used to drop it, emitting
159
+ // the invalid `{ (_p.tag) }`).
160
160
  expect(js).not.toContain('{ (tag) }')
161
- expect(js).toContain('{ (_p.tag) }')
161
+ expect(js).not.toContain('{ (_p.tag) }')
162
+ expect(js).toContain('{ local: (_p.tag) }')
163
+ // The emitted client JS must actually parse.
164
+ const sf = ts.createSourceFile('__test.ts', js, ts.ScriptTarget.Latest, true)
165
+ const diagnostics = (sf as unknown as { parseDiagnostics?: unknown[] }).parseDiagnostics
166
+ expect(diagnostics ?? []).toHaveLength(0)
162
167
  })
163
168
  })