@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
@@ -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
+ }
@@ -17,7 +17,6 @@ import { registerLoweringPlugin } from './lowering-registry.ts'
17
17
  import { queryHrefLocalNames } from './adapters/env-signal.ts'
18
18
  import { matchQueryHrefCall } from './query-href-lowering.ts'
19
19
  import { datePlugin } from './date-lowering.ts'
20
- import { formatDatePlugin } from './format-date-lowering.ts'
21
20
  import { toLocaleDatePlugin } from './to-locale-date-lowering.ts'
22
21
 
23
22
  /**
@@ -47,7 +46,6 @@ export const queryHrefPlugin: LoweringPlugin = {
47
46
  export const BUILTIN_LOWERING_PLUGINS: readonly LoweringPlugin[] = [
48
47
  queryHrefPlugin,
49
48
  datePlugin,
50
- formatDatePlugin,
51
49
  toLocaleDatePlugin,
52
50
  ]
53
51
 
package/src/compiler.ts CHANGED
@@ -18,6 +18,7 @@ import { jsxToIR } from './jsx-to-ir.ts'
18
18
  import { stripClientBuiltinImports } from './builtins.ts'
19
19
  import { generateClientJs, generateClientJsWithSourceMap, analyzeClientNeeds } from './ir-to-client-js/index.ts'
20
20
  import { decideClientOnlyElision } from './ir-to-client-js/client-only-elision.ts'
21
+ import { decideComponentRootScopeComment } from './component-root-scope-comment.ts'
21
22
  import { emitModuleLevelDeclarations } from './ir-to-client-js/emit-module-level.ts'
22
23
  import { RUNTIME_MODULE, detectUsedImports as detectUsedImportsFromCode, makeValueUsageTest, renderUsedImportLines, mergeCompiledClientJsImports } from './ir-to-client-js/imports.ts'
23
24
  import { setActiveComponentScope, computeFileScope } from './ir-to-client-js/component-scope.ts'
@@ -27,6 +28,8 @@ import { preprocessInlineJsxCallbacks } from './preprocess-inline-jsx-callbacks.
27
28
  import { extractSsrDefaults } from './ssr-defaults.ts'
28
29
  import { computeSsrSeedPlan } from './ssr-seed-plan.ts'
29
30
  import { checkRichTypeMethodCalls, checkRichTypePropSerialization } from './rich-type-refusal.ts'
31
+ import { checkAuthoredFormatDateCalls } from './format-date-refusal.ts'
32
+ import { checkAsyncActionReads } from './async-action-refusal.ts'
30
33
  import { ErrorCodes, createError } from './errors.ts'
31
34
  import { collectComponentNamesFromIR } from './ir-to-client-js/child-components.ts'
32
35
 
@@ -209,6 +212,13 @@ function compileMultipleComponents(
209
212
  componentIR.metadata.clientAnalysis = analyzeClientNeeds(componentIR)
210
213
  checkRichTypeMethodCalls(componentIR.root, componentIR.metadata, errors)
211
214
  checkRichTypePropSerialization(componentIR.root, componentIR.metadata, errors, ctx.propsDestructuring?.loc)
215
+ checkAuthoredFormatDateCalls(componentIR.root, componentIR.metadata, errors)
216
+ checkAsyncActionReads(componentIR.root, componentIR.metadata, errors)
217
+
218
+ // #3141: decide once whether a component-call render root needs the
219
+ // comment-based scope marker pair, same "right after clientAnalysis"
220
+ // timing as Step B below.
221
+ decideComponentRootScopeComment(componentIR)
212
222
 
213
223
  // Slot unification Step B — see the single-component path's identical
214
224
  // call for why this must run before adapter.generate/generateClientJs.
@@ -400,6 +410,16 @@ function compileMultipleComponents(
400
410
  }
401
411
  try {
402
412
 
413
+ // Same-file siblings: hand every component's shape to the adapter before
414
+ // any of them generates, so a parent finds a same-file child's shape
415
+ // whatever the declaration order — `entries` follows source order, and a
416
+ // child declared AFTER its parent is legal (function-declaration
417
+ // hoisting). Cross-file children reach the same hook from the CLI /
418
+ // compat / test-render pre-passes; this is the same-file door.
419
+ if (adapter.registerChildComponentShape) {
420
+ for (const { componentIR } of entries) adapter.registerChildComponentShape(componentIR)
421
+ }
422
+
403
423
  for (const { componentIR } of entries) {
404
424
  // Non-default exports share the parent's .client.js, so they
405
425
  // route to the default export's script name. The pipeline's
@@ -769,6 +789,13 @@ export function compileJSX(
769
789
  componentIR.metadata.clientAnalysis = analyzeClientNeeds(componentIR)
770
790
  checkRichTypeMethodCalls(componentIR.root, componentIR.metadata, errors)
771
791
  checkRichTypePropSerialization(componentIR.root, componentIR.metadata, errors, ctx.propsDestructuring?.loc)
792
+ checkAuthoredFormatDateCalls(componentIR.root, componentIR.metadata, errors)
793
+ checkAsyncActionReads(componentIR.root, componentIR.metadata, errors)
794
+
795
+ // #3141: decide once whether a component-call render root needs the
796
+ // comment-based scope marker pair, same "right after clientAnalysis"
797
+ // timing as Step B below.
798
+ decideComponentRootScopeComment(componentIR)
772
799
 
773
800
  // Slot unification Step B (`spec/slot-unification.md` §5 Step B): decide
774
801
  // marker elision ONCE, mutating `componentIR.root` in place, before either
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Component-root scope comment (#3141): decide, EXACTLY ONCE and right after
3
+ * `metadata.clientAnalysis` becomes available, whether a client-interactive
4
+ * component's render ROOT — when that root is itself a single child-
5
+ * component call with no wrapping element of its own — needs a comment-based
6
+ * scope marker pair around its rendered output.
7
+ *
8
+ * Before this, the decision was answered independently by Hono
9
+ * (`isRootComponent` + `wrapWithScopeComment` in `hono-adapter.ts`) and NOT
10
+ * AT ALL by the eight DSL adapters, which only ever wrap a `needsScopeComment`
11
+ * FRAGMENT root (the analogous multi-element-root case) — go-template alone
12
+ * had a partial, adapter-local re-derivation that emitted the opening marker
13
+ * but not the closing one. That's the "one decision, two implementations"
14
+ * defect CLAUDE.md calls out: this function is the single shared answer
15
+ * every adapter's `IRNodeEmitter.emitComponent` now reads off
16
+ * `IRComponent.needsScopeComment` instead of re-deriving.
17
+ *
18
+ * Mirrors `IRFragment.needsScopeComment`, computed inside `jsx-to-ir.ts`'s
19
+ * `transformFragment` at parse time — but THIS flag can't live there: "is
20
+ * this component client-interactive" isn't knowable until
21
+ * `analyzeClientNeeds` has run over the whole IR, which happens in
22
+ * `compiler.ts` after `jsxToIR` returns. So, like Slot Unification Step B's
23
+ * `decideClientOnlyElision`, this is a post-hoc mutation of the already-built
24
+ * IR, run once, before any adapter or `generateClientJs` sees it.
25
+ */
26
+
27
+ import type { ComponentIR, IRComponent } from './types.ts'
28
+
29
+ /**
30
+ * True when `ir`'s render root needs the comment-based scope marker pair:
31
+ * the root is a single component call (no wrapping element) AND the
32
+ * component is client-interactive (owns a `'use client'` directive, or the
33
+ * client-JS pre-pass determined it needs an init call regardless).
34
+ *
35
+ * Matches the Hono reference's existing `hasClientInteractivity` formula
36
+ * exactly (`isClientComponent || needsInit`) — this function REPLACES that
37
+ * adapter-local computation for the one decision it fed (the scope-comment
38
+ * wrap), not the adapter's other, still-adapter-owned uses of the same two
39
+ * inputs (namespaced prop passthrough to the child, `bf-p` presence).
40
+ */
41
+ function needsComponentRootScopeComment(ir: ComponentIR): boolean {
42
+ if (ir.root.type !== 'component') return false
43
+ const hasClientInteractivity =
44
+ ir.metadata.isClientComponent || (ir.metadata.clientAnalysis?.needsInit ?? false)
45
+ return hasClientInteractivity
46
+ }
47
+
48
+ /**
49
+ * Mutate `ir.root` in place, marking it `needsScopeComment: true` when
50
+ * `needsComponentRootScopeComment` says so. A no-op otherwise (including
51
+ * when the root isn't a `component` node at all) — mirrors
52
+ * `decideClientOnlyElision`'s in-place-mutation convention so both
53
+ * `compileMultipleComponents` and the single-component path can call it
54
+ * identically right after `metadata.clientAnalysis` is set.
55
+ */
56
+ export function decideComponentRootScopeComment(ir: ComponentIR): void {
57
+ if (!needsComponentRootScopeComment(ir)) return
58
+ ;(ir.root as IRComponent).needsScopeComment = true
59
+ }