prunelle 0.8.0 → 0.10.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 (209) hide show
  1. package/llms.txt +68 -51
  2. package/package.json +7 -2
  3. package/src/a11y/declaration.ts +10 -17
  4. package/src/a11y/index.ts +69 -125
  5. package/src/animate.ts +127 -0
  6. package/src/build/asides.ts +51 -0
  7. package/src/build/bundle.ts +94 -136
  8. package/src/build/client-entries.ts +6 -6
  9. package/src/build/client-outputs.ts +75 -0
  10. package/src/build/client-plugin.ts +9 -4
  11. package/src/build/ecoindex.ts +4 -2
  12. package/src/build/files.ts +18 -0
  13. package/src/build/graph.ts +14 -6
  14. package/src/build/index.ts +23 -11
  15. package/src/build/island-promote.ts +42 -2
  16. package/src/build/islands.ts +63 -9
  17. package/src/build/key-types.ts +31 -0
  18. package/src/build/manifest.ts +117 -1
  19. package/src/build/plugin-host.ts +13 -1
  20. package/src/build/prerender.ts +8 -3
  21. package/src/build/reach.ts +18 -4
  22. package/src/build/report.ts +1 -1
  23. package/src/build/resolve.ts +5 -1
  24. package/src/build/route-types.ts +16 -0
  25. package/src/build/routes.ts +42 -15
  26. package/src/build/seed-ids.ts +65 -0
  27. package/src/build/seed-writes.ts +111 -0
  28. package/src/build/static-headers.ts +2 -2
  29. package/src/build/static.ts +1 -1
  30. package/src/cli/check-cache.ts +51 -0
  31. package/src/cli/check-consent.ts +95 -0
  32. package/src/cli/check-forms.ts +10 -2
  33. package/src/cli/check-links-patterns.ts +101 -0
  34. package/src/cli/check-links.ts +30 -105
  35. package/src/cli/check-regions.ts +185 -0
  36. package/src/cli/check-security.ts +50 -6
  37. package/src/cli/check.ts +49 -21
  38. package/src/cli/commands.ts +138 -16
  39. package/src/cli/docs.ts +21 -2
  40. package/src/cli/form-opaque-children.ts +40 -0
  41. package/src/cli/index.ts +1 -1
  42. package/src/cli/inspect.ts +2 -0
  43. package/src/cli/mcp-tools.ts +2 -2
  44. package/src/cli/new.ts +9 -5
  45. package/src/cli/upgrade-names.ts +14 -2
  46. package/src/cli/upgrade.ts +3 -0
  47. package/src/compiler/analyze.ts +22 -16
  48. package/src/compiler/cacheability-private.ts +13 -3
  49. package/src/compiler/cacheability.ts +24 -2
  50. package/src/compiler/compliance-contrast.ts +322 -0
  51. package/src/compiler/compliance-empty.ts +24 -0
  52. package/src/compiler/compliance-rgaa-content.ts +95 -0
  53. package/src/compiler/compliance-rgaa-criteria.ts +45 -0
  54. package/src/compiler/compliance-rgaa-pages.ts +140 -0
  55. package/src/compiler/compliance-rgaa.ts +19 -0
  56. package/src/compiler/compliance-rules.ts +72 -0
  57. package/src/compiler/compliance-third-party.ts +59 -0
  58. package/src/compiler/compliance-urls.ts +52 -0
  59. package/src/compiler/compliance.ts +61 -93
  60. package/src/compiler/cookie-inventory.ts +119 -0
  61. package/src/compiler/dom-attrs.ts +178 -22
  62. package/src/compiler/dom.ts +31 -44
  63. package/src/compiler/emit.ts +17 -6
  64. package/src/compiler/expr-context.ts +260 -207
  65. package/src/compiler/foreign-imports.ts +5 -3
  66. package/src/compiler/mistakes.ts +18 -9
  67. package/src/compiler/props-body.ts +263 -21
  68. package/src/compiler/props-pattern.ts +211 -0
  69. package/src/compiler/props.ts +324 -343
  70. package/src/compiler/signal-reads.ts +142 -29
  71. package/src/compiler/spread-handlers.ts +25 -13
  72. package/src/compiler/ssr-emit.ts +510 -0
  73. package/src/compiler/ssr-helpers.ts +165 -121
  74. package/src/compiler/ssr.ts +28 -441
  75. package/src/context.ts +14 -1
  76. package/src/dev/child.ts +1 -1
  77. package/src/dev/host-check.ts +2 -1
  78. package/src/dev/hot-islands.ts +71 -0
  79. package/src/dev/index.ts +31 -18
  80. package/src/dev/protocol.ts +1 -1
  81. package/src/dev/queue.ts +3 -2
  82. package/src/dev/reload.ts +5 -2
  83. package/src/dev/supervisor.ts +3 -1
  84. package/src/dev/watchers.ts +6 -2
  85. package/src/dom/action.ts +97 -14
  86. package/src/dom/attrs.ts +93 -25
  87. package/src/dom/extras.ts +91 -50
  88. package/src/dom/field-marks.ts +32 -0
  89. package/src/dom/hot.ts +9 -0
  90. package/src/dom/index.ts +44 -18
  91. package/src/dom/island-hot.ts +29 -0
  92. package/src/dom/island.ts +13 -2
  93. package/src/dom/loop.ts +259 -188
  94. package/src/dom/prefetch.ts +135 -0
  95. package/src/dom/regions.ts +515 -0
  96. package/src/dom/swap.ts +246 -0
  97. package/src/dom/trusted.ts +22 -0
  98. package/src/dom/upload.ts +44 -0
  99. package/src/eco/declaration.ts +44 -41
  100. package/src/eco/index.ts +8 -5
  101. package/src/href.ts +31 -0
  102. package/src/index.ts +12 -5
  103. package/src/plugins/config.ts +1 -1
  104. package/src/plugins/context.ts +7 -1
  105. package/src/plugins/daily.ts +27 -0
  106. package/src/plugins/index.ts +3 -3
  107. package/src/plugins/order.ts +1 -1
  108. package/src/plugins/public.ts +12 -5
  109. package/src/plugins/services.ts +88 -14
  110. package/src/plugins/types.ts +128 -10
  111. package/src/reactivity/graph.ts +244 -41
  112. package/src/reactivity/hmr.ts +101 -0
  113. package/src/reactivity/index.ts +243 -239
  114. package/src/reactivity/resource.ts +129 -0
  115. package/src/reactivity/seed.ts +141 -0
  116. package/src/reactivity/selector.ts +85 -47
  117. package/src/reactivity/server-seed.ts +202 -0
  118. package/src/reactivity/store.ts +331 -97
  119. package/src/rgpd/draft.ts +171 -0
  120. package/src/rgpd/forms.ts +85 -0
  121. package/src/rgpd/index.ts +57 -0
  122. package/src/server/action-flash.ts +1 -0
  123. package/src/server/action-protect.ts +3 -0
  124. package/src/server/action-registry.ts +11 -9
  125. package/src/server/action.ts +51 -19
  126. package/src/server/app-secret.ts +14 -8
  127. package/src/server/cache-invalidation.ts +97 -0
  128. package/src/server/compress.ts +55 -18
  129. package/src/server/consent.ts +21 -5
  130. package/src/server/cookie-inventory.ts +78 -0
  131. package/src/server/cookies.ts +77 -8
  132. package/src/server/cors.ts +98 -0
  133. package/src/server/csp-report.ts +90 -0
  134. package/src/server/discard.ts +13 -0
  135. package/src/server/document.ts +2 -2
  136. package/src/server/env.ts +1 -1
  137. package/src/server/errors.ts +9 -2
  138. package/src/server/field-errors.ts +91 -0
  139. package/src/server/form-schema.ts +16 -11
  140. package/src/server/health.ts +41 -11
  141. package/src/server/http.ts +28 -11
  142. package/src/server/index.ts +122 -307
  143. package/src/server/loader.ts +2 -0
  144. package/src/server/page.ts +3 -9
  145. package/src/server/plugin-host.ts +66 -16
  146. package/src/server/plugin-route-shadow.ts +24 -0
  147. package/src/server/public.ts +14 -3
  148. package/src/server/rate-limit.ts +49 -10
  149. package/src/server/region.ts +22 -2
  150. package/src/server/request-handler.ts +406 -0
  151. package/src/server/request-log.ts +94 -0
  152. package/src/server/route-cache.ts +55 -8
  153. package/src/server/route-input.ts +54 -0
  154. package/src/server/route-table.ts +53 -27
  155. package/src/server/router.ts +2 -1
  156. package/src/server/routing.ts +104 -45
  157. package/src/server/sanitize-html.ts +4 -2
  158. package/src/server/security.ts +38 -8
  159. package/src/server/serve-handlers.ts +16 -6
  160. package/src/server/served-file.ts +19 -14
  161. package/src/server/shared-store.ts +323 -0
  162. package/src/server/start.ts +12 -5
  163. package/src/server/static-dir.ts +34 -12
  164. package/src/server/stream.ts +2 -1
  165. package/src/server/surface.ts +39 -0
  166. package/src/server/webhook.ts +50 -0
  167. package/src/server/workers.ts +168 -0
  168. package/src/ssr/consent-banner.ts +20 -16
  169. package/src/ssr/consent-texts.ts +40 -0
  170. package/src/ssr/context.ts +174 -53
  171. package/src/ssr/cookie-table.ts +75 -0
  172. package/src/ssr/index.ts +63 -58
  173. package/src/ssr/navigation.ts +161 -14
  174. package/src/ssr/region.ts +9 -3
  175. package/src/style.ts +12 -5
  176. package/src/test/browser.ts +53 -23
  177. package/src/test/build-reuse.ts +85 -0
  178. package/src/test/index.ts +51 -8
  179. package/src/test/mount.ts +53 -0
  180. package/src/test/outside.ts +94 -0
  181. package/src/ts-plugin/diagnostics.ts +56 -18
  182. package/templates/_shared/AGENTS.md +1 -1
  183. package/templates/_shared/Dockerfile +22 -0
  184. package/templates/_shared/dockerignore +9 -0
  185. package/templates/_shared/gitignore +2 -0
  186. package/templates/app/.env.example +3 -1
  187. package/templates/app/compose.yaml +32 -0
  188. package/templates/app/db/migrations/001_notes.sql +7 -0
  189. package/templates/app/db/schema.ts +11 -0
  190. package/templates/app/package.json +1 -0
  191. package/templates/app/prunelle.config.ts +6 -0
  192. package/templates/app/src/actions/notes.ts +26 -0
  193. package/templates/app/src/auth.ts +4 -2
  194. package/templates/app/src/db.ts +5 -0
  195. package/templates/app/src/routes/dashboard/index.tsx +26 -1
  196. package/templates/app/src/routes/privacy.tsx +6 -2
  197. package/templates/app/tests/app.test.ts +14 -3
  198. package/templates/plugin/AGENTS.md +11 -0
  199. package/templates/plugin/CLAUDE.md +1 -0
  200. package/templates/plugin/README.md +27 -0
  201. package/templates/plugin/gitignore +2 -0
  202. package/templates/plugin/llms.txt +19 -0
  203. package/templates/plugin/package.json +33 -0
  204. package/templates/plugin/src/index.ts +40 -0
  205. package/templates/plugin/tests/fixture/prunelle.config.ts +4 -0
  206. package/templates/plugin/tests/fixture/src/routes/index.tsx +11 -0
  207. package/templates/plugin/tests/plugin.test.ts +42 -0
  208. package/templates/plugin/tsconfig.json +19 -0
  209. package/ts-plugin.cjs +4058 -2246
@@ -113,9 +113,11 @@ export class StringParts {
113
113
  toExpr(): string {
114
114
  if (this.#parts.length === 0)
115
115
  return '""'
116
- return this.#parts
117
- .map(p => (p.static ? JSON.stringify(p.value) : `(${p.value})`))
118
- .join(' + ')
116
+ return this.#code().join(' + ')
117
+ }
118
+
119
+ #code(): string[] {
120
+ return this.#parts.map(p => (p.static ? JSON.stringify(p.value) : `(${p.value})`))
119
121
  }
120
122
  }
121
123
 
@@ -419,41 +421,172 @@ function emitSsrSpreadAttrs(
419
421
  return { textareaValue: undefined, nextSelectValue: undefined }
420
422
  }
421
423
 
424
+ type OptionValue = { staticValue?: string | undefined, expr?: string | undefined }
425
+ type ElementAttr = Extract<JSXAttributeItem, { type: 'JSXAttribute' }>
426
+
427
+ // What one pass over an element's attributes collects besides the static markup it pushes.
428
+ interface ElementAttrState {
429
+ innerHtmlExpr: string | undefined
430
+ textareaValue: SsrElementAttrsResult['textareaValue']
431
+ nextSelectValue: SelectValueBinding | undefined
432
+ optionValue: OptionValue | undefined
433
+ optionHasExplicitSelected: boolean
434
+ spreadEntries: string[]
435
+ }
436
+
437
+ function readInnerHtml(ctx: SsrElementAttrsContext, attr: ElementAttr, state: ElementAttrState): void {
438
+ if (attr.value?.type === 'Literal') {
439
+ state.innerHtmlExpr = JSON.stringify(String(attr.value.value))
440
+ }
441
+ else if (attr.value?.type === 'JSXExpressionContainer' && attr.value.expression.type !== 'JSXEmptyExpression') {
442
+ const lit = staticLiteralOrTemplate(attr.value.expression)
443
+ if (lit.ok)
444
+ state.innerHtmlExpr = lit.value === null || lit.value === false ? '""' : JSON.stringify(String(lit.value))
445
+ else
446
+ state.innerHtmlExpr = `${ctx.use('ssrRaw')}(${ctx.compileSubExpression(attr.value.expression)})`
447
+ }
448
+ }
449
+
450
+ function readTextareaValue(ctx: SsrElementAttrsContext, attr: ElementAttr, state: ElementAttrState): void {
451
+ if (attr.value?.type === 'Literal') {
452
+ state.textareaValue = { staticText: String(attr.value.value) }
453
+ }
454
+ else if (attr.value?.type === 'JSXExpressionContainer' && attr.value.expression.type !== 'JSXEmptyExpression') {
455
+ const lit = staticLiteralOrTemplate(attr.value.expression)
456
+ if (lit.ok)
457
+ state.textareaValue = { staticText: lit.value === null || typeof lit.value === 'boolean' ? '' : String(lit.value) }
458
+ else
459
+ state.textareaValue = { expr: ctx.compileSubExpression(attr.value.expression) }
460
+ }
461
+ }
462
+
463
+ function readSelectValue(ctx: SsrElementAttrsContext, attr: ElementAttr, selectIsMultiple: boolean, state: ElementAttrState): void {
464
+ if (attr.value?.type === 'Literal') {
465
+ state.nextSelectValue = { staticValue: String(attr.value.value), multiple: selectIsMultiple }
466
+ }
467
+ else if (attr.value?.type === 'JSXExpressionContainer' && attr.value.expression.type !== 'JSXEmptyExpression') {
468
+ const lit = staticLiteralOrTemplate(attr.value.expression)
469
+ if (lit.ok) {
470
+ if (lit.value !== null && typeof lit.value !== 'boolean')
471
+ state.nextSelectValue = { staticValue: String(lit.value), multiple: selectIsMultiple }
472
+ }
473
+ else {
474
+ const svVar = `_sv${ctx.nextId()}`
475
+ ctx.flushParts()
476
+ ctx.pushStmt(`const ${svVar} = ${ctx.compileSubExpression(attr.value.expression)};`)
477
+ state.nextSelectValue = { expr: svVar, multiple: selectIsMultiple }
478
+ }
479
+ }
480
+ }
481
+
482
+ // An attribute of an element with a spread: it becomes an entry of the props object the spread helper renders.
483
+ function collectSpreadEntry(ctx: SsrElementAttrsContext, attr: ElementAttr, name: string, isOption: boolean, state: ElementAttrState): void {
484
+ const { activeSelectValue, flushParts, pushStmt, nextId, compileSubExpression } = ctx
485
+ const propKey = /^[A-Za-z_$][\w$]*$/.test(name) ? name : JSON.stringify(name)
486
+ if (attr.value === null) {
487
+ state.spreadEntries.push(`${propKey}: true`)
488
+ }
489
+ else if (attr.value.type === 'Literal') {
490
+ if (isOption && name === 'value')
491
+ state.optionValue = { staticValue: String(attr.value.value) }
492
+ state.spreadEntries.push(`${propKey}: ${JSON.stringify(attr.value.value)}`)
493
+ }
494
+ else if (attr.value.type === 'JSXExpressionContainer' && attr.value.expression.type !== 'JSXEmptyExpression') {
495
+ const exprCode = compileSubExpression(attr.value.expression)
496
+ if (isOption && name === 'value' && activeSelectValue !== undefined) {
497
+ if (isSimpleValueExpr(attr.value.expression)) {
498
+ state.optionValue = { expr: exprCode }
499
+ state.spreadEntries.push(`${propKey}: ${exprCode}`)
500
+ }
501
+ else {
502
+ const ovVar = `_ov${nextId()}`
503
+ flushParts()
504
+ pushStmt(`const ${ovVar} = ${exprCode};`)
505
+ state.optionValue = { expr: ovVar }
506
+ state.spreadEntries.push(`${propKey}: ${ovVar}`)
507
+ }
508
+ }
509
+ else {
510
+ state.spreadEntries.push(`${propKey}: ${exprCode}`)
511
+ }
512
+ }
513
+ }
514
+
515
+ function emitPlainAttr(ctx: SsrElementAttrsContext, attr: ElementAttr, name: string, isOption: boolean, state: ElementAttrState): void {
516
+ const { tag, parts } = ctx
517
+ if (attr.value === null) {
518
+ parts.pushStatic(isStringBoolAttr(name) ? ` ${name}="true"` : ` ${name}`)
519
+ }
520
+ else if (attr.value.type === 'Literal') {
521
+ if (isOption && name === 'value')
522
+ state.optionValue = { staticValue: String(attr.value.value) }
523
+ parts.pushStatic(formatStaticAttrValue(name, String(attr.value.value), tag))
524
+ }
525
+ else if (attr.value.type === 'JSXExpressionContainer' && attr.value.expression.type !== 'JSXEmptyExpression') {
526
+ const opt = emitSsrExprAttr(ctx, name, attr.value.expression, isOption)
527
+ if (opt !== undefined)
528
+ state.optionValue = opt
529
+ }
530
+ }
531
+
532
+ // An `<option>` inside a `<select value>` is marked selected from its value, or from its text when it has none.
533
+ function emitOptionSelected(ctx: SsrElementAttrsContext, selectValue: SelectValueBinding, optionValue: OptionValue | undefined): void {
534
+ const { node, parts, compileSubExpression } = ctx
535
+ let value = optionValue
536
+ if (value === undefined) {
537
+ const textVal = staticOptionText(node.children)
538
+ if (textVal !== undefined) {
539
+ value = { staticValue: textVal }
540
+ }
541
+ else {
542
+ const meaningful = filterMeaningfulChildren(node.children)
543
+ if (
544
+ meaningful.length === 1
545
+ && meaningful[0]!.type === 'JSXExpressionContainer'
546
+ && meaningful[0]!.expression.type !== 'JSXEmptyExpression'
547
+ && isSimpleValueExpr(meaningful[0]!.expression)
548
+ ) {
549
+ value = { expr: compileSubExpression(meaningful[0]!.expression) }
550
+ }
551
+ }
552
+ }
553
+ if (value !== undefined) {
554
+ const sel = formatOptionSelectedExpr(selectValue, value)
555
+ if (sel.staticSelected === true)
556
+ parts.pushStatic(' selected')
557
+ else if (sel.expr !== undefined)
558
+ parts.pushExpr(sel.expr)
559
+ }
560
+ }
561
+
422
562
  /** Emits an HTML/SVG element's SSR opening attributes, handling spreads, `<textarea value>`, and `<select value>`/`<option>`. */
423
563
  export function emitSsrElementAttrs(ctx: SsrElementAttrsContext): SsrElementAttrsResult {
424
- const { node, tag, parts, activeSelectValue, flushParts, pushStmt, nextId, use, compileSubExpression } = ctx
564
+ const { node, tag, activeSelectValue, compileSubExpression } = ctx
425
565
  const attrs = node.openingElement.attributes
426
566
  const hasSpread = attrs.some(a => a.type === 'JSXSpreadAttribute')
427
567
  const isTextarea = tag === 'textarea'
428
568
  const isSelect = tag === 'select'
429
569
  const isOption = tag === 'option'
430
- let innerHtmlExpr: string | undefined
431
- let textareaValue: { staticText?: string | undefined, expr?: string | undefined } | undefined
432
- let nextSelectValue: SelectValueBinding | undefined
433
- let optionValue: { staticValue?: string | undefined, expr?: string | undefined } | undefined
434
- let optionHasExplicitSelected = false
435
570
  const selectIsMultiple = isSelect && attrs.some(a => a.type === 'JSXAttribute' && jsxTagName(a.name) === 'multiple')
436
- const spreadEntries: string[] = []
571
+ const state: ElementAttrState = {
572
+ innerHtmlExpr: undefined,
573
+ textareaValue: undefined,
574
+ nextSelectValue: undefined,
575
+ optionValue: undefined,
576
+ optionHasExplicitSelected: false,
577
+ spreadEntries: [],
578
+ }
437
579
 
438
580
  for (const attr of attrs) {
439
581
  if (attr.type === 'JSXSpreadAttribute') {
440
- spreadEntries.push(`...(${compileSubExpression(attr.argument)})`)
582
+ state.spreadEntries.push(`...(${compileSubExpression(attr.argument)})`)
441
583
  continue
442
584
  }
443
585
  const rawName = jsxTagName(attr.name)
444
586
  if (rawName === 'key' || rawName === 'ref' || rawName === '$hydrate' || EVENT_ATTR.test(rawName))
445
587
  continue
446
588
  if (rawName === 'innerHTML') {
447
- if (attr.value?.type === 'Literal') {
448
- innerHtmlExpr = JSON.stringify(String(attr.value.value))
449
- }
450
- else if (attr.value?.type === 'JSXExpressionContainer' && attr.value.expression.type !== 'JSXEmptyExpression') {
451
- const lit = staticLiteralOrTemplate(attr.value.expression)
452
- if (lit.ok)
453
- innerHtmlExpr = lit.value === null || lit.value === false ? '""' : JSON.stringify(String(lit.value))
454
- else
455
- innerHtmlExpr = `${use('ssrRaw')}(${compileSubExpression(attr.value.expression)})`
456
- }
589
+ readInnerHtml(ctx, attr, state)
457
590
  continue
458
591
  }
459
592
 
@@ -462,118 +595,29 @@ export function emitSsrElementAttrs(ctx: SsrElementAttrsContext): SsrElementAttr
462
595
  continue
463
596
 
464
597
  if (!hasSpread && isTextarea && name === 'value') {
465
- if (attr.value?.type === 'Literal') {
466
- textareaValue = { staticText: String(attr.value.value) }
467
- }
468
- else if (attr.value?.type === 'JSXExpressionContainer' && attr.value.expression.type !== 'JSXEmptyExpression') {
469
- const lit = staticLiteralOrTemplate(attr.value.expression)
470
- if (lit.ok)
471
- textareaValue = { staticText: lit.value === null || typeof lit.value === 'boolean' ? '' : String(lit.value) }
472
- else
473
- textareaValue = { expr: compileSubExpression(attr.value.expression) }
474
- }
598
+ readTextareaValue(ctx, attr, state)
475
599
  continue
476
600
  }
477
601
 
478
602
  if (!hasSpread && isSelect && name === 'value') {
479
- if (attr.value?.type === 'Literal') {
480
- nextSelectValue = { staticValue: String(attr.value.value), multiple: selectIsMultiple }
481
- }
482
- else if (attr.value?.type === 'JSXExpressionContainer' && attr.value.expression.type !== 'JSXEmptyExpression') {
483
- const lit = staticLiteralOrTemplate(attr.value.expression)
484
- if (lit.ok) {
485
- if (lit.value !== null && typeof lit.value !== 'boolean')
486
- nextSelectValue = { staticValue: String(lit.value), multiple: selectIsMultiple }
487
- }
488
- else {
489
- const svVar = `_sv${nextId()}`
490
- flushParts()
491
- pushStmt(`const ${svVar} = ${compileSubExpression(attr.value.expression)};`)
492
- nextSelectValue = { expr: svVar, multiple: selectIsMultiple }
493
- }
494
- }
603
+ readSelectValue(ctx, attr, selectIsMultiple, state)
495
604
  continue
496
605
  }
497
606
 
498
607
  if (isOption && name === 'selected')
499
- optionHasExplicitSelected = true
608
+ state.optionHasExplicitSelected = true
500
609
 
501
- if (hasSpread) {
502
- const propKey = /^[A-Za-z_$][\w$]*$/.test(name) ? name : JSON.stringify(name)
503
- if (attr.value === null) {
504
- spreadEntries.push(`${propKey}: true`)
505
- }
506
- else if (attr.value.type === 'Literal') {
507
- if (isOption && name === 'value')
508
- optionValue = { staticValue: String(attr.value.value) }
509
- spreadEntries.push(`${propKey}: ${JSON.stringify(attr.value.value)}`)
510
- }
511
- else if (attr.value.type === 'JSXExpressionContainer' && attr.value.expression.type !== 'JSXEmptyExpression') {
512
- const exprCode = compileSubExpression(attr.value.expression)
513
- if (isOption && name === 'value' && activeSelectValue !== undefined) {
514
- if (isSimpleValueExpr(attr.value.expression)) {
515
- optionValue = { expr: exprCode }
516
- spreadEntries.push(`${propKey}: ${exprCode}`)
517
- }
518
- else {
519
- const ovVar = `_ov${nextId()}`
520
- flushParts()
521
- pushStmt(`const ${ovVar} = ${exprCode};`)
522
- optionValue = { expr: ovVar }
523
- spreadEntries.push(`${propKey}: ${ovVar}`)
524
- }
525
- }
526
- else {
527
- spreadEntries.push(`${propKey}: ${exprCode}`)
528
- }
529
- }
530
- continue
531
- }
532
-
533
- if (attr.value === null) {
534
- parts.pushStatic(isStringBoolAttr(name) ? ` ${name}="true"` : ` ${name}`)
535
- }
536
- else if (attr.value.type === 'Literal') {
537
- if (isOption && name === 'value')
538
- optionValue = { staticValue: String(attr.value.value) }
539
- parts.pushStatic(formatStaticAttrValue(name, String(attr.value.value), tag))
540
- }
541
- else if (attr.value.type === 'JSXExpressionContainer' && attr.value.expression.type !== 'JSXEmptyExpression') {
542
- const opt = emitSsrExprAttr(ctx, name, attr.value.expression, isOption)
543
- if (opt !== undefined)
544
- optionValue = opt
545
- }
610
+ if (hasSpread)
611
+ collectSpreadEntry(ctx, attr, name, isOption, state)
612
+ else
613
+ emitPlainAttr(ctx, attr, name, isOption, state)
546
614
  }
547
615
 
548
616
  if (hasSpread)
549
- ({ textareaValue, nextSelectValue } = emitSsrSpreadAttrs(ctx, attrs, spreadEntries, selectIsMultiple))
617
+ ({ textareaValue: state.textareaValue, nextSelectValue: state.nextSelectValue } = emitSsrSpreadAttrs(ctx, attrs, state.spreadEntries, selectIsMultiple))
550
618
 
551
- if (isOption && activeSelectValue !== undefined && !optionHasExplicitSelected) {
552
- if (optionValue === undefined) {
553
- const textVal = staticOptionText(node.children)
554
- if (textVal !== undefined) {
555
- optionValue = { staticValue: textVal }
556
- }
557
- else {
558
- const meaningful = filterMeaningfulChildren(node.children)
559
- if (
560
- meaningful.length === 1
561
- && meaningful[0]!.type === 'JSXExpressionContainer'
562
- && meaningful[0]!.expression.type !== 'JSXEmptyExpression'
563
- && isSimpleValueExpr(meaningful[0]!.expression)
564
- ) {
565
- optionValue = { expr: compileSubExpression(meaningful[0]!.expression) }
566
- }
567
- }
568
- }
569
- if (optionValue !== undefined) {
570
- const sel = formatOptionSelectedExpr(activeSelectValue, optionValue)
571
- if (sel.staticSelected === true)
572
- parts.pushStatic(' selected')
573
- else if (sel.expr !== undefined)
574
- parts.pushExpr(sel.expr)
575
- }
576
- }
619
+ if (isOption && activeSelectValue !== undefined && !state.optionHasExplicitSelected)
620
+ emitOptionSelected(ctx, activeSelectValue, state.optionValue)
577
621
 
578
- return { innerHtmlExpr, textareaValue, nextSelectValue }
622
+ return { innerHtmlExpr: state.innerHtmlExpr, textareaValue: state.textareaValue, nextSelectValue: state.nextSelectValue }
579
623
  }