diff --git a/packages/svelte/src/compiler/phases/2-analyze/index.js b/packages/svelte/src/compiler/phases/2-analyze/index.js index 180934444a..89bfefe5a6 100644 --- a/packages/svelte/src/compiler/phases/2-analyze/index.js +++ b/packages/svelte/src/compiler/phases/2-analyze/index.js @@ -1178,20 +1178,19 @@ const common_visitors = { context.next(); - node.metadata.expression.has_state = get_attribute_chunks(node.value).some((chunk) => { - if (chunk.type !== 'ExpressionTag') { - return false; - } + for (const chunk of get_attribute_chunks(node.value)) { + if (chunk.type !== 'ExpressionTag') continue; if ( chunk.expression.type === 'FunctionExpression' || chunk.expression.type === 'ArrowFunctionExpression' ) { - return false; + continue; } - return chunk.metadata.expression.has_state; - }); + node.metadata.expression.has_state ||= chunk.metadata.expression.has_state; + node.metadata.expression.has_call ||= chunk.metadata.expression.has_call; + } if (is_event_attribute(node)) { const parent = context.path.at(-1); @@ -1234,9 +1233,13 @@ const common_visitors = { } } else { context.next(); - node.metadata.expression.has_state = get_attribute_chunks(node.value).some( - (node) => node.type === 'ExpressionTag' && node.metadata.expression.has_state - ); + + for (const chunk of get_attribute_chunks(node.value)) { + if (chunk.type !== 'ExpressionTag') continue; + + node.metadata.expression.has_state ||= chunk.metadata.expression.has_state; + node.metadata.expression.has_call ||= chunk.metadata.expression.has_call; + } } }, ExpressionTag(node, context) { diff --git a/packages/svelte/src/compiler/phases/3-transform/client/visitors/template.js b/packages/svelte/src/compiler/phases/3-transform/client/visitors/template.js index 1d11aea1ac..ac6a70852f 100644 --- a/packages/svelte/src/compiler/phases/3-transform/client/visitors/template.js +++ b/packages/svelte/src/compiler/phases/3-transform/client/visitors/template.js @@ -103,13 +103,11 @@ function serialize_style_directives(style_directives, element_id, context, is_at ) ); - const has_call = get_attribute_chunks(directive.value).some( - (v) => v.type === 'ExpressionTag' && v.metadata.expression.has_call - ); + const { has_state, has_call } = directive.metadata.expression; if (!is_attributes_reactive && has_call) { state.init.push(serialize_update(update)); - } else if (is_attributes_reactive || directive.metadata.expression.has_state || has_call) { + } else if (is_attributes_reactive || has_state || has_call) { state.update.push(update); } else { state.init.push(update);