@barefootjs/jsx 0.38.0 → 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 (87) 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/jsx-adapter.d.ts.map +1 -1
  4. package/dist/analyzer.d.ts +30 -1
  5. package/dist/analyzer.d.ts.map +1 -1
  6. package/dist/async-action-refusal.d.ts +45 -0
  7. package/dist/async-action-refusal.d.ts.map +1 -0
  8. package/dist/compiler.d.ts.map +1 -1
  9. package/dist/debug.d.ts +61 -5
  10. package/dist/debug.d.ts.map +1 -1
  11. package/dist/errors.d.ts +4 -0
  12. package/dist/errors.d.ts.map +1 -1
  13. package/dist/format-date-refusal.d.ts +2 -6
  14. package/dist/format-date-refusal.d.ts.map +1 -1
  15. package/dist/index.d.ts +2 -2
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +1056 -344
  18. package/dist/ir-to-client-js/build-references.d.ts.map +1 -1
  19. package/dist/ir-to-client-js/collect-elements.d.ts.map +1 -1
  20. package/dist/ir-to-client-js/compute-inlinability.d.ts.map +1 -1
  21. package/dist/ir-to-client-js/compute-scope.d.ts.map +1 -1
  22. package/dist/ir-to-client-js/control-flow/plan/insert.d.ts +2 -0
  23. package/dist/ir-to-client-js/control-flow/plan/insert.d.ts.map +1 -1
  24. package/dist/ir-to-client-js/csr-substitute.d.ts.map +1 -1
  25. package/dist/ir-to-client-js/declaration-sort.d.ts +2 -1
  26. package/dist/ir-to-client-js/declaration-sort.d.ts.map +1 -1
  27. package/dist/ir-to-client-js/emit-module-level.d.ts.map +1 -1
  28. package/dist/ir-to-client-js/emit-registration.d.ts.map +1 -1
  29. package/dist/ir-to-client-js/plan/declaration-emit.d.ts +7 -5
  30. package/dist/ir-to-client-js/plan/declaration-emit.d.ts.map +1 -1
  31. package/dist/ir-to-client-js/prop-handling.d.ts.map +1 -1
  32. package/dist/ir-to-client-js/reactivity.d.ts.map +1 -1
  33. package/dist/ir-to-client-js/types.d.ts +4 -0
  34. package/dist/ir-to-client-js/types.d.ts.map +1 -1
  35. package/dist/ir-to-client-js/utils.d.ts +41 -2
  36. package/dist/ir-to-client-js/utils.d.ts.map +1 -1
  37. package/dist/jsx-to-ir.d.ts.map +1 -1
  38. package/dist/signal-initializer.d.ts +24 -0
  39. package/dist/signal-initializer.d.ts.map +1 -0
  40. package/dist/template-position-walk.d.ts +68 -0
  41. package/dist/template-position-walk.d.ts.map +1 -0
  42. package/dist/types.d.ts +51 -0
  43. package/dist/types.d.ts.map +1 -1
  44. package/package.json +2 -2
  45. package/src/__tests__/__snapshots__/doc-examples.test.ts.snap +191 -1
  46. package/src/__tests__/action-accessor.test.ts +166 -0
  47. package/src/__tests__/create-mutation.test.ts +220 -0
  48. package/src/__tests__/create-query.test.ts +644 -0
  49. package/src/__tests__/csr-fragment-root-scope-shape.test.ts +156 -0
  50. package/src/__tests__/debug.test.ts +222 -0
  51. package/src/__tests__/doc-examples.test.ts +66 -3
  52. package/src/__tests__/props-destructuring.test.ts +79 -4
  53. package/src/__tests__/reactive-factory-arity.test.ts +311 -0
  54. package/src/__tests__/ssr-portal-ref-callback.test.ts +5 -3
  55. package/src/action-accessor.ts +289 -0
  56. package/src/adapters/jsx-adapter.ts +17 -0
  57. package/src/analyzer.ts +558 -33
  58. package/src/async-action-refusal.ts +254 -0
  59. package/src/compiler.ts +3 -0
  60. package/src/debug.ts +318 -103
  61. package/src/errors.ts +39 -0
  62. package/src/format-date-refusal.ts +6 -125
  63. package/src/index.ts +2 -1
  64. package/src/ir-to-client-js/build-references.ts +6 -2
  65. package/src/ir-to-client-js/collect-elements.ts +1 -0
  66. package/src/ir-to-client-js/compute-inlinability.ts +2 -1
  67. package/src/ir-to-client-js/compute-scope.ts +3 -1
  68. package/src/ir-to-client-js/control-flow/plan/build-insert.ts +1 -0
  69. package/src/ir-to-client-js/control-flow/plan/insert.ts +2 -0
  70. package/src/ir-to-client-js/control-flow/stringify/insert.ts +1 -1
  71. package/src/ir-to-client-js/csr-substitute.ts +11 -3
  72. package/src/ir-to-client-js/declaration-sort.ts +7 -3
  73. package/src/ir-to-client-js/emit-module-level.ts +7 -4
  74. package/src/ir-to-client-js/emit-registration.ts +5 -10
  75. package/src/ir-to-client-js/index.ts +7 -2
  76. package/src/ir-to-client-js/phases/ref-callbacks.ts +1 -1
  77. package/src/ir-to-client-js/plan/build-declaration-emit.ts +16 -15
  78. package/src/ir-to-client-js/plan/declaration-emit.ts +7 -5
  79. package/src/ir-to-client-js/prop-handling.ts +4 -0
  80. package/src/ir-to-client-js/reactivity.ts +1 -0
  81. package/src/ir-to-client-js/stringify/declaration-emit.ts +14 -7
  82. package/src/ir-to-client-js/types.ts +4 -0
  83. package/src/ir-to-client-js/utils.ts +55 -7
  84. package/src/jsx-to-ir.ts +36 -2
  85. package/src/signal-initializer.ts +36 -0
  86. package/src/template-position-walk.ts +203 -0
  87. package/src/types.ts +52 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barefootjs/jsx",
3
- "version": "0.38.0",
3
+ "version": "0.39.0",
4
4
  "description": "JSX compiler for BarefootJS - transforms JSX to server HTML + client JS",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -49,7 +49,7 @@
49
49
  "directory": "packages/jsx"
50
50
  },
51
51
  "dependencies": {
52
- "@barefootjs/shared": "0.38.0"
52
+ "@barefootjs/shared": "0.39.0"
53
53
  },
54
54
  "peerDependencies": {
55
55
  "@barefootjs/client": ">=0.2.0",
@@ -1103,6 +1103,196 @@ hydrate('StatementExample', { init: initStatementExample, template: (_p) => \`<d
1103
1103
  export function StatementExample(_p, __bfKey) { return createComponent('StatementExample', _p, __bfKey) }"
1104
1104
  `;
1105
1105
 
1106
+ exports[`docs/core/reactivity/create-query.md doc-examples L25 — (no label) 1`] = `
1107
+ "import { $, createComponent, createEffect, createQuery, createSignal, escapeAttr, escapeText, http, hydrate, insert, lazySlots, mapArrayLazy, textOrNode } from '@barefootjs/client/runtime'
1108
+
1109
+
1110
+ export function initPostList(__scope, _p = {}) {
1111
+ if (!__scope) return
1112
+ const __scopeId = __scope.getAttribute('bf-s')
1113
+
1114
+ const [page, setPage] = createSignal(1)
1115
+ const [posts, fetchPosts] = createQuery(() => http.get('/api/posts', { page: page() }), { initial: _p.posts })
1116
+
1117
+ const [_s3, _s0, _s2, _s4] = $(__scope, 's3', 's0', 's2', 's4')
1118
+
1119
+ { const __l = []
1120
+ createEffect(() => {
1121
+ if (_s4) {
1122
+ { const __x = fetchPosts.isPending()
1123
+ if (!(0 in __l) || !Object.is(__l[0], __x)) {
1124
+ { const __v = __x; if (__v != null) _s4.setAttribute('aria-busy', String(__v)); else _s4.removeAttribute('aria-busy') }
1125
+ }
1126
+ __l[0] = __x }
1127
+ }
1128
+ }) }
1129
+
1130
+ insert(__scope, 's0', () => fetchPosts.error(), {
1131
+ template: () => { const __slots = []; return { html: \`<p bf-c="s0" role="alert">Failed to load</p>\`, slots: __slots } },
1132
+ bindEvents: (__branchScope, { isFirstRun: __bfFirstRun = false } = {}) => {
1133
+ }
1134
+ }, {
1135
+ template: () => { const __slots = []; return { html: \`<!--bf-cond-start:s0--><!--bf-cond-end:s0-->\`, slots: __slots } },
1136
+ bindEvents: (__branchScope, { isFirstRun: __bfFirstRun = false } = {}) => {
1137
+ }
1138
+ })
1139
+
1140
+ if (_s3) _s3.addEventListener('click', () => { setPage(page() + 1) })
1141
+ const __tpl_l0 = document.createElement('template')
1142
+ __tpl_l0.innerHTML = \`<li data-key=""><!--bf:s1--><!--/--></li>\`
1143
+ const __lzp_l0 = [[0]]
1144
+ const __lzs_l0 = [{ id: 's1', kind: 'text', path: [] }]
1145
+ const __lzsc_l0 = [{ id: 's1', kind: 'text', path: __lzp_l0[0] }]
1146
+ mapArrayLazy(() => posts(), _s2, (post) => String(post.id), {
1147
+ createRow: (__e, __idx) => {
1148
+ const post = () => __e.item
1149
+ const __el = __tpl_l0.content.firstElementChild.cloneNode(true)
1150
+ const __r = __e.refs = [lazySlots(__el, __lzsc_l0)]
1151
+ const __l = __e.last = []
1152
+ { const __x = post().title
1153
+ __r[0]('s1', textOrNode(__x))
1154
+ __l[0] = __x }
1155
+ return __el
1156
+ },
1157
+ applyItem: (__e) => {
1158
+ const post = () => __e.item
1159
+ const __r = __e.refs ?? (__e.refs = [])
1160
+ const __l = __e.last ?? (__e.last = [])
1161
+ const __d = __r[0] ?? (__r[0] = lazySlots(__e.primaryEl, __lzs_l0))
1162
+ { const __x = post().title
1163
+ if (!(0 in __l) || !Object.is(__l[0], __x)) __d('s1', textOrNode(__x))
1164
+ __l[0] = __x }
1165
+ },
1166
+ }, 'l0')
1167
+
1168
+ }
1169
+
1170
+ hydrate('PostList', { init: initPostList, template: (_p) => \`<div \${(false) != null ? 'aria-busy="' + escapeAttr(false) + '"' : ''} bf="s4">\${undefined ? \`<p bf-c="s0" role="alert">Failed to load</p>\` : \`<!--bf-cond-start:s0--><!--bf-cond-end:s0-->\`}<ul bf="s2"><!--bf-loop:l0-->\${(_p.posts).map((post) => \`<li data-key="\${escapeAttr(post.id)}"><!--bf:s1-->\${escapeText(post.title)}<!--/--></li>\`).join('')}<!--bf-/loop:l0--></ul><button bf="s3">Next page</button></div>\` })
1171
+ export function PostList(_p, __bfKey) { return createComponent('PostList', _p, __bfKey) }"
1172
+ `;
1173
+
1174
+ exports[`docs/core/reactivity/create-query.md doc-examples L64 — (no label) 1`] = `
1175
+ "import { $, $c, __bfSlot, createComponent, createDisposableEffect, createQuery, escapeAttr, escapeText, http, hydrate, initChild, insert, lazySlots, mapArrayLazy, renderChild, textOrNode } from '@barefootjs/client/runtime'
1176
+ import '/* @bf-child:Skeleton */'
1177
+
1178
+
1179
+ export function initFeed(__scope, _p = {}) {
1180
+ if (!__scope) return
1181
+ const __scopeId = __scope.getAttribute('bf-s')
1182
+
1183
+ const [posts] = createQuery(() => http.get('/api/posts'), { initial: _p.posts })
1184
+
1185
+ const [_s0] = $(__scope, 's0')
1186
+
1187
+ insert(__scope, 's0', () => !posts(), {
1188
+ template: () => { const __slots = []; return { html: \`<!--bf-cond-start:s0-->\${renderChild('Skeleton', {}, undefined, 's1')}<!--bf-cond-end:s0-->\`, slots: __slots } },
1189
+ bindEvents: (__branchScope, { isFirstRun: __bfFirstRun = false } = {}) => {
1190
+ const [__c0] = $c(__branchScope, 's1')
1191
+ if (__c0) initChild('Skeleton', __c0, {})
1192
+ }
1193
+ }, {
1194
+ template: () => { const __slots = []; return { html: \`<ul bf-c="s0" bf="s3"><!--bf-loop:l0-->\${posts().map((p) => \`<li data-key="\${escapeAttr(p.id)}"><!--bf:s2-->\${__bfSlot(p.title, __slots)}<!--/--></li>\`).join('')}<!--bf-/loop:l0--></ul>\`, slots: __slots } },
1195
+ bindEvents: (__branchScope, { isFirstRun: __bfFirstRun = false } = {}) => {
1196
+ const __disposers = []
1197
+ const [__loop_s3] = $(__branchScope, 's3')
1198
+ __disposers.push(createDisposableEffect(() => {
1199
+ const __lzs_l0 = [{ id: 's2', kind: 'text', path: [] }]
1200
+ if (__loop_s3) mapArrayLazy(() => posts(), __loop_s3, (p) => String(p.id), {
1201
+ createRow: (__e, __idx) => {
1202
+ const p = () => __e.item
1203
+ const __el = (() => { const __tpl = document.createElement('template'); __tpl.innerHTML = \`<li data-key="\${escapeAttr(p().id)}"><!--bf:s2-->\${escapeText(p().title)}<!--/--></li>\`; return __tpl.content.firstElementChild.cloneNode(true) })()
1204
+ const __r = __e.refs = [lazySlots(__el, __lzs_l0)]
1205
+ const __l = __e.last = []
1206
+ { const __x = p().title
1207
+ __r[0]('s2', textOrNode(__x))
1208
+ __l[0] = __x }
1209
+ return __el
1210
+ },
1211
+ applyItem: (__e) => {
1212
+ const p = () => __e.item
1213
+ const __r = __e.refs ?? (__e.refs = [])
1214
+ const __l = __e.last ?? (__e.last = [])
1215
+ const __d = __r[0] ?? (__r[0] = lazySlots(__e.primaryEl, __lzs_l0))
1216
+ { const __x = p().title
1217
+ if (!(0 in __l) || !Object.is(__l[0], __x)) __d('s2', textOrNode(__x))
1218
+ __l[0] = __x }
1219
+ },
1220
+ }, 'l0')
1221
+ }))
1222
+ return () => __disposers.forEach(d => d())
1223
+ }
1224
+ })
1225
+
1226
+ }
1227
+
1228
+ hydrate('Feed', { init: initFeed, template: (_p) => \`<div style="display:contents">\${!(_p.posts) ? \`<!--bf-cond-start:s0-->\${renderChild('Skeleton', {}, undefined, 's1')}<!--bf-cond-end:s0-->\` : \`<ul bf-c="s0" bf="s3"><!--bf-loop:l0-->\${(_p.posts).map((p) => \`<li data-key="\${escapeAttr(p.id)}"><!--bf:s2-->\${escapeText(p.title)}<!--/--></li>\`).join('')}<!--bf-/loop:l0--></ul>\`}</div>\` })
1229
+ export function Feed(_p, __bfKey) { return createComponent('Feed', _p, __bfKey) }"
1230
+ `;
1231
+
1232
+ exports[`docs/core/reactivity/create-mutation.md doc-examples L25 — (no label) 1`] = `
1233
+ "import { $, createComponent, createEffect, createMutation, createSignal, escapeAttr, http, hydrate, insert } from '@barefootjs/client/runtime'
1234
+
1235
+
1236
+ export function initCommentForm(__scope, _p = {}) {
1237
+ if (!__scope) return
1238
+ const __scopeId = __scope.getAttribute('bf-s')
1239
+
1240
+ const [text, setText] = createSignal('')
1241
+ const [saved, save] = createMutation(() => http.post(\`/api/posts/\${_p.postId}/comments\`, { text: text() }), { invalidates: ['/api/posts'] })
1242
+
1243
+ const [_s1, _s2, _s0, _s3] = $(__scope, 's1', 's2', 's0', 's3')
1244
+
1245
+ { const __l = []
1246
+ createEffect(() => {
1247
+ if (_s1) {
1248
+ { const __x = text()
1249
+ if (!(0 in __l) || !Object.is(__l[0], __x)) {
1250
+ const __val = String(__x)
1251
+ if ('value' in _s1) { if (_s1.value !== __val) { _s1.value = __val; if (_s1.tagName === 'SELECT' && !_s1.multiple && _s1.size <= 1 && _s1.value !== __val) _s1.selectedIndex = 0 } } else { _s1.setAttribute('value', __val) }
1252
+ }
1253
+ __l[0] = __x }
1254
+ }
1255
+ }) }
1256
+
1257
+ { const __l = []
1258
+ createEffect(() => {
1259
+ if (_s2) {
1260
+ { const __x = save.isPending()
1261
+ if (!(0 in __l) || !Object.is(__l[0], __x)) {
1262
+ _s2.disabled = !!(__x)
1263
+ }
1264
+ __l[0] = __x }
1265
+ }
1266
+ }) }
1267
+
1268
+ insert(__scope, 's0', () => save.error(), {
1269
+ template: () => { const __slots = []; return { html: \`<p bf-c="s0" role="alert">Failed to save</p>\`, slots: __slots } },
1270
+ bindEvents: (__branchScope, { isFirstRun: __bfFirstRun = false } = {}) => {
1271
+ }
1272
+ }, {
1273
+ template: () => { const __slots = []; return { html: \`<!--bf-cond-start:s0--><!--bf-cond-end:s0-->\`, slots: __slots } },
1274
+ bindEvents: (__branchScope, { isFirstRun: __bfFirstRun = false } = {}) => {
1275
+ }
1276
+ })
1277
+
1278
+ insert(__scope, 's3', () => saved(), {
1279
+ template: () => { const __slots = []; return { html: \`<p bf-c="s3">Saved</p>\`, slots: __slots } },
1280
+ bindEvents: (__branchScope, { isFirstRun: __bfFirstRun = false } = {}) => {
1281
+ }
1282
+ }, {
1283
+ template: () => { const __slots = []; return { html: \`<!--bf-cond-start:s3--><!--bf-cond-end:s3-->\`, slots: __slots } },
1284
+ bindEvents: (__branchScope, { isFirstRun: __bfFirstRun = false } = {}) => {
1285
+ }
1286
+ })
1287
+
1288
+ if (_s1) _s1.addEventListener('input', (e) => { setText(e.target.value) })
1289
+ if (_s2) _s2.addEventListener('click', () => { save() })
1290
+ }
1291
+
1292
+ hydrate('CommentForm', { init: initCommentForm, template: (_p) => \`<form bf="s4">\${undefined ? \`<p bf-c="s0" role="alert">Failed to save</p>\` : \`<!--bf-cond-start:s0--><!--bf-cond-end:s0-->\`}<input \${(('')) != null ? 'value="' + escapeAttr(('')) + '"' : ''} bf="s1" /><button type="button" \${false ? 'disabled' : ''} bf="s2"> Post </button>\${(undefined) ? \`<p bf-c="s3">Saved</p>\` : \`<!--bf-cond-start:s3--><!--bf-cond-end:s3-->\`}</form>\` })
1293
+ export function CommentForm(_p, __bfKey) { return createComponent('CommentForm', _p, __bfKey) }"
1294
+ `;
1295
+
1106
1296
  exports[`docs/core/reactivity/props-reactivity.md doc-examples L11 — (no label) 1`] = `
1107
1297
  "import { createComponent, createEffect, escapeTextOrMarkup, escapeTextOrNode, hydrate, lazySlots } from '@barefootjs/client/runtime'
1108
1298
 
@@ -1655,7 +1845,7 @@ export function initTooltip(__scope, _p = {}) {
1655
1845
 
1656
1846
  if (_s0) _s0.addEventListener('mouseenter', () => { setVisible(true) })
1657
1847
  if (_s0) _s0.addEventListener('mouseleave', () => { setVisible(false) })
1658
- if (_s2) (handleMount)(_s2)
1848
+ if (_s2) { (handleMount)(_s2); if (__scopeId) _s2.setAttribute('bf-po', __scopeId) }
1659
1849
  }
1660
1850
 
1661
1851
  hydrate('Tooltip', { init: initTooltip, template: (_p) => \`<div><span bf="s0">\${markupOrEmpty(_p.children)}</span><div class="tooltip" bf="s2"><!--bf:s1-->\${escapeTextOrMarkup(_p.text)}<!--/--></div></div>\` })
@@ -0,0 +1,166 @@
1
+ /**
2
+ * Unit tests for the shared recognition/gate/seed module (#3166, part B of
3
+ * #3158). `async-action-refusal.ts` (BF117's refusal-lift) and the seed pass
4
+ * (`seedActionAccessorReads`, run from `jsx-to-ir.ts`) both call the same
5
+ * gate, `seedableActionAccessorRead`, so they can never drift apart.
6
+ * Cross-adapter output and end-to-end compiler behaviour are covered by
7
+ * `create-query.test.ts` and the `create-query-action-read` conformance
8
+ * fixture; this file pins the module's own contract in isolation.
9
+ */
10
+
11
+ import { describe, test, expect } from 'bun:test'
12
+ import {
13
+ matchActionAccessorCall,
14
+ actionAccessorSeedParsed,
15
+ actionAccessorSeedText,
16
+ collectActionNames,
17
+ seedableActionAccessorRead,
18
+ ARIA_BOOLEAN_STATE_ATTRS,
19
+ } from '../action-accessor.ts'
20
+ import { parseExpression } from '../expression-parser.ts'
21
+ import type { TemplatePositionRole } from '../template-position-walk.ts'
22
+ import type { SignalInfo } from '../types.ts'
23
+ import { isAriaBooleanAttr as bladeIsAriaBooleanAttr } from '../../../adapter-blade/src/adapter/boolean-result'
24
+ import { isAriaBooleanAttr as erbIsAriaBooleanAttr } from '../../../adapter-erb/src/adapter/boolean-result'
25
+ import { isAriaBooleanAttr as jinjaIsAriaBooleanAttr } from '../../../adapter-jinja/src/adapter/boolean-result'
26
+ import { isAriaBooleanAttr as mojoIsAriaBooleanAttr } from '../../../adapter-mojolicious/src/adapter/boolean-result'
27
+ import { isAriaBooleanAttr as pebbleIsAriaBooleanAttr } from '../../../adapter-pebble/src/adapter/boolean-result'
28
+ import { isAriaBooleanAttr as rustIsAriaBooleanAttr } from '../../../adapter-rust/src/adapter/boolean-result'
29
+ import { isAriaBooleanAttr as twigIsAriaBooleanAttr } from '../../../adapter-twig/src/adapter/boolean-result'
30
+ import { isAriaBooleanAttr as xslateIsAriaBooleanAttr } from '../../../adapter-xslate/src/adapter/boolean-result'
31
+
32
+ function factorySignal(action: string): Pick<SignalInfo, 'factory'> {
33
+ return { factory: { kind: 'query', callee: 'createQuery', argsText: '', requestText: '', requestFreeIdentifiers: new Set(), action } }
34
+ }
35
+
36
+ describe('collectActionNames', () => {
37
+ test('collects only signals with a recognised factory action', () => {
38
+ const actions = collectActionNames([factorySignal('fetchPosts'), {}, factorySignal('fetchUsers')])
39
+ expect([...actions].sort()).toEqual(['fetchPosts', 'fetchUsers'])
40
+ })
41
+
42
+ test('empty for a component with no async factory', () => {
43
+ expect(collectActionNames([{}, {}]).size).toBe(0)
44
+ })
45
+ })
46
+
47
+ describe('matchActionAccessorCall', () => {
48
+ const actions = new Set(['fetchPosts'])
49
+
50
+ test('matches a direct isPending()/error() call on a recognised action', () => {
51
+ expect(matchActionAccessorCall(parseExpression('fetchPosts.isPending()'), actions))
52
+ .toEqual({ action: 'fetchPosts', accessor: 'isPending' })
53
+ expect(matchActionAccessorCall(parseExpression('fetchPosts.error()'), actions))
54
+ .toEqual({ action: 'fetchPosts', accessor: 'error' })
55
+ })
56
+
57
+ test('rejects an unrecognised object, even with the same accessor name', () => {
58
+ expect(matchActionAccessorCall(parseExpression('otherThing.isPending()'), actions)).toBeNull()
59
+ })
60
+
61
+ test('rejects an accessor name the action does not carry', () => {
62
+ expect(matchActionAccessorCall(parseExpression('fetchPosts.refetch()'), actions)).toBeNull()
63
+ })
64
+
65
+ test('rejects a call with arguments — the real accessors take none', () => {
66
+ expect(matchActionAccessorCall(parseExpression('fetchPosts.isPending(true)'), actions)).toBeNull()
67
+ })
68
+
69
+ test('rejects the uncalled member access — only the CALL is a seeded value', () => {
70
+ expect(matchActionAccessorCall(parseExpression('fetchPosts.isPending'), actions)).toBeNull()
71
+ })
72
+
73
+ test('rejects a computed member access', () => {
74
+ expect(matchActionAccessorCall(parseExpression("fetchPosts['isPending']()"), actions)).toBeNull()
75
+ })
76
+
77
+ test('rejects a compound expression — only the WHOLE expression matches', () => {
78
+ expect(matchActionAccessorCall(parseExpression('!fetchPosts.isPending()'), actions)).toBeNull()
79
+ expect(matchActionAccessorCall(parseExpression('fetchPosts.isPending() && x'), actions)).toBeNull()
80
+ })
81
+
82
+ test('empty actions set matches nothing', () => {
83
+ expect(matchActionAccessorCall(parseExpression('fetchPosts.isPending()'), new Set())).toBeNull()
84
+ })
85
+ })
86
+
87
+ describe('seeds (spec/async.md §7.3)', () => {
88
+ test('actionAccessorSeedParsed is the boolean literal false for both accessors', () => {
89
+ expect(actionAccessorSeedParsed('isPending')).toEqual({ kind: 'literal', value: false, literalType: 'boolean' })
90
+ expect(actionAccessorSeedParsed('error')).toEqual({ kind: 'literal', value: false, literalType: 'boolean' })
91
+ })
92
+
93
+ test('actionAccessorSeedText is JS source text: false / undefined', () => {
94
+ expect(actionAccessorSeedText('isPending')).toBe('false')
95
+ expect(actionAccessorSeedText('error')).toBe('undefined')
96
+ })
97
+ })
98
+
99
+ describe('seedableActionAccessorRead — the one gate for the BF117 lift and the seed', () => {
100
+ const actions = new Set(['fetchPosts'])
101
+ const at = (source: string, role: TemplatePositionRole, attrName?: string) =>
102
+ seedableActionAccessorRead({ expr: parseExpression(source), role, attrName }, actions)
103
+
104
+ test('a condition admits both accessors (truthiness only: false ≡ undefined)', () => {
105
+ expect(at('fetchPosts.isPending()', 'condition')).toEqual({ action: 'fetchPosts', accessor: 'isPending' })
106
+ expect(at('fetchPosts.error()', 'condition')).toEqual({ action: 'fetchPosts', accessor: 'error' })
107
+ })
108
+
109
+ test('an ARIA boolean-state element attribute admits isPending() only', () => {
110
+ expect(at('fetchPosts.isPending()', 'element-attr', 'aria-busy')).toEqual({ action: 'fetchPosts', accessor: 'isPending' })
111
+ expect(at('fetchPosts.isPending()', 'element-attr', 'aria-hidden')).not.toBeNull()
112
+ // Hono omits an `undefined` attribute; the `false` seed would render it.
113
+ expect(at('fetchPosts.error()', 'element-attr', 'aria-busy')).toBeNull()
114
+ })
115
+
116
+ test('an HTML boolean attribute admits isPending() only (#3210)', () => {
117
+ expect(at('fetchPosts.isPending()', 'element-attr', 'disabled')).toEqual({ action: 'fetchPosts', accessor: 'isPending' })
118
+ expect(at('fetchPosts.isPending()', 'element-attr', 'readonly')).not.toBeNull()
119
+ // Only truthiness is observed here, so `error()` would render the same,
120
+ // but it is not a boolean and no fixture covers it: the gate admits only
121
+ // what the conformance corpus pins.
122
+ expect(at('fetchPosts.error()', 'element-attr', 'disabled')).toBeNull()
123
+ })
124
+
125
+ test('any other attribute refuses — Mojolicious / Xslate render the false literal as 0 there', () => {
126
+ expect(at('fetchPosts.isPending()', 'element-attr', 'aria-label')).toBeNull()
127
+ expect(at('fetchPosts.isPending()', 'element-attr', 'title')).toBeNull()
128
+ expect(at('fetchPosts.isPending()', 'element-attr', 'data-pending')).toBeNull()
129
+ expect(at('fetchPosts.error()', 'element-attr', 'title')).toBeNull()
130
+ })
131
+
132
+ test('text, prop, spread, template-part and loop-array positions refuse', () => {
133
+ for (const role of ['text', 'prop', 'spread', 'template-part', 'loop-array'] as const) {
134
+ expect(at('fetchPosts.isPending()', role, role === 'prop' ? 'aria-busy' : undefined)).toBeNull()
135
+ expect(at('fetchPosts.error()', role)).toBeNull()
136
+ }
137
+ })
138
+
139
+ test('an unrecognised or compound read is never admitted, whatever the position', () => {
140
+ expect(at('other.isPending()', 'condition')).toBeNull()
141
+ expect(at('!fetchPosts.isPending()', 'condition')).toBeNull()
142
+ expect(at('other.isPending()', 'element-attr', 'aria-busy')).toBeNull()
143
+ })
144
+ })
145
+
146
+ describe('ARIA_BOOLEAN_STATE_ATTRS agrees with every DSL adapter', () => {
147
+ // The seed renders `aria-x={false}` as `aria-x="false"` (Hono's output) only
148
+ // where the adapter stringifies a boolean JS-style; outside its own
149
+ // `isAriaBooleanAttr` set, Mojolicious / Xslate render the literal as `0`.
150
+ // Go renders `{{false}}` as `false` on every attribute, so it has no set.
151
+ const adapters: Array<[string, (name: string) => boolean]> = [
152
+ ['blade', bladeIsAriaBooleanAttr],
153
+ ['erb', erbIsAriaBooleanAttr],
154
+ ['jinja', jinjaIsAriaBooleanAttr],
155
+ ['mojolicious', mojoIsAriaBooleanAttr],
156
+ ['pebble', pebbleIsAriaBooleanAttr],
157
+ ['rust', rustIsAriaBooleanAttr],
158
+ ['twig', twigIsAriaBooleanAttr],
159
+ ['xslate', xslateIsAriaBooleanAttr],
160
+ ]
161
+ for (const [adapter, isAriaBooleanAttr] of adapters) {
162
+ test(`${adapter} stringifies every gated attribute as a boolean`, () => {
163
+ expect([...ARIA_BOOLEAN_STATE_ATTRS].filter((name) => !isAriaBooleanAttr(name))).toEqual([])
164
+ })
165
+ }
166
+ })
@@ -0,0 +1,220 @@
1
+ /**
2
+ * `createMutation` recognition (#3210): the value is collected as a signal
3
+ * seeded `undefined` (a mutation has no `initial`, spec/async.md §7.4), the
4
+ * request function is emitted into the client JS only and never wrapped in
5
+ * anything that tracks, and the action's `isPending()` / `error()` seed
6
+ * through the same gate as a query's (`action-accessor.ts`, #3166).
7
+ * Cross-adapter output lives in the `create-mutation-*` conformance fixtures;
8
+ * this file pins the compiler-internal decisions.
9
+ */
10
+
11
+ import { describe, test, expect } from 'bun:test'
12
+ import { compileJSX } from '../compiler'
13
+ import { TestAdapter } from '../adapters/test-adapter'
14
+ import { HonoAdapter } from '../../../adapter-hono/src/adapter/hono-adapter'
15
+ import { GoTemplateAdapter } from '../../../adapter-go-template/src/index'
16
+ import { BladeAdapter } from '../../../adapter-blade/src/index'
17
+ import { ErbAdapter } from '../../../adapter-erb/src/index'
18
+ import { JinjaAdapter } from '../../../adapter-jinja/src/index'
19
+ import { MojoAdapter } from '../../../adapter-mojolicious/src/index'
20
+ import { PebbleAdapter } from '../../../adapter-pebble/src/index'
21
+ import { MinijinjaAdapter } from '../../../adapter-rust/src/index'
22
+ import { TwigAdapter } from '../../../adapter-twig/src/index'
23
+ import { XslateAdapter } from '../../../adapter-xslate/src/index'
24
+ import { extractInitBody, extractTemplateBody } from './staged-ir/helpers'
25
+
26
+ function compile(source: string, options: { adapter?: 'test' | 'hono' | 'go' } = {}) {
27
+ const adapter =
28
+ options.adapter === 'hono' ? new HonoAdapter() : options.adapter === 'go' ? new GoTemplateAdapter() : new TestAdapter()
29
+ const result = compileJSX(source, 'Component.tsx', { adapter })
30
+ const clientJs = result.files.find((f) => f.type === 'clientJs')?.content ?? ''
31
+ const ssr = result.files.find((f) => f.type === 'markedTemplate')?.content ?? ''
32
+ return {
33
+ codes: result.errors.map((e) => e.code),
34
+ errors: result.errors,
35
+ clientJs,
36
+ initBody: extractInitBody(clientJs),
37
+ templateBody: extractTemplateBody(clientJs),
38
+ ssr,
39
+ }
40
+ }
41
+
42
+ const FORM = `
43
+ 'use client'
44
+ import { createMutation, createSignal, http } from '@barefootjs/client'
45
+ export function CommentForm(props: { postId: number }) {
46
+ const [text, setText] = createSignal('')
47
+ const [saved, save] = createMutation(() => http.post('/api/posts/' + props.postId + '/comments', { body: { text: text() } }), { invalidates: ['/api/posts'] })
48
+ return (
49
+ <form>
50
+ {save.error() ? <p>Failed</p> : null}
51
+ {saved() ? <p>Saved</p> : null}
52
+ <input value={text()} onInput={(e) => setText(e.target.value)} />
53
+ <button disabled={save.isPending()} onClick={() => save()}>Send</button>
54
+ </form>
55
+ )
56
+ }
57
+ `
58
+
59
+ describe('createMutation value and client JS (#3210)', () => {
60
+ test('emits the factory call verbatim with props read live and `invalidates` unchanged', () => {
61
+ const { codes, initBody } = compile(FORM)
62
+ expect(codes).toEqual([])
63
+ expect(initBody).toContain(
64
+ "const [saved, save] = createMutation(() => http.post('/api/posts/' + _p.postId + '/comments', { body: { text: text() } }), { invalidates: ['/api/posts'] })",
65
+ )
66
+ })
67
+
68
+ test('the request function is not wrapped in anything that tracks', () => {
69
+ const { initBody } = compile(FORM)
70
+ // The only occurrence of the request is the factory call's own argument:
71
+ // no effect, memo or signal initializer re-emits it.
72
+ expect(initBody.split("http.post('/api/posts/'").length - 1).toBe(1)
73
+ const effectBodies = initBody.split('createEffect(').slice(1)
74
+ for (const body of effectBodies) expect(body.split('\n')[0]).not.toContain('http.post')
75
+ expect(initBody).not.toContain('createSignal(undefined)')
76
+ })
77
+
78
+ test('the CSR template seeds the value undefined and never reads the request function', () => {
79
+ const { templateBody } = compile(FORM)
80
+ expect(templateBody).not.toContain('http.post')
81
+ expect(templateBody).toContain('${undefined ?')
82
+ })
83
+
84
+ test('Hono SSR seeds the value undefined, stubs the action, and never emits the request function', () => {
85
+ const { codes, ssr } = compile(FORM, { adapter: 'hono' })
86
+ expect(codes).toEqual([])
87
+ expect(ssr).toContain('const saved = () => undefined')
88
+ expect(ssr).toContain('const save: any = Object.assign(() => {}, { isPending: () => false, error: () => undefined })')
89
+ expect(ssr).not.toContain('http.post')
90
+ // A prop read only by the request function still reaches the client.
91
+ expect(ssr).toContain("__hydrateProps['postId'] = props.postId")
92
+ })
93
+
94
+ test('the value-elided form keeps just the action', () => {
95
+ const { codes, initBody } = compile(`
96
+ 'use client'
97
+ import { createMutation, http } from '@barefootjs/client'
98
+ export function C() {
99
+ const [, send] = createMutation(() => http.post('/api/ping'))
100
+ return <button onClick={() => send()}>ping</button>
101
+ }
102
+ `)
103
+ expect(codes).toEqual([])
104
+ expect(initBody).toContain("const [, send] = createMutation(() => http.post('/api/ping'))")
105
+ })
106
+ })
107
+
108
+ describe('createMutation action accessors (#3210, via #3166)', () => {
109
+ test('disabled={save.isPending()} and an error condition are seeded in DSL output', () => {
110
+ const { codes, ssr } = compile(FORM, { adapter: 'go' })
111
+ expect(codes).toEqual([])
112
+ expect(ssr).not.toContain('IsPending')
113
+ expect(ssr).not.toContain('.Save.')
114
+ expect(ssr).toContain('<button {{if false}}disabled{{end}}')
115
+ expect(ssr).toContain('{{if false}}<p bf-c="s0">Failed</p>')
116
+ })
117
+
118
+ // The shared fixture compares rendered HTML, and a DSL adapter that re-parses
119
+ // the raw `save.isPending()` reads an undeclared `save`, which every engine
120
+ // treats as falsy — the same HTML. So check the template text itself: no
121
+ // adapter may emit a reference to the action or its accessor.
122
+ test('every DSL adapter lowers the seed, never the accessor read', () => {
123
+ const adapters = [
124
+ new GoTemplateAdapter(),
125
+ new ErbAdapter(),
126
+ new MojoAdapter(),
127
+ new JinjaAdapter(),
128
+ new TwigAdapter(),
129
+ new XslateAdapter(),
130
+ new BladeAdapter(),
131
+ new MinijinjaAdapter(),
132
+ new PebbleAdapter(),
133
+ ]
134
+ for (const adapter of adapters) {
135
+ const result = compileJSX(FORM, 'Component.tsx', { adapter })
136
+ const ssr = result.files.find((f) => f.type === 'markedTemplate')?.content ?? ''
137
+ expect({ adapter: adapter.name, codes: result.errors.map((e) => e.code) }).toEqual({ adapter: adapter.name, codes: [] })
138
+ expect({ adapter: adapter.name, leaks: /isPending|IsPending|is_pending|\bsave\b|\bSave\b/.test(ssr) }).toEqual({
139
+ adapter: adapter.name,
140
+ leaks: false,
141
+ })
142
+ }
143
+ })
144
+
145
+ test('a read the gate does not admit still refuses with BF117', () => {
146
+ for (const markup of ['<p>{save.error()}</p>', '<p title={save.isPending()}>x</p>', '<button disabled={save.error()}>x</button>']) {
147
+ const { codes } = compile(`
148
+ 'use client'
149
+ import { createMutation, http } from '@barefootjs/client'
150
+ export function C() {
151
+ const [, save] = createMutation(() => http.post('/api/ping'))
152
+ return <div>${markup}</div>
153
+ }
154
+ `)
155
+ expect(codes).toContain('BF117')
156
+ }
157
+ })
158
+ })
159
+
160
+ describe('createMutation arity (BF115 / BF116)', () => {
161
+ test('a two-argument call and a two-element destructure are accepted', () => {
162
+ expect(compile(FORM).codes).toEqual([])
163
+ })
164
+
165
+ test('a three-element destructure is BF115', () => {
166
+ const { codes } = compile(`
167
+ 'use client'
168
+ import { createMutation, http } from '@barefootjs/client'
169
+ export function C() {
170
+ const [a, b, c] = createMutation(() => http.post('/api/items'))
171
+ return <p>{a() ? 'y' : 'n'}</p>
172
+ }
173
+ `)
174
+ expect(codes).toContain('BF115')
175
+ })
176
+
177
+ test('a third argument is BF116', () => {
178
+ const { codes } = compile(`
179
+ 'use client'
180
+ import { createMutation, http } from '@barefootjs/client'
181
+ export function C() {
182
+ const [a] = createMutation(() => http.post('/api/items'), {}, 'extra')
183
+ return <p>{a() ? 'y' : 'n'}</p>
184
+ }
185
+ `)
186
+ expect(codes).toContain('BF116')
187
+ })
188
+ })
189
+
190
+ describe('createMutation `initial` is refused (BF118)', () => {
191
+ const withOptions = (options: string, params = '') => `
192
+ 'use client'
193
+ import { createMutation, http } from '@barefootjs/client'
194
+ export function C(${params}) {
195
+ const [saved, save] = createMutation(() => http.post('/api/items'), ${options})
196
+ return <button onClick={() => save()}>{saved() ? 'saved' : 'save'}</button>
197
+ }
198
+ `
199
+
200
+ test('an `initial` key names createQuery as the factory that takes it', () => {
201
+ const { codes, errors } = compile(withOptions("{ initial: 'x', invalidates: ['/api'] }"))
202
+ expect(codes).toEqual(['BF118'])
203
+ expect(errors[0].message).toContain("Use 'createQuery'")
204
+ })
205
+
206
+ test('a shorthand `initial` is refused too', () => {
207
+ const { codes } = compile(withOptions('{ initial }', '{ initial }: { initial?: string }'))
208
+ expect(codes).toEqual(['BF118'])
209
+ })
210
+
211
+ test('options without `initial`, or that cannot be read structurally, are accepted', () => {
212
+ expect(compile(withOptions("{ invalidates: ['/api'] }")).codes).toEqual([])
213
+ expect(compile(withOptions('{ ...props.opts }', 'props: { opts: {} }')).codes).toEqual([])
214
+ })
215
+
216
+ test('the refused `initial` never seeds the value', () => {
217
+ const { ssr } = compile(withOptions("{ initial: 'x' }"), { adapter: 'hono' })
218
+ expect(ssr).toContain('const saved = () => undefined')
219
+ })
220
+ })