From c0d670d8a3369fa850a88ea654e483b9f9d9a823 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Wed, 28 May 2025 18:02:25 -0400 Subject: [PATCH] simplify a bit (pass callback direct to valueless_option) --- .../server/visitors/RegularElement.js | 16 +++++++-- .../server/visitors/shared/element.js | 10 ------ packages/svelte/src/internal/server/index.js | 34 ++++++++++--------- .../_expected/server/index.svelte.js | 8 +---- 4 files changed, 32 insertions(+), 36 deletions(-) diff --git a/packages/svelte/src/compiler/phases/3-transform/server/visitors/RegularElement.js b/packages/svelte/src/compiler/phases/3-transform/server/visitors/RegularElement.js index 000df4b086..c19e995349 100644 --- a/packages/svelte/src/compiler/phases/3-transform/server/visitors/RegularElement.js +++ b/packages/svelte/src/compiler/phases/3-transform/server/visitors/RegularElement.js @@ -127,7 +127,16 @@ export function RegularElement(node, context) { } } - if (body === null) { + const is_option_with_implicit_value = + node.name === 'option' && + !node.attributes.some( + (attribute) => + attribute.type === 'SpreadAttribute' || + ((attribute.type === 'Attribute' || attribute.type === 'BindDirective') && + attribute.name === 'value') + ); + + if (body === null && !is_option_with_implicit_value) { process_children(trimmed, { ...context, state }); } else { // we need the body if: @@ -137,14 +146,15 @@ export function RegularElement(node, context) { const inner_state = { ...state, template: [], init: [] }; process_children(trimmed, { ...context, state: inner_state }); - if (node.name === 'option') { + if (is_option_with_implicit_value) { // in case of a valueless `