prunelle 0.1.1 → 0.7.2

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 (177) hide show
  1. package/LICENSE +21 -0
  2. package/llms.txt +137 -40
  3. package/package.json +11 -2
  4. package/src/a11y/declaration.ts +373 -0
  5. package/src/a11y/index.ts +477 -0
  6. package/src/a11y/rgaa-map.ts +230 -0
  7. package/src/attrs.ts +11 -3
  8. package/src/build/bundle.ts +89 -41
  9. package/src/build/byte-size.ts +11 -0
  10. package/src/build/client-entries.ts +3 -2
  11. package/src/build/client-plugin.ts +11 -5
  12. package/src/build/client-prune.ts +56 -6
  13. package/src/build/compile.ts +13 -10
  14. package/src/build/ecoindex.ts +238 -0
  15. package/src/build/files.ts +15 -0
  16. package/src/build/first-load.ts +85 -14
  17. package/src/build/graph.ts +29 -39
  18. package/src/build/index.ts +225 -122
  19. package/src/build/island-promote.ts +311 -0
  20. package/src/build/islands.ts +14 -203
  21. package/src/build/manifest.ts +56 -116
  22. package/src/build/output.ts +3 -6
  23. package/src/build/plugin-host.ts +115 -41
  24. package/src/build/precompress.ts +16 -3
  25. package/src/build/prerender.ts +177 -39
  26. package/src/build/reach.ts +200 -0
  27. package/src/build/render-rules.ts +2 -2
  28. package/src/build/report.ts +48 -5
  29. package/src/build/resolve.ts +8 -6
  30. package/src/build/routes.ts +175 -10
  31. package/src/build/static-headers.ts +112 -0
  32. package/src/build/static.ts +139 -39
  33. package/src/build/status-pages.ts +127 -0
  34. package/src/build/style-bundles.ts +526 -0
  35. package/src/cli/check-forms.ts +636 -0
  36. package/src/cli/check-imports.ts +31 -0
  37. package/src/cli/check-links.ts +632 -0
  38. package/src/cli/check-security.ts +64 -0
  39. package/src/cli/check.ts +101 -26
  40. package/src/cli/commands.ts +120 -11
  41. package/src/cli/docs.ts +403 -0
  42. package/src/cli/inspect.ts +105 -15
  43. package/src/cli/mcp-tools.ts +492 -0
  44. package/src/cli/mcp.ts +205 -0
  45. package/src/cli/new.ts +16 -5
  46. package/src/cli/render.ts +416 -0
  47. package/src/cli/upgrade-names.ts +73 -13
  48. package/src/cli/upgrade.ts +156 -22
  49. package/src/compiler/analyze.ts +87 -54
  50. package/src/compiler/browser-globals.ts +140 -17
  51. package/src/compiler/cacheability-private.ts +566 -0
  52. package/src/compiler/cacheability.ts +335 -0
  53. package/src/compiler/compliance-eco.ts +71 -0
  54. package/src/compiler/compliance-rgaa.ts +614 -0
  55. package/src/compiler/compliance-urls.ts +148 -0
  56. package/src/compiler/compliance.ts +407 -352
  57. package/src/compiler/data-keys.ts +199 -192
  58. package/src/compiler/dev-source.ts +87 -0
  59. package/src/compiler/dom-attrs.ts +138 -65
  60. package/src/compiler/dom.ts +517 -442
  61. package/src/compiler/expr-context.ts +260 -81
  62. package/src/compiler/foreign-imports.ts +88 -0
  63. package/src/compiler/mistakes.ts +23 -2
  64. package/src/compiler/props-body.ts +60 -0
  65. package/src/compiler/props.ts +87 -36
  66. package/src/compiler/scope.ts +400 -333
  67. package/src/compiler/server-only.ts +190 -151
  68. package/src/compiler/shared.ts +42 -14
  69. package/src/compiler/signal-reads.ts +6 -2
  70. package/src/compiler/spread-handlers.ts +295 -0
  71. package/src/compiler/ssr-prunelle-tags.ts +27 -14
  72. package/src/compiler/ssr.ts +220 -89
  73. package/src/context.ts +34 -0
  74. package/src/dev/error-log.ts +177 -0
  75. package/src/dev/host-check.ts +32 -0
  76. package/src/dev/index.ts +94 -34
  77. package/src/dev/open-editor.ts +228 -0
  78. package/src/dev/protocol.ts +3 -0
  79. package/src/dev/reload.ts +5 -3
  80. package/src/dev/supervisor.ts +50 -25
  81. package/src/dev/watchers.ts +74 -13
  82. package/src/dom/action.ts +47 -21
  83. package/src/dom/attrs.ts +15 -3
  84. package/src/dom/extras.ts +57 -40
  85. package/src/dom/index.ts +54 -14
  86. package/src/dom/island.ts +102 -68
  87. package/src/dom/loop.ts +66 -32
  88. package/src/eco/declaration.ts +328 -0
  89. package/src/eco/index.ts +69 -0
  90. package/src/index.ts +2 -2
  91. package/src/jsx-runtime.ts +2 -2
  92. package/src/plugins/config.ts +18 -12
  93. package/src/plugins/context.ts +44 -1
  94. package/src/plugins/index.ts +2 -2
  95. package/src/plugins/load.ts +30 -10
  96. package/src/plugins/order.ts +38 -1
  97. package/src/plugins/public.ts +6 -3
  98. package/src/plugins/services.ts +84 -0
  99. package/src/plugins/types.ts +51 -2
  100. package/src/reactivity/graph.ts +10 -0
  101. package/src/reactivity/index.ts +24 -16
  102. package/src/reactivity/selector.ts +31 -4
  103. package/src/reactivity/store.ts +64 -20
  104. package/src/server/action-flash.ts +158 -0
  105. package/src/server/action-protect.ts +199 -0
  106. package/src/server/action-registry.ts +1 -1
  107. package/src/server/action.ts +188 -152
  108. package/src/server/app-secret.ts +63 -0
  109. package/src/server/assets.ts +34 -2
  110. package/src/server/compress.ts +96 -10
  111. package/src/server/consent.ts +59 -22
  112. package/src/server/cookies.ts +16 -2
  113. package/src/server/document.ts +25 -10
  114. package/src/server/env.ts +14 -0
  115. package/src/server/errors.ts +308 -65
  116. package/src/server/form-schema.ts +337 -0
  117. package/src/server/health.ts +275 -0
  118. package/src/server/http.ts +186 -39
  119. package/src/server/index.ts +272 -273
  120. package/src/server/loader.ts +15 -2
  121. package/src/server/page.ts +15 -0
  122. package/src/server/param-matchers.ts +112 -0
  123. package/src/server/plugin-host.ts +125 -88
  124. package/src/server/public.ts +6 -5
  125. package/src/server/rate-limit.ts +102 -36
  126. package/src/server/request-body.ts +1 -1
  127. package/src/server/route-cache.ts +541 -0
  128. package/src/server/route-table.ts +356 -11
  129. package/src/server/router.ts +125 -40
  130. package/src/server/routing.ts +112 -63
  131. package/src/server/sanitize-html.ts +309 -0
  132. package/src/server/security.ts +279 -52
  133. package/src/server/serve-handlers.ts +31 -7
  134. package/src/server/standard-schema.ts +17 -0
  135. package/src/server/start.ts +60 -16
  136. package/src/server/static-dir.ts +91 -12
  137. package/src/server/stream.ts +68 -27
  138. package/src/ssr/consent-banner.ts +58 -0
  139. package/src/ssr/context.ts +106 -8
  140. package/src/ssr/index.ts +151 -4
  141. package/src/ssr/navigation.ts +2 -2
  142. package/src/ssr/region.ts +40 -19
  143. package/src/style.ts +64 -1
  144. package/src/test/browser.ts +28 -13
  145. package/src/test/index.ts +97 -12
  146. package/src/ts-plugin/diagnostics.ts +505 -0
  147. package/src/ts-plugin/fixes.ts +364 -0
  148. package/src/ts-plugin/index.ts +194 -0
  149. package/templates/_shared/AGENTS.md +2 -2
  150. package/templates/_shared/gitignore +5 -0
  151. package/templates/_shared/mcp.json +11 -0
  152. package/templates/_shared/src/routes/legal.tsx +15 -1
  153. package/templates/_shared/tsconfig.json +5 -0
  154. package/templates/app/.env.example +4 -0
  155. package/templates/app/package.json +2 -1
  156. package/templates/app/prunelle.config.ts +2 -0
  157. package/templates/app/src/auth.ts +4 -6
  158. package/templates/app/src/mail.ts +4 -0
  159. package/templates/app/src/routes/_layout.tsx +9 -1
  160. package/templates/app/src/routes/dashboard/index.tsx +42 -8
  161. package/templates/app/src/routes/login.tsx +49 -30
  162. package/templates/app/src/routes/privacy.tsx +25 -0
  163. package/templates/app/src/styles/app.css +8 -1
  164. package/templates/app/tests/app.test.ts +44 -3
  165. package/templates/blog/package.json +1 -1
  166. package/templates/blog/prunelle.config.ts +1 -1
  167. package/templates/blog/src/routes/_layout.tsx +6 -1
  168. package/templates/blog/src/routes/index.tsx +5 -1
  169. package/templates/blog/src/styles/app.css +6 -1
  170. package/templates/fullstack/package.json +1 -1
  171. package/templates/fullstack/src/components/GreetForm.tsx +2 -1
  172. package/templates/fullstack/src/routes/_layout.tsx +4 -0
  173. package/templates/fullstack/src/styles/app.css +11 -1
  174. package/templates/minimal/package.json +1 -1
  175. package/templates/minimal/src/routes/_layout.tsx +4 -0
  176. package/templates/minimal/src/styles/app.css +11 -1
  177. package/ts-plugin.cjs +4277 -0
@@ -0,0 +1,295 @@
1
+ // Static detection of event handlers and refs passed through JSX spread attributes (`{...props}`, `{...rest}`, `{...{ onClick }}`).
2
+
3
+ import type { Function as OxcFunction, Node, Program } from 'oxc-parser'
4
+ import type { Interactivity } from './interactivity'
5
+ import type { CompilerWarning } from './mistakes'
6
+ import { walk } from './ast'
7
+ import { EVENT_ATTR, isComponentTag, jsxTagName, unwrapTsExpr } from './shared'
8
+
9
+ export interface BindingUnit {
10
+ name: string
11
+ node: Node
12
+ }
13
+
14
+ // A module's body as top-level bindings, each with the node holding its code; module-level statements go under ''.
15
+ export function bindingUnits(program: Program): BindingUnit[] {
16
+ const units: BindingUnit[] = []
17
+ const add = (node: Node): void => {
18
+ if (node.type.startsWith('TS'))
19
+ return
20
+ if ((node.type === 'FunctionDeclaration' || node.type === 'ClassDeclaration') && node.id !== null) {
21
+ units.push({ name: node.id.name, node })
22
+ }
23
+ else if (node.type === 'VariableDeclaration') {
24
+ for (const d of node.declarations)
25
+ units.push({ name: d.id.type === 'Identifier' ? d.id.name : '', node: d })
26
+ }
27
+ else {
28
+ units.push({ name: '', node })
29
+ }
30
+ }
31
+ for (const stmt of program.body) {
32
+ if (stmt.type === 'ExportNamedDeclaration') {
33
+ if (stmt.declaration !== null)
34
+ add(stmt.declaration)
35
+ }
36
+ else if (stmt.type === 'ExportDefaultDeclaration') {
37
+ const decl = unwrapTsExpr(stmt.declaration)
38
+ if ((decl.type === 'FunctionDeclaration' || decl.type === 'ClassDeclaration') && decl.id !== null)
39
+ add(decl)
40
+ else if (decl.type !== 'Identifier')
41
+ units.push({ name: 'default', node: decl })
42
+ }
43
+ else if (stmt.type !== 'ImportDeclaration') {
44
+ add(stmt)
45
+ }
46
+ }
47
+ return units
48
+ }
49
+
50
+ /** Collects `const` / variable initialisers declared inside `unitNode`, layered over top-level `topInits`. */
51
+ export function collectUnitInits(unitNode: Node, topInits: ReadonlyMap<string, Node>): ReadonlyMap<string, Node> {
52
+ let merged: Map<string, Node> | undefined
53
+ walk(unitNode, (node) => {
54
+ if (node.type === 'VariableDeclarator' && node.id.type === 'Identifier' && node.init !== null) {
55
+ merged ??= new Map(topInits)
56
+ merged.set(node.id.name, node.init)
57
+ }
58
+ })
59
+ return merged ?? topInits
60
+ }
61
+
62
+ function propKeyName(key: Node): string | undefined {
63
+ if (key.type === 'Identifier')
64
+ return key.name
65
+ if (key.type === 'Literal' && typeof key.value === 'string')
66
+ return key.value
67
+ return undefined
68
+ }
69
+
70
+ function isInteractiveKey(name: string): boolean {
71
+ return EVENT_ATTR.test(name) || name === 'ref'
72
+ }
73
+
74
+ function isOmittedHandlerValue(value: Node | null | undefined): boolean {
75
+ if (value === null || value === undefined)
76
+ return false
77
+ if (value.type !== 'JSXExpressionContainer')
78
+ return false
79
+ if (value.expression.type === 'JSXEmptyExpression')
80
+ return true
81
+ const expr = unwrapTsExpr(value.expression)
82
+ return (expr.type === 'Identifier' && expr.name === 'undefined')
83
+ || (expr.type === 'Literal' && (expr.value === null || expr.value === false))
84
+ }
85
+
86
+ function isObjectAssignCall(node: Extract<Node, { type: 'CallExpression' }>): boolean {
87
+ return node.callee.type === 'MemberExpression'
88
+ && !node.callee.computed
89
+ && node.callee.object.type === 'Identifier'
90
+ && node.callee.object.name === 'Object'
91
+ && node.callee.property.type === 'Identifier'
92
+ && node.callee.property.name === 'assign'
93
+ }
94
+
95
+ /** Finds the first `on*` event handler or `ref` statically present in a JSX spread expression. */
96
+ export function findSpreadInteractiveAttr(expr: Node, inits: ReadonlyMap<string, Node>, seen: Set<string> = new Set()): string | undefined {
97
+ const cur = unwrapTsExpr(expr)
98
+ if (cur.type === 'ObjectExpression') {
99
+ for (const prop of cur.properties) {
100
+ if (prop.type === 'Property' && !prop.computed) {
101
+ const key = propKeyName(prop.key)
102
+ if (key !== undefined && isInteractiveKey(key))
103
+ return key
104
+ }
105
+ else if (prop.type === 'SpreadElement') {
106
+ const found = findSpreadInteractiveAttr(prop.argument, inits, seen)
107
+ if (found !== undefined)
108
+ return found
109
+ }
110
+ }
111
+ return undefined
112
+ }
113
+ if (cur.type === 'ConditionalExpression')
114
+ return findSpreadInteractiveAttr(cur.consequent, inits, seen) ?? findSpreadInteractiveAttr(cur.alternate, inits, seen)
115
+ if (cur.type === 'LogicalExpression')
116
+ return cur.operator === '&&' ? findSpreadInteractiveAttr(cur.right, inits, seen) : findSpreadInteractiveAttr(cur.left, inits, seen) ?? findSpreadInteractiveAttr(cur.right, inits, seen)
117
+ if (cur.type === 'CallExpression' && isObjectAssignCall(cur)) {
118
+ for (const arg of cur.arguments) {
119
+ const target = arg.type === 'SpreadElement' ? arg.argument : arg
120
+ const found = findSpreadInteractiveAttr(target, inits, seen)
121
+ if (found !== undefined)
122
+ return found
123
+ }
124
+ return undefined
125
+ }
126
+ if (cur.type === 'Identifier' && !seen.has(cur.name)) {
127
+ const init = inits.get(cur.name)
128
+ if (init !== undefined) {
129
+ seen.add(cur.name)
130
+ return findSpreadInteractiveAttr(init, inits, seen)
131
+ }
132
+ }
133
+ return undefined
134
+ }
135
+
136
+ function unwrapComponentFn(node: Node): OxcFunction | Extract<Node, { type: 'ArrowFunctionExpression' }> | undefined {
137
+ const target = node.type === 'VariableDeclarator' ? (node.init === null ? undefined : unwrapTsExpr(node.init)) : unwrapTsExpr(node)
138
+ if (target === undefined)
139
+ return undefined
140
+ if (target.type === 'FunctionDeclaration' || target.type === 'FunctionExpression' || target.type === 'ArrowFunctionExpression')
141
+ return target
142
+ return undefined
143
+ }
144
+
145
+ function collectPropVars(fn: OxcFunction | Extract<Node, { type: 'ArrowFunctionExpression' }>): Set<string> {
146
+ const vars = new Set<string>()
147
+ const p0 = fn.params[0]
148
+ if (p0 === undefined)
149
+ return vars
150
+ const pat = p0.type === 'AssignmentPattern' ? p0.left : p0
151
+ if (pat.type === 'Identifier') {
152
+ vars.add(pat.name)
153
+ }
154
+ else if (pat.type === 'ObjectPattern') {
155
+ for (const prop of pat.properties) {
156
+ if (prop.type === 'RestElement' && prop.argument.type === 'Identifier')
157
+ vars.add(prop.argument.name)
158
+ }
159
+ }
160
+ if (vars.size === 0 || fn.body === null)
161
+ return vars
162
+ walk(fn.body, (node) => {
163
+ if (node.type !== 'VariableDeclarator' || node.init === null)
164
+ return
165
+ const init = unwrapTsExpr(node.init)
166
+ const carriesProps = (init.type === 'Identifier' && vars.has(init.name))
167
+ || (init.type === 'CallExpression' && init.arguments.some(a => a.type !== 'SpreadElement' && unwrapTsExpr(a).type === 'Identifier' && vars.has((unwrapTsExpr(a) as Extract<Node, { type: 'Identifier' }>).name)))
168
+ if (!carriesProps)
169
+ return
170
+ if (node.id.type === 'Identifier') {
171
+ vars.add(node.id.name)
172
+ }
173
+ else if (node.id.type === 'ObjectPattern') {
174
+ for (const prop of node.id.properties) {
175
+ if (prop.type === 'RestElement' && prop.argument.type === 'Identifier')
176
+ vars.add(prop.argument.name)
177
+ }
178
+ }
179
+ })
180
+ return vars
181
+ }
182
+
183
+ function exprCarriesPropVar(expr: Node, propVars: ReadonlySet<string>): boolean {
184
+ const cur = unwrapTsExpr(expr)
185
+ if (cur.type === 'Identifier')
186
+ return propVars.has(cur.name)
187
+ if (cur.type === 'ObjectExpression')
188
+ return cur.properties.some(p => p.type === 'SpreadElement' && exprCarriesPropVar(p.argument, propVars))
189
+ if (cur.type === 'ConditionalExpression')
190
+ return exprCarriesPropVar(cur.consequent, propVars) || exprCarriesPropVar(cur.alternate, propVars)
191
+ if (cur.type === 'LogicalExpression')
192
+ return exprCarriesPropVar(cur.left, propVars) || exprCarriesPropVar(cur.right, propVars)
193
+ if (cur.type === 'CallExpression')
194
+ return cur.arguments.some(a => exprCarriesPropVar(a.type === 'SpreadElement' ? a.argument : a, propVars))
195
+ return false
196
+ }
197
+
198
+ function findStaticPropSpreaders(units: readonly BindingUnit[], inIsland: (offset: number) => boolean): Set<string> {
199
+ const direct = new Set<string>()
200
+ const forwardsTo = new Map<string, Set<string>>()
201
+ const staticNames = new Set<string>()
202
+
203
+ for (const unit of units) {
204
+ if (unit.name === '' || inIsland(unit.node.start))
205
+ continue
206
+ const fn = unwrapComponentFn(unit.node)
207
+ if (fn === undefined || fn.body === null)
208
+ continue
209
+ staticNames.add(unit.name)
210
+ const propVars = collectPropVars(fn)
211
+ if (propVars.size === 0)
212
+ continue
213
+ walk(fn.body, (node) => {
214
+ if (node.type !== 'JSXOpeningElement')
215
+ return
216
+ const tag = jsxTagName(node.name)
217
+ if (tag === '')
218
+ return
219
+ const spreadsProps = node.attributes.some(a => a.type === 'JSXSpreadAttribute' && exprCarriesPropVar(a.argument, propVars))
220
+ if (!spreadsProps)
221
+ return
222
+ if (!isComponentTag(tag)) {
223
+ direct.add(unit.name)
224
+ }
225
+ else if (!tag.includes('.')) {
226
+ const set = forwardsTo.get(unit.name) ?? new Set<string>()
227
+ set.add(tag)
228
+ forwardsTo.set(unit.name, set)
229
+ }
230
+ })
231
+ }
232
+
233
+ for (let changed = true; changed;) {
234
+ changed = false
235
+ for (const [name, targets] of forwardsTo) {
236
+ if (direct.has(name) || !staticNames.has(name))
237
+ continue
238
+ for (const target of targets) {
239
+ if (direct.has(target)) {
240
+ direct.add(name)
241
+ changed = true
242
+ break
243
+ }
244
+ }
245
+ }
246
+ }
247
+ return direct
248
+ }
249
+
250
+ /** Warns when non-interactive code passes an `on*` handler or `ref` to a local static component that spreads props onto a DOM element. */
251
+ export function checkStaticSpreadHandlers(
252
+ units: readonly BindingUnit[],
253
+ topInits: ReadonlyMap<string, Node>,
254
+ interactivity: Interactivity,
255
+ filename: string,
256
+ warnings: CompilerWarning[],
257
+ ): void {
258
+ const inIsland = (offset: number): boolean => interactivity.islandSpans.some(([start, end]) => offset >= start && offset < end)
259
+ const spreaders = findStaticPropSpreaders(units, inIsland)
260
+ if (spreaders.size === 0)
261
+ return
262
+
263
+ for (const unit of units) {
264
+ if (inIsland(unit.node.start))
265
+ continue
266
+ const inits = collectUnitInits(unit.node, topInits)
267
+ walk(unit.node, (node) => {
268
+ if (node.type !== 'JSXOpeningElement')
269
+ return
270
+ const tag = jsxTagName(node.name)
271
+ if (!spreaders.has(tag))
272
+ return
273
+ for (const attr of node.attributes) {
274
+ if (attr.type === 'JSXAttribute' && attr.name.type === 'JSXIdentifier') {
275
+ const name = attr.name.name
276
+ if (isInteractiveKey(name) && !isOmittedHandlerValue(attr.value)) {
277
+ warnings.push({
278
+ start: attr.start,
279
+ message: `prunelle compiler: "${name}" passed to <${tag}> in ${filename} will not bind because <${tag}> is static and its caller is not an island: move the handler inside <${tag}>, or render <${tag}> from an island.`,
280
+ })
281
+ }
282
+ }
283
+ else if (attr.type === 'JSXSpreadAttribute') {
284
+ const found = findSpreadInteractiveAttr(attr.argument, inits)
285
+ if (found !== undefined) {
286
+ warnings.push({
287
+ start: attr.start,
288
+ message: `prunelle compiler: "${found}" spread into <${tag}> in ${filename} will not bind because <${tag}> is static and its caller is not an island: move the handler inside <${tag}>, or render <${tag}> from an island.`,
289
+ })
290
+ }
291
+ }
292
+ }
293
+ })
294
+ }
295
+ }
@@ -2,8 +2,7 @@
2
2
 
3
3
  import type { JSXChild, JSXElement, JSXFragment, Node } from 'oxc-parser'
4
4
  import type { StringParts } from './ssr-helpers'
5
- import { cleanJsxText, decodeHtmlEntities, filterMeaningfulChildren, isComponentTag, isJsxNode, jsxTagName } from './shared'
6
- import { serializeComponentProps } from './ssr-helpers'
5
+ import { cleanJsxText, decodeHtmlEntities, filterMeaningfulChildren, isComponentTag, isJsxNode, jsxTagName, matchJsxMapCall } from './shared'
7
6
 
8
7
  /** What the two emitters borrow from the running `compileSsr()`. */
9
8
  export interface PrunelleTagEmitter {
@@ -11,20 +10,18 @@ export interface PrunelleTagEmitter {
11
10
  compileSubExpression: (node: Node) => string
12
11
  compileChildren: (children: readonly JSXChild[], slotMarkers?: boolean, inFragment?: boolean) => string
13
12
  compileJsx: (node: JSXElement | JSXFragment) => string
13
+ compileComponentRaw: (node: JSXElement, tag: string) => string
14
14
  markersAt: (offset: number) => boolean
15
15
  directAwaitNodes: WeakSet<Node>
16
+ jsxNodes: WeakSet<Node>
16
17
  }
17
18
 
18
19
  // `<Suspense fallback={...}><AsyncComp .../></Suspense>` passes the raw component call or Promise.
19
- export function emitSuspense(em: PrunelleTagEmitter, node: JSXElement, tag: string, propEntries: string[], parts: StringParts): void {
20
+ export function emitSuspense(em: PrunelleTagEmitter, node: JSXElement, tag: string, propEntries: string[], parts: StringParts, onRaw?: (expr: string) => void): void {
20
21
  const meaningful = filterMeaningfulChildren(node.children)
21
22
  const only = meaningful.length === 1 ? meaningful[0]! : undefined
22
23
  if (only?.type === 'JSXElement' && isComponentTag(jsxTagName(only.openingElement.name))) {
23
- const inner = serializeComponentProps(only.openingElement.attributes, em.compileSubExpression)
24
- if (filterMeaningfulChildren(only.children).length > 0)
25
- inner.propEntries.push(`children: ${em.use('raw')}(${em.compileChildren(only.children)})`)
26
- const innerObj = inner.propEntries.length > 0 ? `{ ${inner.propEntries.join(', ')} }` : '{}'
27
- propEntries.push(`children: ${jsxTagName(only.openingElement.name)}(${innerObj})`)
24
+ propEntries.push(`children: ${em.compileComponentRaw(only, jsxTagName(only.openingElement.name))}`)
28
25
  }
29
26
  else if (only?.type === 'JSXExpressionContainer' && only.expression.type !== 'JSXEmptyExpression') {
30
27
  propEntries.push(`children: ${em.compileSubExpression(only.expression)}`)
@@ -36,21 +33,37 @@ export function emitSuspense(em: PrunelleTagEmitter, node: JSXElement, tag: stri
36
33
  propEntries.push(`children: ${em.use('raw')}(${em.compileJsx(only)})`)
37
34
  }
38
35
  const propsObj = propEntries.length > 0 ? `{ ${propEntries.join(', ')} }` : '{}'
39
- parts.pushExpr(`${em.use('ssrChild')}(${tag}(${propsObj}))`)
36
+ const callExpr = `${tag}(${propsObj})`
37
+ if (onRaw !== undefined)
38
+ onRaw(callExpr)
39
+ else
40
+ parts.pushExpr(`${em.use('ssrChild')}(${callExpr})`)
40
41
  }
41
42
 
42
43
  // `<Catch>` reads its children inside a try, so they reach it as a getter even when static; in an island it renders in a range of its own, which the browser swaps.
43
- export function emitCatch(em: PrunelleTagEmitter, node: JSXElement, tag: string, propEntries: string[], parts: StringParts): void {
44
+ export function emitCatch(em: PrunelleTagEmitter, node: JSXElement, tag: string, propEntries: string[], parts: StringParts, onRaw?: (expr: string) => void): void {
44
45
  const meaningful = filterMeaningfulChildren(node.children)
45
46
  const awaits = node.children.some(c => em.directAwaitNodes.has(c))
46
- const markers = em.markersAt(node.start)
47
+ const markers = onRaw === undefined && em.markersAt(node.start)
47
48
  if (meaningful.length > 0) {
48
- const childExpr = `${em.use('raw')}(${em.compileChildren(node.children, markers, markers && meaningful.length > 1)})`
49
- propEntries.push(`get children() { return ${awaits ? `(async () => ${childExpr})()` : childExpr} }`)
49
+ const only = meaningful.length === 1 ? meaningful[0]! : undefined
50
+ let childExpr: string
51
+ if (onRaw !== undefined && only?.type === 'JSXElement' && isComponentTag(jsxTagName(only.openingElement.name))) {
52
+ childExpr = em.compileComponentRaw(only, jsxTagName(only.openingElement.name))
53
+ }
54
+ else {
55
+ const singleLoop = only?.type === 'JSXExpressionContainer' && only.expression.type !== 'JSXEmptyExpression' && matchJsxMapCall(only.expression, em.jsxNodes) !== undefined
56
+ childExpr = `${em.use('raw')}(${em.compileChildren(node.children, markers, markers && (meaningful.length > 1 || singleLoop))})`
57
+ }
58
+ propEntries.push(`get children() { return (${awaits ? `(async () => ${childExpr})()` : childExpr}) }`)
50
59
  }
51
60
  if (markers)
52
61
  parts.pushStatic('<!--k[-->')
53
- parts.pushExpr(`${em.use('ssrChild')}(${awaits ? 'await ' : ''}${tag}({ ${propEntries.join(', ')} }))`)
62
+ const callExpr = `${awaits ? 'await ' : ''}${tag}({ ${propEntries.join(', ')} })`
63
+ if (onRaw !== undefined)
64
+ onRaw(callExpr)
65
+ else
66
+ parts.pushExpr(`${em.use('ssrChild')}(${callExpr})`)
54
67
  if (markers)
55
68
  parts.pushStatic('<!--k]-->')
56
69
  }