@barefootjs/jsx 0.37.1 → 0.39.0

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 (168) hide show
  1. package/dist/action-accessor.d.ts +159 -0
  2. package/dist/action-accessor.d.ts.map +1 -0
  3. package/dist/adapters/env-signal.d.ts +0 -8
  4. package/dist/adapters/env-signal.d.ts.map +1 -1
  5. package/dist/adapters/interface.d.ts +12 -0
  6. package/dist/adapters/interface.d.ts.map +1 -1
  7. package/dist/adapters/jsx-adapter.d.ts.map +1 -1
  8. package/dist/analyzer.d.ts +61 -1
  9. package/dist/analyzer.d.ts.map +1 -1
  10. package/dist/async-action-refusal.d.ts +45 -0
  11. package/dist/async-action-refusal.d.ts.map +1 -0
  12. package/dist/builtin-lowering-plugins.d.ts.map +1 -1
  13. package/dist/compiler.d.ts.map +1 -1
  14. package/dist/component-root-scope-comment.d.ts +36 -0
  15. package/dist/component-root-scope-comment.d.ts.map +1 -0
  16. package/dist/debug.d.ts +61 -5
  17. package/dist/debug.d.ts.map +1 -1
  18. package/dist/errors.d.ts +7 -0
  19. package/dist/errors.d.ts.map +1 -1
  20. package/dist/event-handler-name.d.ts +13 -0
  21. package/dist/event-handler-name.d.ts.map +1 -0
  22. package/dist/expression-parser.d.ts +9 -0
  23. package/dist/expression-parser.d.ts.map +1 -1
  24. package/dist/format-date-refusal.d.ts +33 -0
  25. package/dist/format-date-refusal.d.ts.map +1 -0
  26. package/dist/index.d.ts +6 -4
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +3260 -1914
  29. package/dist/ir-to-client-js/build-references.d.ts.map +1 -1
  30. package/dist/ir-to-client-js/collect-elements.d.ts.map +1 -1
  31. package/dist/ir-to-client-js/compute-inlinability.d.ts.map +1 -1
  32. package/dist/ir-to-client-js/compute-scope.d.ts.map +1 -1
  33. package/dist/ir-to-client-js/control-flow/plan/build-branch-loop.d.ts.map +1 -1
  34. package/dist/ir-to-client-js/control-flow/plan/build-component-loop.d.ts.map +1 -1
  35. package/dist/ir-to-client-js/control-flow/plan/build-composite-loop.d.ts.map +1 -1
  36. package/dist/ir-to-client-js/control-flow/plan/build-loop-child-arm.d.ts.map +1 -1
  37. package/dist/ir-to-client-js/control-flow/plan/build-loop.d.ts.map +1 -1
  38. package/dist/ir-to-client-js/control-flow/plan/insert.d.ts +2 -0
  39. package/dist/ir-to-client-js/control-flow/plan/insert.d.ts.map +1 -1
  40. package/dist/ir-to-client-js/control-flow/plan/lazy-row-eligibility.d.ts +1 -1
  41. package/dist/ir-to-client-js/control-flow/plan/loop.d.ts +57 -12
  42. package/dist/ir-to-client-js/control-flow/plan/loop.d.ts.map +1 -1
  43. package/dist/ir-to-client-js/control-flow/shared.d.ts +44 -3
  44. package/dist/ir-to-client-js/control-flow/shared.d.ts.map +1 -1
  45. package/dist/ir-to-client-js/control-flow/stringify/component-loop.d.ts +7 -5
  46. package/dist/ir-to-client-js/control-flow/stringify/component-loop.d.ts.map +1 -1
  47. package/dist/ir-to-client-js/csr-substitute.d.ts.map +1 -1
  48. package/dist/ir-to-client-js/declaration-sort.d.ts +2 -1
  49. package/dist/ir-to-client-js/declaration-sort.d.ts.map +1 -1
  50. package/dist/ir-to-client-js/emit-module-level.d.ts.map +1 -1
  51. package/dist/ir-to-client-js/emit-reactive.d.ts +43 -2
  52. package/dist/ir-to-client-js/emit-reactive.d.ts.map +1 -1
  53. package/dist/ir-to-client-js/emit-registration.d.ts.map +1 -1
  54. package/dist/ir-to-client-js/html-template.d.ts.map +1 -1
  55. package/dist/ir-to-client-js/plan/declaration-emit.d.ts +7 -5
  56. package/dist/ir-to-client-js/plan/declaration-emit.d.ts.map +1 -1
  57. package/dist/ir-to-client-js/prop-handling.d.ts.map +1 -1
  58. package/dist/ir-to-client-js/reactivity.d.ts +9 -1
  59. package/dist/ir-to-client-js/reactivity.d.ts.map +1 -1
  60. package/dist/ir-to-client-js/source-map.d.ts.map +1 -1
  61. package/dist/ir-to-client-js/types.d.ts +4 -0
  62. package/dist/ir-to-client-js/types.d.ts.map +1 -1
  63. package/dist/ir-to-client-js/utils.d.ts +66 -1
  64. package/dist/ir-to-client-js/utils.d.ts.map +1 -1
  65. package/dist/jsx-to-ir.d.ts.map +1 -1
  66. package/dist/opaque-local-accessor.d.ts +27 -0
  67. package/dist/opaque-local-accessor.d.ts.map +1 -0
  68. package/dist/signal-initializer.d.ts +24 -0
  69. package/dist/signal-initializer.d.ts.map +1 -0
  70. package/dist/template-position-walk.d.ts +68 -0
  71. package/dist/template-position-walk.d.ts.map +1 -0
  72. package/dist/to-locale-date-lowering.d.ts +7 -4
  73. package/dist/to-locale-date-lowering.d.ts.map +1 -1
  74. package/dist/types.d.ts +104 -17
  75. package/dist/types.d.ts.map +1 -1
  76. package/package.json +2 -2
  77. package/src/__tests__/__snapshots__/doc-examples.test.ts.snap +878 -4528
  78. package/src/__tests__/action-accessor.test.ts +166 -0
  79. package/src/__tests__/binding-scope-ratchet.test.ts +21 -10
  80. package/src/__tests__/branch-local-in-raw-capture.test.ts +1 -1
  81. package/src/__tests__/branch-local-same-name-collision.test.ts +9 -9
  82. package/src/__tests__/client-js-generation.test.ts +175 -0
  83. package/src/__tests__/component-root-scope-comment.test.ts +106 -0
  84. package/src/__tests__/create-mutation.test.ts +220 -0
  85. package/src/__tests__/create-query.test.ts +644 -0
  86. package/src/__tests__/csr-fragment-root-scope-shape.test.ts +156 -0
  87. package/src/__tests__/debug.test.ts +222 -0
  88. package/src/__tests__/doc-examples.test.ts +78 -25
  89. package/src/__tests__/event-handler-name.test.ts +74 -0
  90. package/src/__tests__/flatmap-segments.test.ts +11 -9
  91. package/src/__tests__/format-date-refusal.test.ts +134 -0
  92. package/src/__tests__/fragment-wrapped-conditional-return-branch.test.ts +132 -0
  93. package/src/__tests__/hydrate-template.test.ts +9 -1
  94. package/src/__tests__/issue-2798-static-nested-loop-bindings.test.ts +2 -2
  95. package/src/__tests__/issue-3009-loop-branch-ref.test.ts +2 -2
  96. package/src/__tests__/issue-3044-nested-prop-object-array-not-static.test.ts +213 -0
  97. package/src/__tests__/issue-3113-init-fn-name-collision.test.ts +133 -0
  98. package/src/__tests__/jsx-return-type-assertion.test.ts +2 -2
  99. package/src/__tests__/lazy-row-eligibility.test.ts +5 -4
  100. package/src/__tests__/loop-row-child-children-reactive-attrs.test.ts +108 -0
  101. package/src/__tests__/loop-row-child-text-children-markers.test.ts +158 -0
  102. package/src/__tests__/opaque-local-accessor.test.ts +90 -0
  103. package/src/__tests__/profiler-e2e.test.ts +13 -8
  104. package/src/__tests__/props-destructuring.test.ts +79 -4
  105. package/src/__tests__/reactive-factory-arity.test.ts +311 -0
  106. package/src/__tests__/ref-attr-absent-at-ssr.test.ts +472 -0
  107. package/src/__tests__/ssr-portal-ref-callback.test.ts +219 -0
  108. package/src/action-accessor.ts +289 -0
  109. package/src/adapters/env-signal.ts +2 -21
  110. package/src/adapters/interface.ts +13 -0
  111. package/src/adapters/jsx-adapter.ts +17 -0
  112. package/src/analyzer.ts +589 -60
  113. package/src/async-action-refusal.ts +254 -0
  114. package/src/builtin-lowering-plugins.ts +0 -2
  115. package/src/compiler.ts +27 -0
  116. package/src/component-root-scope-comment.ts +59 -0
  117. package/src/debug.ts +318 -103
  118. package/src/errors.ts +83 -1
  119. package/src/event-handler-name.ts +14 -0
  120. package/src/expression-parser.ts +41 -17
  121. package/src/format-date-refusal.ts +147 -0
  122. package/src/index.ts +14 -3
  123. package/src/ir-to-client-js/build-references.ts +6 -2
  124. package/src/ir-to-client-js/child-components.ts +8 -3
  125. package/src/ir-to-client-js/collect-elements.ts +28 -13
  126. package/src/ir-to-client-js/compute-inlinability.ts +2 -1
  127. package/src/ir-to-client-js/compute-scope.ts +3 -1
  128. package/src/ir-to-client-js/control-flow/plan/build-branch-loop.ts +2 -4
  129. package/src/ir-to-client-js/control-flow/plan/build-component-loop.ts +67 -5
  130. package/src/ir-to-client-js/control-flow/plan/build-composite-loop.ts +3 -6
  131. package/src/ir-to-client-js/control-flow/plan/build-insert.ts +1 -0
  132. package/src/ir-to-client-js/control-flow/plan/build-loop-child-arm.ts +2 -1
  133. package/src/ir-to-client-js/control-flow/plan/build-loop.ts +23 -11
  134. package/src/ir-to-client-js/control-flow/plan/insert.ts +2 -0
  135. package/src/ir-to-client-js/control-flow/plan/lazy-row-eligibility.ts +3 -3
  136. package/src/ir-to-client-js/control-flow/plan/loop.ts +51 -10
  137. package/src/ir-to-client-js/control-flow/shared.ts +78 -5
  138. package/src/ir-to-client-js/control-flow/stringify/component-loop.ts +25 -12
  139. package/src/ir-to-client-js/control-flow/stringify/insert.ts +1 -1
  140. package/src/ir-to-client-js/csr-substitute.ts +11 -3
  141. package/src/ir-to-client-js/declaration-sort.ts +7 -3
  142. package/src/ir-to-client-js/emit-module-level.ts +7 -4
  143. package/src/ir-to-client-js/emit-reactive.ts +140 -10
  144. package/src/ir-to-client-js/emit-registration.ts +6 -11
  145. package/src/ir-to-client-js/generate-init.ts +2 -2
  146. package/src/ir-to-client-js/html-template.ts +41 -19
  147. package/src/ir-to-client-js/index.ts +9 -3
  148. package/src/ir-to-client-js/phases/ref-callbacks.ts +1 -1
  149. package/src/ir-to-client-js/plan/build-declaration-emit.ts +16 -15
  150. package/src/ir-to-client-js/plan/declaration-emit.ts +7 -5
  151. package/src/ir-to-client-js/prop-handling.ts +4 -0
  152. package/src/ir-to-client-js/reactivity.ts +21 -16
  153. package/src/ir-to-client-js/source-map.ts +2 -1
  154. package/src/ir-to-client-js/stringify/declaration-emit.ts +14 -7
  155. package/src/ir-to-client-js/types.ts +4 -0
  156. package/src/ir-to-client-js/utils.ts +89 -7
  157. package/src/jsx-to-ir.ts +772 -50
  158. package/src/opaque-local-accessor.ts +44 -0
  159. package/src/rich-type-refusal.ts +1 -1
  160. package/src/signal-initializer.ts +36 -0
  161. package/src/template-position-walk.ts +203 -0
  162. package/src/to-locale-date-lowering.ts +7 -4
  163. package/src/types.ts +103 -15
  164. package/dist/format-date-lowering.d.ts +0 -30
  165. package/dist/format-date-lowering.d.ts.map +0 -1
  166. package/src/__tests__/create-selector.test.ts +0 -124
  167. package/src/__tests__/format-date-lowering.test.ts +0 -125
  168. package/src/format-date-lowering.ts +0 -55
@@ -52,13 +52,13 @@ describe("JSX return through TypeScript type assertion (#1405)", () => {
52
52
 
53
53
  if (isSmall) {
54
54
  return (
55
- <div ref={attachHost}>
55
+ <div ref={attachHost} data-attached="true">
56
56
  <div>small: {count()}</div>
57
57
  </div>
58
58
  ) as unknown as HTMLElement
59
59
  }
60
60
  return (
61
- <div ref={attachHost}>
61
+ <div ref={attachHost} data-attached="true">
62
62
  <div>large: {count()}</div>
63
63
  </div>
64
64
  ) as unknown as HTMLElement
@@ -341,12 +341,13 @@ describe('classifyLazyBinding — fail-safe', () => {
341
341
  })
342
342
 
343
343
  test('an import, a local function, and a non-literal const are all OPAQUE, not inert', () => {
344
- // A reactive accessor hides behind ordinary-looking names — the
345
- // `createSelector` const is the canonical case. Guessing "inert" here
346
- // would emit an applyOuter effect that reads them non-reactively.
344
+ // A reactive accessor hides behind ordinary-looking names — a local
345
+ // `const isSelected = someFactory(selected)` is the canonical case.
346
+ // Guessing "inert" here would emit an applyOuter effect that reads them
347
+ // non-reactively.
347
348
  const selScope = makeScope({
348
349
  signals: scope.signals,
349
- constants: new Map<string, ReadonlySet<string> | null>([['isSelected', new Set(['createSelector', 'selected'])]]),
350
+ constants: new Map<string, ReadonlySet<string> | null>([['isSelected', new Set(['someFactory', 'selected'])]]),
350
351
  inert: new Set(['clsx']),
351
352
  })
352
353
  const c = classifyLazyBinding({
@@ -0,0 +1,108 @@
1
+ /**
2
+ * BarefootJS Compiler — reactive attrs on an element forwarded as a
3
+ * loop-row child component's `children` (#3143).
4
+ *
5
+ * `{items.map(item => <Chip><a href={...}>...</a></Chip>)}` used to compile
6
+ * clean but silently drop any effect for the `<a>`'s own reactive
7
+ * attributes — no diagnostic, the DOM just never patched after the first
8
+ * render. Two distinct loop-plan shapes hit this, both fixed here:
9
+ *
10
+ * - a DYNAMIC (signal-derived) array whose row root is a component
11
+ * (`buildComponentLoopPlan`, `control-flow/plan/build-component-loop.ts`)
12
+ * — `elem.bindings.reactiveAttrs`/`.reactiveTexts` were collected but
13
+ * never read by that builder, AND the "simple" (no nested child
14
+ * components) stringifier path returned before ever looking at the
15
+ * reactive-effects plan at all.
16
+ * - a STATIC array (a plain literal, not a signal) whose row root is a
17
+ * component (`buildStaticLoopPlan`, `control-flow/plan/build-loop.ts`)
18
+ * — `attrsBySlot` was unconditionally skipped whenever the row root was
19
+ * a child component, a migration-era artifact (#1253) that never
20
+ * applied to the equivalent `texts` collection a few lines below it.
21
+ *
22
+ * The static-array shape is also the real-browser regression fixture
23
+ * `loop-row-child-children-attrs` (`packages/adapter-tests/fixtures/
24
+ * loop-row-child-children-attrs.ts`, its `interactions` — quarantine
25
+ * removed by this same change) and the known-limitation registry entry
26
+ * `loop-row-child-children-attrs-frozen` (narrowed by this change to the
27
+ * unrelated go-template SSR-construction bug the same fixture also caught).
28
+ */
29
+
30
+ import { describe, test, expect } from 'bun:test'
31
+ import { compileJSX } from '../compiler'
32
+ import { TestAdapter } from '../adapters/test-adapter'
33
+
34
+ const adapter = new TestAdapter()
35
+
36
+ describe('loop-row child component forwarded-children reactive attrs (#3143)', () => {
37
+ test('dynamic (signal-derived) array + component-root loop: forwarded <a> attrs get a createEffect', () => {
38
+ const source = `
39
+ 'use client'
40
+ import { createSignal } from '@barefootjs/client'
41
+
42
+ function Chip({ children }: { children?: any }) {
43
+ return <span>{children}</span>
44
+ }
45
+
46
+ export function Nav() {
47
+ const [active, setActive] = createSignal('a')
48
+ const [opts] = createSignal(['a', 'b'])
49
+ return (
50
+ <div>
51
+ {opts().map(opt => (
52
+ <Chip key={opt}>
53
+ <a
54
+ href={active() === opt ? '/current' : \`/other/\${opt}\`}
55
+ data-current={active() === opt ? 'true' : 'false'}
56
+ >{opt}</a>
57
+ </Chip>
58
+ ))}
59
+ </div>
60
+ )
61
+ }
62
+ `
63
+ const result = compileJSX(source, 'Nav.tsx', { adapter })
64
+ expect(result.errors).toHaveLength(0)
65
+ const content = result.files.find((f) => f.type === 'clientJs')!.content
66
+
67
+ // The forwarded <a>'s own reactive attrs must reach a createEffect —
68
+ // not just be baked once into the `children` props getter.
69
+ expect(content).toContain("setAttribute('href'")
70
+ expect(content).toContain("setAttribute('data-current'")
71
+ expect(content).toMatch(/createEffect\(\(\) => \{[\s\S]*?setAttribute\('href'/)
72
+ })
73
+
74
+ test('static array (plain literal) + component-root loop: forwarded <a> attrs get a createEffect', () => {
75
+ const source = `
76
+ 'use client'
77
+ import { createSignal } from '@barefootjs/client'
78
+
79
+ function Chip({ children }: { children?: any }) {
80
+ return <span>{children}</span>
81
+ }
82
+
83
+ export function Nav() {
84
+ const [active, setActive] = createSignal('a')
85
+ const opts = ['a', 'b']
86
+ return (
87
+ <div>
88
+ {opts.map(opt => (
89
+ <Chip key={opt}>
90
+ <a
91
+ href={active() === opt ? '/current' : \`/other/\${opt}\`}
92
+ data-current={active() === opt ? 'true' : 'false'}
93
+ >{opt}</a>
94
+ </Chip>
95
+ ))}
96
+ </div>
97
+ )
98
+ }
99
+ `
100
+ const result = compileJSX(source, 'Nav.tsx', { adapter })
101
+ expect(result.errors).toHaveLength(0)
102
+ const content = result.files.find((f) => f.type === 'clientJs')!.content
103
+
104
+ expect(content).toContain("setAttribute('href'")
105
+ expect(content).toContain("setAttribute('data-current'")
106
+ expect(content).toMatch(/createEffect\(\(\) => \{[\s\S]*?setAttribute\('href'/)
107
+ })
108
+ })
@@ -0,0 +1,158 @@
1
+ /**
2
+ * BarefootJS Compiler — keyed loop row: forwarded text children of a child
3
+ * component keep their SSR slot markers on hydration (#3064).
4
+ *
5
+ * Given a keyed `.map()` row whose child component call receives
6
+ * parent-owned reactive text as `children`
7
+ * (`<TableRow key={...}><TableCell>{payment.id}</TableCell></TableRow>`),
8
+ * the row's hydration effect used to rewrite each forwarded cell with
9
+ * `__c.textContent = ...` on every run — including its OWN first run, which
10
+ * fires immediately even when nothing has changed yet — discarding the
11
+ * `<!--bf:^sN-->…<!--/-->` slot marker pair the server emitted around the
12
+ * forwarded text. The fix patches through the marker (`$t`'s resolved Text
13
+ * node, `.data =`) instead of clobbering the whole child root, mirroring
14
+ * how a parent-owned text patches everywhere else in the compiler
15
+ * (`packages/client/src/runtime/query.ts`'s `$t`/`textNodeAfterComment`).
16
+ *
17
+ * Real-browser regression pin: the shared `data-table` fixture
18
+ * (`packages/adapter-tests/fixtures/data-table.ts`, `site/ui/components/
19
+ * data-table-demo.tsx`'s `DataTablePreviewDemo` — see `oracle-quarantine.ts`,
20
+ * quarantine removed by this same change) and the known-limitation entry
21
+ * `loop-row-child-text-children-markers-dropped` (deleted by this change).
22
+ */
23
+
24
+ import { describe, test, expect } from 'bun:test'
25
+ import { compileJSX } from '../compiler'
26
+ import { TestAdapter } from '../adapters/test-adapter'
27
+
28
+ const adapter = new TestAdapter()
29
+
30
+ describe('keyed loop row: forwarded text children keep their SSR markers (#3064)', () => {
31
+ test('a single bare-expression child patches through $t, not textContent', () => {
32
+ const source = `
33
+ 'use client'
34
+ import { createSignal } from '@barefootjs/client'
35
+
36
+ function Cell({ children }: { children?: any }) {
37
+ return <td>{children}</td>
38
+ }
39
+ function Row({ children }: { children?: any }) {
40
+ return <tr>{children}</tr>
41
+ }
42
+
43
+ type Payment = { id: string }
44
+
45
+ export function Table() {
46
+ const [payments] = createSignal<Payment[]>([])
47
+ return (
48
+ <table>
49
+ <tbody>
50
+ {payments().map(payment => (
51
+ <Row key={payment.id}>
52
+ <Cell>{payment.id}</Cell>
53
+ </Row>
54
+ ))}
55
+ </tbody>
56
+ </table>
57
+ )
58
+ }
59
+ `
60
+ const result = compileJSX(source, 'Table.tsx', { adapter })
61
+ expect(result.errors).toHaveLength(0)
62
+ const content = result.files.find((f) => f.type === 'clientJs')!.content
63
+
64
+ // Must patch through the marker-aware $t primitive, not blindly
65
+ // overwrite the whole child root's textContent (which would discard
66
+ // the SSR `<!--bf:^sN-->…<!--/-->` marker pair around `payment.id`).
67
+ expect(content).toContain('$t(__c,')
68
+ expect(content).not.toMatch(/__c\.textContent = Array\.isArray\(__v\) \? __v\.join/)
69
+ // The resolved Text node's `.data` is written, not innerHTML/textContent.
70
+ expect(content).toMatch(/\.data = String\(payment\(\)\.id/)
71
+ })
72
+
73
+ test('mixed static text + expression child (e.g. "$" + amount) only patches the expression slot', () => {
74
+ const source = `
75
+ 'use client'
76
+ import { createSignal } from '@barefootjs/client'
77
+
78
+ function Cell({ children }: { children?: any }) {
79
+ return <td>{children}</td>
80
+ }
81
+ function Row({ children }: { children?: any }) {
82
+ return <tr>{children}</tr>
83
+ }
84
+
85
+ type Payment = { id: string; amount: number }
86
+
87
+ export function Table() {
88
+ const [payments] = createSignal<Payment[]>([])
89
+ return (
90
+ <table>
91
+ <tbody>
92
+ {payments().map(payment => (
93
+ <Row key={payment.id}>
94
+ <Cell>\${payment.amount.toFixed(2)}</Cell>
95
+ </Row>
96
+ ))}
97
+ </tbody>
98
+ </table>
99
+ )
100
+ }
101
+ `
102
+ const result = compileJSX(source, 'Table.tsx', { adapter })
103
+ expect(result.errors).toHaveLength(0)
104
+ const content = result.files.find((f) => f.type === 'clientJs')!.content
105
+
106
+ expect(content).toContain('$t(__c,')
107
+ expect(content).toMatch(/\.data = String\(payment\(\)\.amount\.toFixed\(2\)/)
108
+ // The static "$" text must never be part of a patch expression — only
109
+ // the reactive part gets its own marker/slot.
110
+ expect(content).not.toMatch(/\.data = String\(\["\$"/)
111
+ })
112
+
113
+ test('composite loop (plain-element row + nested component + inner loop) patches through $t too', () => {
114
+ // `emitComponentAndEventSetup` (control-flow/shared.ts) is the SAME
115
+ // decision + emission `stringify/component-loop.ts`'s `emitNestedInit`
116
+ // used to duplicate, for the composite-loop shape (a plain-element loop
117
+ // row with both a nested child component AND an inner `.map()`, which
118
+ // routes through `upsertChild` instead of `initChild`+`createComponent`).
119
+ // #3064's fix lives in the ONE shared `buildChildrenTextEffect`/
120
+ // `stringifyChildrenTextEffect` pair both call, so this shape must be
121
+ // covered by its own fixture, not just inferred from the component-root
122
+ // case above.
123
+ const source = `
124
+ 'use client'
125
+ import { createSignal } from '@barefootjs/client'
126
+
127
+ function Badge({ children }: { children?: any }) {
128
+ return <span>{children}</span>
129
+ }
130
+
131
+ type Item = { id: number; name: string; tags: string[] }
132
+
133
+ export function List() {
134
+ const [items] = createSignal<Item[]>([])
135
+ return (
136
+ <ul>
137
+ {items().map(item => (
138
+ <li key={item.id}>
139
+ {item.tags.map(tag => <em key={tag}>{tag}</em>)}
140
+ <Badge>{item.name}</Badge>
141
+ </li>
142
+ ))}
143
+ </ul>
144
+ )
145
+ }
146
+ `
147
+ const result = compileJSX(source, 'List.tsx', { adapter })
148
+ expect(result.errors).toHaveLength(0)
149
+ const content = result.files.find((f) => f.type === 'clientJs')!.content
150
+
151
+ // upsertChild confirms this row is on the composite (not component-root)
152
+ // path — the shape `emitComponentAndEventSetup` handles.
153
+ expect(content).toContain('upsertChild(')
154
+ expect(content).toContain('$t(__c,')
155
+ expect(content).toMatch(/\.data = String\(item\(\)\.name/)
156
+ expect(content).not.toMatch(/__c\.textContent = Array\.isArray\(__v\) \? __v\.join/)
157
+ })
158
+ })
@@ -0,0 +1,90 @@
1
+ /**
2
+ * `isOpaqueLocalAccessorName` (#3144) — the shared "is this a component-body
3
+ * local bound to an opaque call" check every non-JS-runtime adapter's
4
+ * `call()` fallback consults before treating a zero-arg identifier call as
5
+ * a signal getter. See `opaque-local-accessor.ts`'s docstring.
6
+ *
7
+ * The real end-to-end behavior (the refusal firing, with the right BF101
8
+ * diagnostic, through each adapter's actual `call()` method) is covered by
9
+ * the `opaque-local-accessor-call` corpus fixture's `conformancePins`
10
+ * entries, exercised against real PHP/Blade, Ruby/ERB, Python/Jinja2,
11
+ * Rust/minijinja, Perl/Mojolicious, Java/Pebble, PHP/Twig, Perl/Xslate and
12
+ * Go rendering. This file pins the pure classification function itself,
13
+ * built from the real analyzer's `ConstantInfo[]` (via `compileJSX`) rather
14
+ * than hand-built fixtures, so the shape this function actually receives in
15
+ * production is what gets tested.
16
+ */
17
+
18
+ import { describe, test, expect } from 'bun:test'
19
+ import { compileJSX } from '../compiler.ts'
20
+ import { TestAdapter } from '../adapters/test-adapter.ts'
21
+ import { isOpaqueLocalAccessorName } from '../opaque-local-accessor.ts'
22
+ import type { ComponentIR } from '../types.ts'
23
+
24
+ function localConstantsFor(source: string, filePath: string, componentName: string): ComponentIR['metadata']['localConstants'] {
25
+ const result = compileJSX(source, filePath, { adapter: new TestAdapter(), outputIR: true })
26
+ expect(result.errors).toEqual([])
27
+ const irFile = result.files.find(
28
+ (f) => f.type === 'ir' && f.path.includes(`.${componentName}.ir.json`),
29
+ ) ?? result.files.find((f) => f.type === 'ir')
30
+ expect(irFile).toBeDefined()
31
+ const ir = JSON.parse(irFile!.content) as ComponentIR
32
+ return ir.metadata.localConstants
33
+ }
34
+
35
+ describe('isOpaqueLocalAccessorName', () => {
36
+ test('true for a component-body const bound to an opaque call', () => {
37
+ const localConstants = localConstantsFor(
38
+ `
39
+ 'use client'
40
+ import { createSignal } from '@barefootjs/client'
41
+ function makeLabel() { return () => 'ready' }
42
+ export function Widget() {
43
+ const [count] = createSignal(0)
44
+ const label = makeLabel()
45
+ return <div><span>{label()}</span><button>{count()}</button></div>
46
+ }
47
+ `,
48
+ 'Widget.tsx',
49
+ 'Widget',
50
+ )
51
+ expect(isOpaqueLocalAccessorName('label', localConstants)).toBe(true)
52
+ })
53
+
54
+ test('false for a plain literal-valued local', () => {
55
+ const localConstants = localConstantsFor(
56
+ `
57
+ export function Widget({ label }: { label: string }) {
58
+ const greeting = 'hi'
59
+ return <div>{greeting}: {label}</div>
60
+ }
61
+ `,
62
+ 'Widget.tsx',
63
+ 'Widget',
64
+ )
65
+ expect(isOpaqueLocalAccessorName('greeting', localConstants)).toBe(false)
66
+ })
67
+
68
+ test('false for a name that names no local constant at all (e.g. a real signal getter)', () => {
69
+ expect(isOpaqueLocalAccessorName('count', [])).toBe(false)
70
+ expect(isOpaqueLocalAccessorName('count', undefined)).toBe(false)
71
+ })
72
+
73
+ test('false for a MODULE-scope const bound to an opaque call (a different, already-handled shape)', () => {
74
+ const localConstants = localConstantsFor(
75
+ `
76
+ 'use client'
77
+ import { createSignal } from '@barefootjs/client'
78
+ function makeLabel() { return () => 'ready' }
79
+ const label = makeLabel()
80
+ export function Widget() {
81
+ const [count] = createSignal(0)
82
+ return <div><span>{label()}</span><button>{count()}</button></div>
83
+ }
84
+ `,
85
+ 'Widget.tsx',
86
+ 'Widget',
87
+ )
88
+ expect(isOpaqueLocalAccessorName('label', localConstants)).toBe(false)
89
+ })
90
+ })
@@ -9,8 +9,10 @@
9
9
  * `Cart#handler:s1:click`). It then joins to the real IR graph (SR4) and runs
10
10
  * the v1 analyses, asserting the end-to-end story holds:
11
11
  *
12
- * an unbatched 3-write click re-runs `total` 5×/turn; a `batch()` would
13
- * collapse 14 effect runs to 5.
12
+ * an unbatched 3-write click re-runs `total` 3×/turn (once per write —
13
+ * glitch-free propagation recomputes it once even though it reads
14
+ * `subtotal` both directly and through `tax`); a `batch()` would collapse
15
+ * 12 effect runs to 5.
14
16
  *
15
17
  * This is the executable proof of the pipeline until the `--scenario` run
16
18
  * driver lands; it also pins the mount-vs-interaction metric split surfaced by
@@ -76,11 +78,12 @@ describe('profiler end-to-end (real substrate)', () => {
76
78
  expect(total).toBeDefined()
77
79
  expect(total.kind).toBe('memo')
78
80
  expect(total.loc!.file).toBe('Cart.tsx')
79
- // The unbatched 3-write turn re-runs `total` 5× — and mount (1 run) is
80
- // excluded, so the per-turn figure is 5.0, not the diluted 3.0.
81
+ // The unbatched 3-write turn re-runs `total` 3× (once per write) — and
82
+ // mount (1 run) is excluded, so the per-turn figure is 3.0, not the
83
+ // diluted 2.0.
81
84
  expect(total.mountRuns).toBe(1)
82
85
  expect(total.turns).toBe(1)
83
- expect(total.runsPerTurn).toBe(5)
86
+ expect(total.runsPerTurn).toBe(3)
84
87
  expect(total.hot).toBe(true)
85
88
 
86
89
  // Every hot subscriber resolved to a real source line.
@@ -94,11 +97,13 @@ describe('profiler end-to-end (real substrate)', () => {
94
97
  const batch = analyzeBatchAdvisor(events)
95
98
  const cand = batch.candidates.find(c => c.turn === 'Cart#handler:s1:click')!
96
99
  expect(cand).toBeDefined()
97
- // 3 unbatched writes cascade the memo chain: 14 effect runs, 5 distinct.
100
+ // 3 unbatched writes cascade the memo chain: qty and price each re-run
101
+ // subtotal, tax, total and both effects (5 each), coupon re-runs total and
102
+ // its effect (2) — 12 runs over 5 distinct subscribers.
98
103
  expect(cand.writes).toBe(3)
99
- expect(cand.totalRuns).toBe(14)
104
+ expect(cand.totalRuns).toBe(12)
100
105
  expect(cand.distinctSubscribers).toBe(5)
101
- expect(cand.savings).toBe(9)
106
+ expect(cand.savings).toBe(7)
102
107
  expect(cand.safety).toBe('unverified')
103
108
  })
104
109
  })
@@ -117,12 +117,13 @@ describe('Destructured props keep their declared types (#2150)', () => {
117
117
  })
118
118
  })
119
119
 
120
- // A non-primitive optional keeps `unknown` (interface{}-based lowering)
121
- // but still reports the type's `?` — the adversarial catalogue derives
122
- // absent points from `optional` alone.
120
+ // A non-primitive optional whose type doesn't resolve (here: an imported
121
+ // element type) keeps `unknown` (interface{}-based lowering) but still
122
+ // reports the type's `?` — the adversarial catalogue derives absent
123
+ // points from `optional` alone.
123
124
  test('marks OPTIONAL non-primitive members optional while keeping unknown type (#2259)', () => {
124
125
  const source = `
125
- type Todo = { id: number }
126
+ import type { Todo } from './todo'
126
127
  type Props = { items?: Todo[] }
127
128
 
128
129
  export function Component({ items }: Props) {
@@ -208,4 +209,78 @@ describe('Destructured props keep their declared types (#2150)', () => {
208
209
  expect(typeOf(ctx, 'handlers')).toEqual({ kind: 'unknown', raw: 'unknown' })
209
210
  expect(typeOf(ctx, 'configs')).toEqual({ kind: 'unknown', raw: 'unknown' })
210
211
  })
212
+
213
+ // A same-file object type referenced BY NAME resolves like its inline
214
+ // spelling — the `props`-object form (`props: { initial: State }`) always
215
+ // kept it; the destructured form declined it to `unknown`.
216
+ test('resolves a member typed by a same-file object type, named element types included', () => {
217
+ const source = `
218
+ type Item = { id: string; label: string }
219
+ interface State { items: Item[]; nextId: number }
220
+
221
+ export function Component({ initial, rows }: { initial: State; rows: Item[] }) {
222
+ return <div>{initial.nextId}{rows.length}</div>
223
+ }
224
+ `
225
+
226
+ const ctx = analyzeComponent(source, 'Component.tsx')
227
+
228
+ expect(typeOf(ctx, 'initial')).toEqual({ kind: 'interface', raw: 'State' })
229
+ expect(typeOf(ctx, 'rows')).toEqual({
230
+ kind: 'array',
231
+ raw: 'Item[]',
232
+ elementType: { kind: 'interface', raw: 'Item' },
233
+ })
234
+ })
235
+
236
+ // The named type is checked through its declaration's members, so the
237
+ // same all-or-nothing rule applies: a union/function leaf, a generic, an
238
+ // `extends` clause, a non-property member, an import, or a recursive
239
+ // reference still declines the whole member.
240
+ test('declines a named type that is not a plain, fully-resolvable same-file object type', () => {
241
+ const source = `
242
+ import type { External } from './external'
243
+ type WithUnion = { kind: 'a' | 'b' }
244
+ type Generic<T> = { value: T }
245
+ interface Base { id: string }
246
+ interface Derived extends Base { label: string }
247
+ interface WithMethod { run(): void }
248
+ type Tree = { children: Tree[] }
249
+
250
+ export function Component({ a, b, c, d, e, f }: {
251
+ a: WithUnion; b: Generic<string>; c: Derived; d: WithMethod; e: External; f: Tree
252
+ }) {
253
+ return <div />
254
+ }
255
+ `
256
+
257
+ const ctx = analyzeComponent(source, 'Component.tsx')
258
+
259
+ for (const name of ['a', 'b', 'c', 'd', 'e', 'f']) {
260
+ expect(typeOf(ctx, name)).toEqual({ kind: 'unknown', raw: 'unknown' })
261
+ }
262
+ })
263
+
264
+ // Interface declaration merging: the type is the union of both blocks,
265
+ // so either half alone can't vouch for it. Declines whichever order the
266
+ // halves come in, rather than admitting on whichever one a walk keeps.
267
+ test('declines a named type declared more than once (interface merging)', () => {
268
+ const merged = (first: string, second: string) => `
269
+ interface State { ${first} }
270
+ interface State { ${second} }
271
+
272
+ export function Component({ initial }: { initial: State }) {
273
+ return <div />
274
+ }
275
+ `
276
+
277
+ for (const source of [
278
+ merged('label: string', "kind: 'a' | 'b'"),
279
+ merged("kind: 'a' | 'b'", 'label: string'),
280
+ merged('label: string', 'count: number'),
281
+ ]) {
282
+ const ctx = analyzeComponent(source, 'Component.tsx')
283
+ expect(typeOf(ctx, 'initial')).toEqual({ kind: 'unknown', raw: 'unknown' })
284
+ }
285
+ })
211
286
  })