From 6ff6e7e8abcebbc386dfcb7aaf676c179814d522 Mon Sep 17 00:00:00 2001 From: paoloricciuti Date: Wed, 28 May 2025 17:21:49 +0200 Subject: [PATCH] fix: handle implicit values --- .../3-transform/server/visitors/shared/element.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/packages/svelte/src/compiler/phases/3-transform/server/visitors/shared/element.js b/packages/svelte/src/compiler/phases/3-transform/server/visitors/shared/element.js index e57afbb42a..af493e82b1 100644 --- a/packages/svelte/src/compiler/phases/3-transform/server/visitors/shared/element.js +++ b/packages/svelte/src/compiler/phases/3-transform/server/visitors/shared/element.js @@ -200,6 +200,8 @@ export function build_element_attributes(node, context) { } } + let option_has_value = false; + if (has_spread) { build_element_spread_attributes(node, attributes, style_directives, class_directives, context); } else { @@ -272,11 +274,23 @@ export function build_element_attributes(node, context) { } if (name === 'value' && node.name === 'option') { + option_has_value = true; context.state.template.push(b.call('$.maybe_selected', b.id('$$payload'), value)); } } } + if (!option_has_value && node.name === 'option') { + context.state.template.push( + b.call( + '$.maybe_selected', + b.id('$$payload'), + // this should be fine for the moment since option can only contain text and expressions + build_attribute_value(/** @type {*} */ (node.fragment.nodes), context) + ) + ); + } + if (events_to_capture.size !== 0) { for (const event of events_to_capture) { context.state.template.push(b.literal(` ${event}="this.__e=event"`));