@barefootjs/jsx 0.38.0 → 0.39.1

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 (105) 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/interface.d.ts +19 -0
  4. package/dist/adapters/interface.d.ts.map +1 -1
  5. package/dist/adapters/jsx-adapter.d.ts.map +1 -1
  6. package/dist/analyzer.d.ts +49 -1
  7. package/dist/analyzer.d.ts.map +1 -1
  8. package/dist/async-action-refusal.d.ts +45 -0
  9. package/dist/async-action-refusal.d.ts.map +1 -0
  10. package/dist/compiler.d.ts.map +1 -1
  11. package/dist/debug.d.ts +61 -5
  12. package/dist/debug.d.ts.map +1 -1
  13. package/dist/errors.d.ts +4 -0
  14. package/dist/errors.d.ts.map +1 -1
  15. package/dist/format-date-refusal.d.ts +2 -6
  16. package/dist/format-date-refusal.d.ts.map +1 -1
  17. package/dist/html-types.d.ts +5 -0
  18. package/dist/html-types.d.ts.map +1 -1
  19. package/dist/index.d.ts +3 -2
  20. package/dist/index.d.ts.map +1 -1
  21. package/dist/index.js +1261 -422
  22. package/dist/ir-to-client-js/build-references.d.ts.map +1 -1
  23. package/dist/ir-to-client-js/collect-elements.d.ts +17 -1
  24. package/dist/ir-to-client-js/collect-elements.d.ts.map +1 -1
  25. package/dist/ir-to-client-js/compute-inlinability.d.ts.map +1 -1
  26. package/dist/ir-to-client-js/compute-scope.d.ts.map +1 -1
  27. package/dist/ir-to-client-js/control-flow/plan/insert.d.ts +2 -0
  28. package/dist/ir-to-client-js/control-flow/plan/insert.d.ts.map +1 -1
  29. package/dist/ir-to-client-js/csr-substitute.d.ts.map +1 -1
  30. package/dist/ir-to-client-js/declaration-sort.d.ts +2 -1
  31. package/dist/ir-to-client-js/declaration-sort.d.ts.map +1 -1
  32. package/dist/ir-to-client-js/emit-module-level.d.ts.map +1 -1
  33. package/dist/ir-to-client-js/emit-registration.d.ts.map +1 -1
  34. package/dist/ir-to-client-js/plan/declaration-emit.d.ts +7 -5
  35. package/dist/ir-to-client-js/plan/declaration-emit.d.ts.map +1 -1
  36. package/dist/ir-to-client-js/prop-handling.d.ts.map +1 -1
  37. package/dist/ir-to-client-js/reactivity.d.ts +10 -2
  38. package/dist/ir-to-client-js/reactivity.d.ts.map +1 -1
  39. package/dist/ir-to-client-js/types.d.ts +4 -0
  40. package/dist/ir-to-client-js/types.d.ts.map +1 -1
  41. package/dist/ir-to-client-js/utils.d.ts +52 -9
  42. package/dist/ir-to-client-js/utils.d.ts.map +1 -1
  43. package/dist/jsx-to-ir.d.ts.map +1 -1
  44. package/dist/signal-initializer.d.ts +24 -0
  45. package/dist/signal-initializer.d.ts.map +1 -0
  46. package/dist/ssr-defaults.d.ts.map +1 -1
  47. package/dist/ssr-seed-plan.d.ts.map +1 -1
  48. package/dist/template-position-walk.d.ts +68 -0
  49. package/dist/template-position-walk.d.ts.map +1 -0
  50. package/dist/types.d.ts +95 -0
  51. package/dist/types.d.ts.map +1 -1
  52. package/package.json +2 -2
  53. package/src/__tests__/__snapshots__/doc-examples.test.ts.snap +194 -4
  54. package/src/__tests__/action-accessor.test.ts +166 -0
  55. package/src/__tests__/adapter-output.test.ts +142 -0
  56. package/src/__tests__/create-mutation.test.ts +250 -0
  57. package/src/__tests__/create-query.test.ts +696 -0
  58. package/src/__tests__/csr-fragment-root-scope-shape.test.ts +156 -0
  59. package/src/__tests__/debug.test.ts +305 -0
  60. package/src/__tests__/doc-examples.test.ts +66 -3
  61. package/src/__tests__/ir-fragment-transparency.test.ts +23 -0
  62. package/src/__tests__/issue-3240-nested-static-map-event-delegation.test.ts +245 -0
  63. package/src/__tests__/jsx-text-linebreak-whitespace.test.ts +80 -0
  64. package/src/__tests__/loop-param-accessor-key-member-safety.test.ts +445 -0
  65. package/src/__tests__/props-destructuring.test.ts +79 -4
  66. package/src/__tests__/reactive-factory-arity.test.ts +311 -0
  67. package/src/__tests__/ssr-portal-ref-callback.test.ts +5 -3
  68. package/src/action-accessor.ts +289 -0
  69. package/src/adapters/interface.ts +19 -0
  70. package/src/adapters/jsx-adapter.ts +47 -20
  71. package/src/analyzer.ts +593 -44
  72. package/src/async-action-refusal.ts +254 -0
  73. package/src/compiler.ts +81 -46
  74. package/src/debug.ts +351 -104
  75. package/src/errors.ts +39 -0
  76. package/src/format-date-refusal.ts +6 -125
  77. package/src/html-types.ts +14 -0
  78. package/src/index.ts +3 -1
  79. package/src/ir-to-client-js/build-references.ts +6 -2
  80. package/src/ir-to-client-js/collect-elements.ts +65 -4
  81. package/src/ir-to-client-js/compute-inlinability.ts +2 -1
  82. package/src/ir-to-client-js/compute-scope.ts +3 -1
  83. package/src/ir-to-client-js/control-flow/plan/build-insert.ts +1 -0
  84. package/src/ir-to-client-js/control-flow/plan/insert.ts +2 -0
  85. package/src/ir-to-client-js/control-flow/stringify/event-delegation.ts +112 -3
  86. package/src/ir-to-client-js/control-flow/stringify/insert.ts +1 -1
  87. package/src/ir-to-client-js/csr-substitute.ts +11 -3
  88. package/src/ir-to-client-js/declaration-sort.ts +7 -3
  89. package/src/ir-to-client-js/emit-module-level.ts +7 -4
  90. package/src/ir-to-client-js/emit-registration.ts +5 -10
  91. package/src/ir-to-client-js/index.ts +7 -2
  92. package/src/ir-to-client-js/phases/ref-callbacks.ts +1 -1
  93. package/src/ir-to-client-js/plan/build-declaration-emit.ts +16 -15
  94. package/src/ir-to-client-js/plan/declaration-emit.ts +7 -5
  95. package/src/ir-to-client-js/prop-handling.ts +4 -0
  96. package/src/ir-to-client-js/reactivity.ts +32 -1
  97. package/src/ir-to-client-js/stringify/declaration-emit.ts +14 -7
  98. package/src/ir-to-client-js/types.ts +4 -0
  99. package/src/ir-to-client-js/utils.ts +184 -21
  100. package/src/jsx-to-ir.ts +111 -14
  101. package/src/signal-initializer.ts +36 -0
  102. package/src/ssr-defaults.ts +10 -0
  103. package/src/ssr-seed-plan.ts +12 -1
  104. package/src/template-position-walk.ts +203 -0
  105. package/src/types.ts +99 -0
@@ -9,10 +9,65 @@ import { describe, test, expect } from 'bun:test'
9
9
  import { compileJSX } from '../compiler'
10
10
  import { TestAdapter } from '../adapters/test-adapter'
11
11
  import { HonoAdapter } from '../../../../packages/adapter-hono/src/adapter/hono-adapter'
12
+ import { BaseAdapter } from '../adapters/interface'
13
+ import type { AdapterOutput, TemplateSections } from '../adapters/interface'
12
14
  import { resolve, dirname } from 'node:path'
13
15
 
14
16
  const adapter = new TestAdapter()
15
17
 
18
+ // Minimal stand-in for `@barefootjs/client`'s `CSRAdapter` — same shape
19
+ // (empty `generate()`, `emitsTemplates: false`) without pulling in the
20
+ // `@barefootjs/client` package, which `packages/jsx` does not (and must
21
+ // not) depend on. See `CSRAdapter`'s docstring for the full contract this
22
+ // mirrors.
23
+ const EMPTY_SECTIONS: TemplateSections = Object.freeze({
24
+ imports: '',
25
+ types: '',
26
+ component: '',
27
+ defaultExport: '',
28
+ })
29
+ const EMPTY_OUTPUT: AdapterOutput = Object.freeze({
30
+ template: '',
31
+ sections: EMPTY_SECTIONS,
32
+ extension: '.tsx',
33
+ })
34
+ class EmptyNoTemplateAdapter extends BaseAdapter {
35
+ name = 'empty-no-template'
36
+ extension = '.tsx'
37
+ emitsTemplates = false
38
+ acceptsTemplateCall = (): boolean => true
39
+ generate(): AdapterOutput {
40
+ return EMPTY_OUTPUT
41
+ }
42
+ renderNode(): string { return '' }
43
+ renderElement(): string { return '' }
44
+ renderExpression(): string { return '' }
45
+ renderConditional(): string { return '' }
46
+ renderLoop(): string { return '' }
47
+ renderComponent(): string { return '' }
48
+ renderScopeMarker(): string { return '' }
49
+ renderSlotMarker(): string { return '' }
50
+ renderCondMarker(): string { return '' }
51
+ }
52
+
53
+ // A hypothetical `emitsTemplates: false` adapter whose `generate()` (unlike
54
+ // `CSRAdapter`'s) returns non-empty `sections`. Nothing in the
55
+ // `TemplateAdapter` contract requires an `emitsTemplates: false` adapter's
56
+ // sections to be empty — `emitsTemplates` alone is what's supposed to
57
+ // suppress assembly. Used to pin that `compileMultipleComponents` enforces
58
+ // the same short-circuit as `compileJSX`'s single-component path, not just
59
+ // a `moduleExports`-only skip (#3234).
60
+ class LeakySectionsAdapter extends EmptyNoTemplateAdapter {
61
+ name = 'leaky-sections-no-template'
62
+ generate(): AdapterOutput {
63
+ return {
64
+ template: '',
65
+ sections: { imports: '', types: '', component: 'const LEAKED = 1;', defaultExport: '' },
66
+ extension: '.tsx',
67
+ }
68
+ }
69
+ }
70
+
16
71
  describe('Adapter output', () => {
17
72
  describe('real components', () => {
18
73
  test('compiles ButtonDemo component', async () => {
@@ -265,6 +320,93 @@ describe('Adapter output', () => {
265
320
  })
266
321
  })
267
322
 
323
+ describe('emitsTemplates: false adapters skip module-export assembly (#3234)', () => {
324
+ const emptyAdapter = new EmptyNoTemplateAdapter()
325
+
326
+ test('component with no value export: empty markedTemplate (baseline)', () => {
327
+ const source = `
328
+ 'use client'
329
+ export function Hello() { return <p>hi</p> }
330
+ `
331
+ const result = compileJSX(source, 'Hello.tsx', { adapter: emptyAdapter })
332
+ expect(result.errors).toHaveLength(0)
333
+ const template = result.files.find(f => f.type === 'markedTemplate')
334
+ expect(template?.content ?? '').toBe('')
335
+ })
336
+
337
+ test('component + export const: markedTemplate stays empty instead of becoming the export alone', () => {
338
+ const source = `
339
+ 'use client'
340
+ export const MAX = 3
341
+ export function Hello() { return <p>hi {MAX}</p> }
342
+ `
343
+ const result = compileJSX(source, 'Hello.tsx', { adapter: emptyAdapter })
344
+ expect(result.errors).toHaveLength(0)
345
+ const template = result.files.find(f => f.type === 'markedTemplate')
346
+ expect(template?.content ?? '').toBe('')
347
+ })
348
+
349
+ test('component + export function: markedTemplate stays empty', () => {
350
+ const source = `
351
+ 'use client'
352
+ export function helper() { return 1 }
353
+ export function Hello() { return <p>hi {helper()}</p> }
354
+ `
355
+ const result = compileJSX(source, 'Hello.tsx', { adapter: emptyAdapter })
356
+ expect(result.errors).toHaveLength(0)
357
+ const template = result.files.find(f => f.type === 'markedTemplate')
358
+ expect(template?.content ?? '').toBe('')
359
+ })
360
+
361
+ test('server component (no "use client") + export const: markedTemplate stays empty', () => {
362
+ const source = `
363
+ export const MAX = 3
364
+ export function Hello() { return <p>hi {MAX}</p> }
365
+ `
366
+ const result = compileJSX(source, 'Hello.tsx', { adapter: emptyAdapter })
367
+ expect(result.errors).toHaveLength(0)
368
+ const template = result.files.find(f => f.type === 'markedTemplate')
369
+ expect(template?.content ?? '').toBe('')
370
+ })
371
+
372
+ test('multi-component file + export const: markedTemplate stays empty (compileMultipleComponents path)', () => {
373
+ const source = `
374
+ 'use client'
375
+ export const MAX = 3
376
+ export function Hello() { return <p>hi {MAX}</p> }
377
+ export function World() { return <p>world</p> }
378
+ `
379
+ const result = compileJSX(source, 'Multi.tsx', { adapter: emptyAdapter })
380
+ expect(result.errors).toHaveLength(0)
381
+ const template = result.files.find(f => f.type === 'markedTemplate')
382
+ expect(template?.content ?? '').toBe('')
383
+ })
384
+
385
+ test('multi-component file: emitsTemplates:false still wins even when generate() returns non-empty sections', () => {
386
+ const source = `
387
+ 'use client'
388
+ export function Hello() { return <p>hi</p> }
389
+ export function World() { return <p>world</p> }
390
+ `
391
+ const result = compileJSX(source, 'Multi.tsx', { adapter: new LeakySectionsAdapter() })
392
+ expect(result.errors).toHaveLength(0)
393
+ const template = result.files.find(f => f.type === 'markedTemplate')
394
+ expect(template?.content ?? '').toBe('')
395
+ })
396
+
397
+ test('an adapter WITHOUT emitsTemplates: false still gets its value exports appended (regression guard)', () => {
398
+ const source = `
399
+ 'use client'
400
+ export const MAX = 3
401
+ export function Hello() { return <p>hi {MAX}</p> }
402
+ `
403
+ const result = compileJSX(source, 'Hello.tsx', { adapter })
404
+ expect(result.errors).toHaveLength(0)
405
+ const template = result.files.find(f => f.type === 'markedTemplate')!
406
+ expect(template.content).toContain('export const MAX = 3')
407
+ })
408
+ })
409
+
268
410
  describe('arrow function bodies preserved in SSR (#543)', () => {
269
411
  test('simple derived-state arrow function body is preserved in markedTemplate', () => {
270
412
  const honoAdapter = new HonoAdapter()
@@ -0,0 +1,250 @@
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
+ // #3245: the value-elided form synthesizes an internal getter name
108
+ // (`__bfGet_<action>`, analyzer.ts's `collectFactorySignal`) that nothing in
109
+ // the source ever references. It must not leak into any adapter's
110
+ // server-facing output — the SSR module, the SSR-defaults manifest, or a
111
+ // generated props struct/constructor.
112
+ test('an elided value never leaks `__bfGet_` into SSR-facing output', () => {
113
+ const source = `
114
+ 'use client'
115
+ import { createMutation, http } from '@barefootjs/client'
116
+ export function Save() {
117
+ const [, save] = createMutation(() => http.post('/api/items', {}))
118
+ return <button disabled={save.isPending()} onClick={() => save()}>Save</button>
119
+ }
120
+ `
121
+ const honoResult = compileJSX(source, 'Save.tsx', { adapter: new HonoAdapter() })
122
+ expect(honoResult.errors).toEqual([])
123
+ const ssr = honoResult.files.find((f) => f.type === 'markedTemplate')?.content ?? ''
124
+ expect(ssr).not.toContain('__bfGet_')
125
+ expect(ssr).toContain('Object.assign(() => {}, { isPending: () => false, error: () => undefined })')
126
+ const honoSsrDefaults = honoResult.files.find((f) => f.type === 'ssrDefaults')?.content ?? ''
127
+ expect(honoSsrDefaults).not.toContain('__bfGet_')
128
+
129
+ const goResult = compileJSX(source, 'Save.tsx', { adapter: new GoTemplateAdapter() })
130
+ expect(goResult.errors).toEqual([])
131
+ const goSsrDefaults = goResult.files.find((f) => f.type === 'ssrDefaults')?.content ?? ''
132
+ expect(goSsrDefaults).not.toContain('__bfGet_')
133
+ const goTypes = goResult.files.find((f) => f.type === 'types')?.content ?? ''
134
+ expect(goTypes).not.toContain('__bfGet_')
135
+ })
136
+ })
137
+
138
+ describe('createMutation action accessors (#3210, via #3166)', () => {
139
+ test('disabled={save.isPending()} and an error condition are seeded in DSL output', () => {
140
+ const { codes, ssr } = compile(FORM, { adapter: 'go' })
141
+ expect(codes).toEqual([])
142
+ expect(ssr).not.toContain('IsPending')
143
+ expect(ssr).not.toContain('.Save.')
144
+ expect(ssr).toContain('<button {{if false}}disabled{{end}}')
145
+ expect(ssr).toContain('{{if false}}<p bf-c="s0">Failed</p>')
146
+ })
147
+
148
+ // The shared fixture compares rendered HTML, and a DSL adapter that re-parses
149
+ // the raw `save.isPending()` reads an undeclared `save`, which every engine
150
+ // treats as falsy — the same HTML. So check the template text itself: no
151
+ // adapter may emit a reference to the action or its accessor.
152
+ test('every DSL adapter lowers the seed, never the accessor read', () => {
153
+ const adapters = [
154
+ new GoTemplateAdapter(),
155
+ new ErbAdapter(),
156
+ new MojoAdapter(),
157
+ new JinjaAdapter(),
158
+ new TwigAdapter(),
159
+ new XslateAdapter(),
160
+ new BladeAdapter(),
161
+ new MinijinjaAdapter(),
162
+ new PebbleAdapter(),
163
+ ]
164
+ for (const adapter of adapters) {
165
+ const result = compileJSX(FORM, 'Component.tsx', { adapter })
166
+ const ssr = result.files.find((f) => f.type === 'markedTemplate')?.content ?? ''
167
+ expect({ adapter: adapter.name, codes: result.errors.map((e) => e.code) }).toEqual({ adapter: adapter.name, codes: [] })
168
+ expect({ adapter: adapter.name, leaks: /isPending|IsPending|is_pending|\bsave\b|\bSave\b/.test(ssr) }).toEqual({
169
+ adapter: adapter.name,
170
+ leaks: false,
171
+ })
172
+ }
173
+ })
174
+
175
+ test('a read the gate does not admit still refuses with BF117', () => {
176
+ for (const markup of ['<p>{save.error()}</p>', '<p title={save.isPending()}>x</p>', '<button disabled={save.error()}>x</button>']) {
177
+ const { codes } = compile(`
178
+ 'use client'
179
+ import { createMutation, http } from '@barefootjs/client'
180
+ export function C() {
181
+ const [, save] = createMutation(() => http.post('/api/ping'))
182
+ return <div>${markup}</div>
183
+ }
184
+ `)
185
+ expect(codes).toContain('BF117')
186
+ }
187
+ })
188
+ })
189
+
190
+ describe('createMutation arity (BF115 / BF116)', () => {
191
+ test('a two-argument call and a two-element destructure are accepted', () => {
192
+ expect(compile(FORM).codes).toEqual([])
193
+ })
194
+
195
+ test('a three-element destructure is BF115', () => {
196
+ const { codes } = compile(`
197
+ 'use client'
198
+ import { createMutation, http } from '@barefootjs/client'
199
+ export function C() {
200
+ const [a, b, c] = createMutation(() => http.post('/api/items'))
201
+ return <p>{a() ? 'y' : 'n'}</p>
202
+ }
203
+ `)
204
+ expect(codes).toContain('BF115')
205
+ })
206
+
207
+ test('a third argument is BF116', () => {
208
+ const { codes } = compile(`
209
+ 'use client'
210
+ import { createMutation, http } from '@barefootjs/client'
211
+ export function C() {
212
+ const [a] = createMutation(() => http.post('/api/items'), {}, 'extra')
213
+ return <p>{a() ? 'y' : 'n'}</p>
214
+ }
215
+ `)
216
+ expect(codes).toContain('BF116')
217
+ })
218
+ })
219
+
220
+ describe('createMutation `initial` is refused (BF118)', () => {
221
+ const withOptions = (options: string, params = '') => `
222
+ 'use client'
223
+ import { createMutation, http } from '@barefootjs/client'
224
+ export function C(${params}) {
225
+ const [saved, save] = createMutation(() => http.post('/api/items'), ${options})
226
+ return <button onClick={() => save()}>{saved() ? 'saved' : 'save'}</button>
227
+ }
228
+ `
229
+
230
+ test('an `initial` key names createQuery as the factory that takes it', () => {
231
+ const { codes, errors } = compile(withOptions("{ initial: 'x', invalidates: ['/api'] }"))
232
+ expect(codes).toEqual(['BF118'])
233
+ expect(errors[0].message).toContain("Use 'createQuery'")
234
+ })
235
+
236
+ test('a shorthand `initial` is refused too', () => {
237
+ const { codes } = compile(withOptions('{ initial }', '{ initial }: { initial?: string }'))
238
+ expect(codes).toEqual(['BF118'])
239
+ })
240
+
241
+ test('options without `initial`, or that cannot be read structurally, are accepted', () => {
242
+ expect(compile(withOptions("{ invalidates: ['/api'] }")).codes).toEqual([])
243
+ expect(compile(withOptions('{ ...props.opts }', 'props: { opts: {} }')).codes).toEqual([])
244
+ })
245
+
246
+ test('the refused `initial` never seeds the value', () => {
247
+ const { ssr } = compile(withOptions("{ initial: 'x' }"), { adapter: 'hono' })
248
+ expect(ssr).toContain('const saved = () => undefined')
249
+ })
250
+ })