@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
@@ -0,0 +1,254 @@
1
+ /**
2
+ * `checkAsyncActionReads` (#3165, BF117): a read of a query action in a
3
+ * template-lowered position is refused at compile time, uniformly across every
4
+ * adapter including Hono.
5
+ *
6
+ * `const [posts, fetchPosts] = createQuery(fn, options)` seeds `posts()` from
7
+ * `options.initial`. Since #3166, `fetchPosts.isPending()` / `fetchPosts.error()`
8
+ * are ALSO seeded (`false` / `undefined`, spec/async.md §7.3) when read as the
9
+ * WHOLE expression of a position where the seed renders like Hono: a
10
+ * condition (either accessor), or an ARIA boolean-state attribute
11
+ * (`isPending()` only). `action-accessor.ts`'s `seedableActionAccessorRead` is
12
+ * the one gate deciding that, for both this lift and the seed itself. Any
13
+ * other direct accessor read — a text child (`{fetchPosts.error()}`),
14
+ * `error()` in any attribute, `isPending()` in a non-ARIA-boolean attribute,
15
+ * a structured template attribute's ternary — has no sound seed and refuses
16
+ * here as before. Everything else is unchanged too: calling the action itself
17
+ * (`fetchPosts()`) still sends a request during render, and a compound or
18
+ * nested accessor read (`!fetchPosts.isPending()`, buried inside a memo) has
19
+ * no seed substitution yet, so a template position may still not:
20
+ *
21
+ * - read an accessor outside the positions above,
22
+ * - call the action (`fetchPosts()`),
23
+ * - read a memo or a component-local constant that reads the action, since
24
+ * every backend evaluates a memo or constant it renders, or
25
+ * - call a local function that reads the action.
26
+ *
27
+ * "Reads the action" is transitive through memos, constants and functions
28
+ * (a constant reading a memo reading the action counts). Passing the action,
29
+ * or a local function that reads it, as a value (`<Retry onRetry={fetchPosts} />`,
30
+ * `run={reload}`) is fine: nothing runs until the client calls it. A constant
31
+ * that only aliases one of them (`const run = fetchPosts`) is treated like its
32
+ * target. Any read inside an event handler or effect is fine too, since those
33
+ * only run on the client. A `/* @client *\/`-marked position is skipped by
34
+ * `walkTemplatePositions`: the read is deferred to the client.
35
+ *
36
+ * Other function-valued expressions that read the action are refused even when
37
+ * they are only passed on, because the walk cannot tell passing from calling
38
+ * during render (an array-method callback runs then): an inline arrow outside
39
+ * an `on*` prop (`run={() => fetchPosts()}`), and a constant holding arrows in an object or
40
+ * array literal (`const h = { run: () => fetchPosts() }`, `run={h.run}`). Name
41
+ * the function as a local instead, or mark the position `/* @client *\/`.
42
+ */
43
+
44
+ import type { IRNode, IRMetadata, CompilerError, SourceLocation } from './types.ts'
45
+ import type { ParsedExpr } from './expression-parser.ts'
46
+ import { ErrorCodes } from './errors.ts'
47
+ import { isEventHandlerName } from './event-handler-name.ts'
48
+ import { walkTemplatePositions } from './template-position-walk.ts'
49
+ import { seedableActionAccessorRead, collectActionNames, ACTION_ACCESSOR_NAMES, parsedExprChildren } from './action-accessor.ts'
50
+
51
+ /** What a template position read, for the diagnostic. */
52
+ type ActionRead =
53
+ | { kind: 'accessor'; action: string; accessor: string }
54
+ | { kind: 'call'; action: string }
55
+ | { kind: 'local'; name: string; declaration: 'memo' | 'constant' | 'function'; action: string }
56
+
57
+ /** A component-local declaration that reads a query action, and the action it reaches. */
58
+ interface ActionReader {
59
+ declaration: 'memo' | 'constant' | 'function'
60
+ action: string
61
+ }
62
+
63
+ /**
64
+ * The component-local declarations that read a query action, split by how a
65
+ * template position evaluates them: `values` (memos and constants whose value
66
+ * is computed when rendered, so a reference is a read) and `callables`
67
+ * (functions, and constants whose value is a function, whose body runs only
68
+ * when called).
69
+ */
70
+ interface ActionReaders {
71
+ values: ReadonlyMap<string, ActionReader>
72
+ callables: ReadonlyMap<string, ActionReader>
73
+ }
74
+
75
+ export function checkAsyncActionReads(root: IRNode, metadata: IRMetadata, errors: CompilerError[]): void {
76
+ // The action bindings a recognised factory produced DIRECTLY — the same
77
+ // set the seed pass (`seedActionAccessorReads`) recognises.
78
+ // Kept separate from `actions` below (which also grows through aliases):
79
+ // the seed substitution only ever rewrites a read of a DIRECT binding, so
80
+ // the "no longer refused" check here must match exactly that, not a wider
81
+ // alias-grown set — an aliased read (`const run = fetchPosts;
82
+ // run.isPending()`) stays refused below exactly as before #3166, since
83
+ // nothing seeds it structurally.
84
+ const directActions = collectActionNames(metadata.signals)
85
+ if (directActions.size === 0) return
86
+ const actions = new Set(directActions)
87
+ // `const run = fetchPosts` is the action under another name.
88
+ for (let grew = true; grew; ) {
89
+ grew = false
90
+ for (const constant of metadata.localConstants) {
91
+ const target = aliasTarget(constant)
92
+ if (target !== undefined && actions.has(target) && !actions.has(constant.name)) {
93
+ actions.add(constant.name)
94
+ grew = true
95
+ }
96
+ }
97
+ }
98
+ const readers = localsReadingActions(metadata, actions)
99
+ const seen = new Set<string>()
100
+ walkTemplatePositions(root, (position) => {
101
+ const { expr, loc, attrName } = position
102
+ if (attrName !== undefined && isEventHandlerName(attrName)) return
103
+ // #3166: a direct accessor read the shared gate admits is an ordinary
104
+ // seeded value (`seedActionAccessorReads` has usually already replaced
105
+ // it with its seed literal by now) — no refusal. The gate is the same
106
+ // function the seed pass calls, over the same walk, so the two cannot
107
+ // disagree. Anything it does not admit — a compound/nested use, or a
108
+ // direct read at a position where the seed would not render like Hono
109
+ // (a text child, `error()` in an attribute, …) — falls through to
110
+ // `findActionRead` below, refused exactly as before.
111
+ if (seedableActionAccessorRead(position, directActions)) return
112
+ const read = findActionRead(expr, actions, readers, new Set())
113
+ if (read) pushDiagnostic(errors, seen, loc, read)
114
+ })
115
+ }
116
+
117
+ /**
118
+ * The component-local memos, constants and functions that read a query
119
+ * action, directly or through another such declaration (a fixpoint). Uses each
120
+ * declaration's free identifiers, so a block-bodied memo or function is
121
+ * covered too: mentioning the action, or a declaration that reads it, is
122
+ * enough, since the only things a body can do with the action are read an
123
+ * accessor, send a request, or pass it on. JSX-valued constants and functions
124
+ * are skipped: they are inlined into the IR, where the walk sees their reads
125
+ * directly. `isModule` is not consulted: for a function it only marks a
126
+ * candidate for hoisting (`compute-scope.ts` decides), and a declaration that
127
+ * really lives at module scope cannot name a component's action anyway.
128
+ */
129
+ function localsReadingActions(metadata: IRMetadata, actions: ReadonlySet<string>): ActionReaders {
130
+ const values = new Map<string, ActionReader>()
131
+ const callables = new Map<string, ActionReader>()
132
+ const candidates: Array<{
133
+ name: string
134
+ declaration: ActionReader['declaration']
135
+ callable: boolean
136
+ freeIds: Iterable<string>
137
+ aliasOf?: string
138
+ }> = []
139
+ for (const memo of metadata.memos) {
140
+ candidates.push({ name: memo.name, declaration: 'memo', callable: false, freeIds: memo.computationFreeIdentifiers ?? [] })
141
+ }
142
+ for (const constant of metadata.localConstants) {
143
+ if (constant.isJsx || constant.isJsxFunction || actions.has(constant.name)) continue
144
+ candidates.push({
145
+ name: constant.name,
146
+ declaration: 'constant',
147
+ callable: constant.isFunctionValue === true,
148
+ freeIds: constant.freeIdentifiers ?? [],
149
+ aliasOf: aliasTarget(constant),
150
+ })
151
+ }
152
+ for (const fn of metadata.localFunctions) {
153
+ if (fn.isJsxFunction) continue
154
+ candidates.push({ name: fn.name, declaration: 'function', callable: true, freeIds: fn.freeIdentifiers ?? [] })
155
+ }
156
+
157
+ let changed = true
158
+ while (changed) {
159
+ changed = false
160
+ for (const candidate of candidates) {
161
+ if (values.has(candidate.name) || callables.has(candidate.name)) continue
162
+ if (candidate.aliasOf !== undefined) {
163
+ // An alias reads the action only if its target does, and is called or
164
+ // referenced the same way.
165
+ const target = values.get(candidate.aliasOf) ?? callables.get(candidate.aliasOf)
166
+ if (target === undefined) continue
167
+ const reader = { declaration: candidate.declaration, action: target.action }
168
+ if (callables.has(candidate.aliasOf)) callables.set(candidate.name, reader)
169
+ else values.set(candidate.name, reader)
170
+ changed = true
171
+ continue
172
+ }
173
+ for (const id of candidate.freeIds) {
174
+ if (id === candidate.name) continue
175
+ const action = actions.has(id) ? id : (values.get(id) ?? callables.get(id))?.action
176
+ if (action === undefined) continue
177
+ const reader = { declaration: candidate.declaration, action }
178
+ if (candidate.callable) callables.set(candidate.name, reader)
179
+ else values.set(candidate.name, reader)
180
+ changed = true
181
+ break
182
+ }
183
+ }
184
+ }
185
+ return { values, callables }
186
+ }
187
+
188
+ /** The name a constant only aliases (`const run = fetchPosts`), if it is one. */
189
+ function aliasTarget(constant: IRMetadata['localConstants'][number]): string | undefined {
190
+ return constant.parsed?.kind === 'identifier' ? constant.parsed.name : undefined
191
+ }
192
+
193
+ function findActionRead(
194
+ expr: ParsedExpr,
195
+ actions: ReadonlySet<string>,
196
+ readers: ActionReaders,
197
+ bound: ReadonlySet<string>,
198
+ ): ActionRead | null {
199
+ switch (expr.kind) {
200
+ case 'identifier': {
201
+ if (bound.has(expr.name)) return null
202
+ const reader = readers.values.get(expr.name)
203
+ return reader ? { kind: 'local', name: expr.name, ...reader } : null
204
+ }
205
+ case 'member':
206
+ if (
207
+ expr.object.kind === 'identifier' &&
208
+ actions.has(expr.object.name) &&
209
+ !bound.has(expr.object.name) &&
210
+ ACTION_ACCESSOR_NAMES.has(expr.property)
211
+ ) {
212
+ return { kind: 'accessor', action: expr.object.name, accessor: expr.property }
213
+ }
214
+ break
215
+ case 'call':
216
+ if (expr.callee.kind === 'identifier' && !bound.has(expr.callee.name)) {
217
+ if (actions.has(expr.callee.name)) return { kind: 'call', action: expr.callee.name }
218
+ const reader = readers.callables.get(expr.callee.name)
219
+ if (reader) return { kind: 'local', name: expr.callee.name, ...reader }
220
+ }
221
+ break
222
+ }
223
+ for (const child of parsedExprChildren(expr)) {
224
+ const read = findActionRead(child.expr, actions, readers, child.params ? new Set([...bound, ...child.params]) : bound)
225
+ if (read) return read
226
+ }
227
+ return null
228
+ }
229
+
230
+ function pushDiagnostic(errors: CompilerError[], seen: Set<string>, loc: SourceLocation, read: ActionRead): void {
231
+ const key = `${loc.start.line}:${loc.start.column}`
232
+ if (seen.has(key)) return
233
+ seen.add(key)
234
+ const what =
235
+ read.kind === 'accessor'
236
+ ? `'${read.action}.${read.accessor}' reads an async action's accessor`
237
+ : read.kind === 'call'
238
+ ? `'${read.action}()' calls an async action, which sends a request,`
239
+ : `${read.declaration} '${read.name}' reads the async action '${read.action}' and is used`
240
+ errors.push({
241
+ code: ErrorCodes.ASYNC_ACTION_READ_IN_TEMPLATE,
242
+ severity: 'error',
243
+ message:
244
+ `${what} in a template position. The request function never runs on the server, so ` +
245
+ `'${read.action}.isPending()' and '${read.action}.error()' have no value to render there yet.`,
246
+ loc,
247
+ suggestion: {
248
+ message:
249
+ 'Defer the read to the client with /* @client */, or read it inside an event handler or ' +
250
+ 'effect, which only run on the client.',
251
+ escape: [{ kind: 'client-directive' }],
252
+ },
253
+ })
254
+ }
package/src/compiler.ts CHANGED
@@ -29,6 +29,7 @@ import { extractSsrDefaults } from './ssr-defaults.ts'
29
29
  import { computeSsrSeedPlan } from './ssr-seed-plan.ts'
30
30
  import { checkRichTypeMethodCalls, checkRichTypePropSerialization } from './rich-type-refusal.ts'
31
31
  import { checkAuthoredFormatDateCalls } from './format-date-refusal.ts'
32
+ import { checkAsyncActionReads } from './async-action-refusal.ts'
32
33
  import { ErrorCodes, createError } from './errors.ts'
33
34
  import { collectComponentNamesFromIR } from './ir-to-client-js/child-components.ts'
34
35
 
@@ -165,6 +166,14 @@ function compileMultipleComponents(
165
166
  const files: FileOutput[] = []
166
167
  const errors: CompileResult['errors'] = []
167
168
  const adapter = options.adapter
169
+ // `emitsTemplates: false` (CSR) — nothing will ever read this file's
170
+ // markedTemplate, so every assembly step below (per-component module
171
+ // exports AND the combined multi-component template) skips straight to
172
+ // empty rather than trusting `generate()`'s own output to already be
173
+ // empty. One flag, read at both sites, so the invariant can't drift
174
+ // between them the way `moduleExports`-only skip did before it covered
175
+ // the combined-template site too (#3234).
176
+ const skipTemplateAssembly = adapter.emitsTemplates === false
168
177
 
169
178
  // --- Pass 1: analyze + jsxToIR for ALL components ---
170
179
  const entries: { componentIR: ComponentIR; ctx: ReturnType<typeof analyzeComponent> }[] = []
@@ -212,6 +221,7 @@ function compileMultipleComponents(
212
221
  checkRichTypeMethodCalls(componentIR.root, componentIR.metadata, errors)
213
222
  checkRichTypePropSerialization(componentIR.root, componentIR.metadata, errors, ctx.propsDestructuring?.loc)
214
223
  checkAuthoredFormatDateCalls(componentIR.root, componentIR.metadata, errors)
224
+ checkAsyncActionReads(componentIR.root, componentIR.metadata, errors)
215
225
 
216
226
  // #3141: decide once whether a component-call render root needs the
217
227
  // comment-based scope marker pair, same "right after clientAnalysis"
@@ -435,12 +445,14 @@ function compileMultipleComponents(
435
445
  scriptAssets: options.scriptAssets,
436
446
  preloadAssets: options.preloadAssets,
437
447
  })
438
- const moduleExports = generateModuleExports(
439
- componentIR,
440
- fileWideInlineExported,
441
- options.rewriteRelativeImport,
442
- { skipValueDeclarations: adapterOutput.sections.moduleConstantsIncludeExports },
443
- )
448
+ const moduleExports = skipTemplateAssembly
449
+ ? ''
450
+ : generateModuleExports(
451
+ componentIR,
452
+ fileWideInlineExported,
453
+ options.rewriteRelativeImport,
454
+ { skipValueDeclarations: adapterOutput.sections.moduleConstantsIncludeExports },
455
+ )
444
456
 
445
457
  const s = adapterOutput.sections
446
458
  const imports = s.imports
@@ -521,52 +533,66 @@ function compileMultipleComponents(
521
533
  return { files, errors }
522
534
  }
523
535
 
524
- // Merge imports from all components. Named imports from the same source
525
- // are combined into their first occurrence rather than deduplicated by
526
- // exact line: in a multi-component file each component emits its own
527
- // `import { … } from '@barefootjs/hono/utils'` listing only the symbols
528
- // it uses, so plain line-dedup leaves several statements that re-declare
529
- // the same binding (e.g. `bfComment`). Bun tolerates the redeclaration,
530
- // but stricter ESM parsers — including Deno, used to render the SSR
531
- // template — reject it as a SyntaxError.
532
- const mergedImports = mergeTemplateImports(
533
- allOutputs.flatMap(o => (o.imports ? o.imports.split('\n') : [])),
534
- )
535
-
536
- // Combine unique type definitions
537
- const seenTypes = new Set<string>()
538
- const uniqueTypes: string[] = []
539
- for (const output of allOutputs) {
540
- if (output.types && !seenTypes.has(output.types)) {
541
- seenTypes.add(output.types)
542
- uniqueTypes.push(output.types)
536
+ // `generate()`'s own `sections` (imports/types/component) aren't
537
+ // guaranteed empty just because `moduleExports` was skipped above —
538
+ // nothing in the `TemplateAdapter` contract stops a future
539
+ // `emitsTemplates: false` adapter from returning non-empty sections.
540
+ // Reusing `skipTemplateAssembly` here mirrors `compileJSX`'s
541
+ // single-component short-circuit, so the invariant ("this adapter's
542
+ // markedTemplate is always empty") is enforced once per adapter, not
543
+ // once per adapter per component-count code path (#3234).
544
+ let combinedTemplate: string
545
+ if (skipTemplateAssembly) {
546
+ combinedTemplate = ''
547
+ } else {
548
+ // Merge imports from all components. Named imports from the same
549
+ // source are combined into their first occurrence rather than
550
+ // deduplicated by exact line: in a multi-component file each
551
+ // component emits its own `import { … } from '@barefootjs/hono/utils'`
552
+ // listing only the symbols it uses, so plain line-dedup leaves
553
+ // several statements that re-declare the same binding (e.g.
554
+ // `bfComment`). Bun tolerates the redeclaration, but stricter ESM
555
+ // parsers — including Deno, used to render the SSR template — reject
556
+ // it as a SyntaxError.
557
+ const mergedImports = mergeTemplateImports(
558
+ allOutputs.flatMap(o => (o.imports ? o.imports.split('\n') : [])),
559
+ )
560
+
561
+ // Combine unique type definitions
562
+ const seenTypes = new Set<string>()
563
+ const uniqueTypes: string[] = []
564
+ for (const output of allOutputs) {
565
+ if (output.types && !seenTypes.has(output.types)) {
566
+ seenTypes.add(output.types)
567
+ uniqueTypes.push(output.types)
568
+ }
543
569
  }
544
- }
545
570
 
546
- // Deduplicate module-level exports across components
547
- const seenModuleExports = new Set<string>()
548
- const uniqueModuleExports: string[] = []
549
- for (const output of allOutputs) {
550
- if (output.moduleExports) {
551
- for (const line of output.moduleExports.split('\n')) {
552
- if (line.trim() && !seenModuleExports.has(line)) {
553
- seenModuleExports.add(line)
554
- uniqueModuleExports.push(line)
571
+ // Deduplicate module-level exports across components
572
+ const seenModuleExports = new Set<string>()
573
+ const uniqueModuleExports: string[] = []
574
+ for (const output of allOutputs) {
575
+ if (output.moduleExports) {
576
+ for (const line of output.moduleExports.split('\n')) {
577
+ if (line.trim() && !seenModuleExports.has(line)) {
578
+ seenModuleExports.add(line)
579
+ uniqueModuleExports.push(line)
580
+ }
555
581
  }
556
582
  }
557
583
  }
558
- }
559
584
 
560
- // Combine all components
561
- const combinedTemplate = [
562
- mergedImports,
563
- moduleStatementsOrdered.join('\n\n'),
564
- uniqueTypes.join('\n\n'),
565
- uniqueModuleExports.length > 0 ? uniqueModuleExports.join('\n') : '',
566
- ...allOutputs.map(o => o.component),
567
- ]
568
- .filter(Boolean)
569
- .join('\n\n')
585
+ // Combine all components
586
+ combinedTemplate = [
587
+ mergedImports,
588
+ moduleStatementsOrdered.join('\n\n'),
589
+ uniqueTypes.join('\n\n'),
590
+ uniqueModuleExports.length > 0 ? uniqueModuleExports.join('\n') : '',
591
+ ...allOutputs.map(o => o.component),
592
+ ]
593
+ .filter(Boolean)
594
+ .join('\n\n')
595
+ }
570
596
 
571
597
  files.push({
572
598
  path: filePath.replace(/\.tsx?$/, adapter.extension),
@@ -788,6 +814,7 @@ export function compileJSX(
788
814
  checkRichTypeMethodCalls(componentIR.root, componentIR.metadata, errors)
789
815
  checkRichTypePropSerialization(componentIR.root, componentIR.metadata, errors, ctx.propsDestructuring?.loc)
790
816
  checkAuthoredFormatDateCalls(componentIR.root, componentIR.metadata, errors)
817
+ checkAsyncActionReads(componentIR.root, componentIR.metadata, errors)
791
818
 
792
819
  // #3141: decide once whether a component-call render root needs the
793
820
  // comment-based scope marker pair, same "right after clientAnalysis"
@@ -853,6 +880,14 @@ export function compileJSX(
853
880
  let content: string
854
881
  if (adapter.templatesPerComponent) {
855
882
  content = adapterOutput.template
883
+ } else if (adapter.emitsTemplates === false) {
884
+ // Nothing will ever read this file's markedTemplate (CSR) — skip
885
+ // assembly entirely, module-level value exports included. Otherwise a
886
+ // component file that also exports a plain constant/function would
887
+ // produce a markedTemplate whose only content is that export, which
888
+ // `@barefootjs/vite`'s `assertNoRealTemplateOutput` treats as real
889
+ // template output requiring a configured `templates` dir (#3234).
890
+ content = ''
856
891
  } else {
857
892
  const moduleExports = generateModuleExports(componentIR, undefined, options.rewriteRelativeImport, {
858
893
  skipValueDeclarations: s.moduleConstantsIncludeExports,