From 317282d7c8d1c52b0834311be1206678a43ca786 Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Fri, 6 Sep 2024 07:26:53 -0700 Subject: [PATCH] simplify --- .../client/visitors/RegularElement.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/packages/svelte/src/compiler/phases/3-transform/client/visitors/RegularElement.js b/packages/svelte/src/compiler/phases/3-transform/client/visitors/RegularElement.js index 7dea173eb8..1ec9840054 100644 --- a/packages/svelte/src/compiler/phases/3-transform/client/visitors/RegularElement.js +++ b/packages/svelte/src/compiler/phases/3-transform/client/visitors/RegularElement.js @@ -613,10 +613,10 @@ function build_element_attribute_update_assignment(element, node_id, attribute, ); } - const { has_expression_tag, can_inline } = + const inlinable_expression = attribute.value === true - ? { has_expression_tag: false, can_inline: true } - : can_inline_all_nodes( + ? false // not an expression + : is_inlinable_expression( Array.isArray(attribute.value) ? attribute.value : [attribute.value], context.state ); @@ -628,7 +628,7 @@ function build_element_attribute_update_assignment(element, node_id, attribute, } return true; } else { - if (has_expression_tag && can_inline) { + if (inlinable_expression) { push_template_quasi(context.state, ` ${name}="`); push_template_expression(context.state, value); push_template_quasi(context.state, '"'); @@ -643,8 +643,7 @@ function build_element_attribute_update_assignment(element, node_id, attribute, * @param {(AST.Text | AST.ExpressionTag)[]} nodes * @param {import('../types.js').ComponentClientTransformState} state */ -function can_inline_all_nodes(nodes, state) { - let can_inline = true; +function is_inlinable_expression(nodes, state) { let has_expression_tag = false; for (let value of nodes) { if (value.type === 'ExpressionTag') { @@ -652,14 +651,16 @@ function can_inline_all_nodes(nodes, state) { const binding = state.scope .owner(value.expression.name) ?.declarations.get(value.expression.name); - can_inline &&= can_inline_variable(binding); + if (!can_inline_variable(binding)) { + return false; + } } else { - can_inline = false; + return false; } has_expression_tag = true; } } - return { can_inline, has_expression_tag }; + return has_expression_tag; } /**