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