diff --git a/packages/svelte/src/compiler/phases/2-analyze/visitors/ExpressionTag.js b/packages/svelte/src/compiler/phases/2-analyze/visitors/ExpressionTag.js index fa15ad3e56..86a2f6a9e1 100644 --- a/packages/svelte/src/compiler/phases/2-analyze/visitors/ExpressionTag.js +++ b/packages/svelte/src/compiler/phases/2-analyze/visitors/ExpressionTag.js @@ -22,7 +22,7 @@ export function ExpressionTag(node, context) { * the subtree as dynamic. This is because if it's inlinable it will be inlined in the template * directly making the whole thing actually static. */ - if (!attribute_parent || !is_inlinable_expression(node, context.state.scope)) { + if (!attribute_parent || !is_inlinable_expression(attribute_parent, context.state.scope)) { // TODO ideally we wouldn't do this here, we'd just do it on encountering // an `Identifier` within the tag. But we currently need to handle `{42}` etc mark_subtree_dynamic(context.path); diff --git a/packages/svelte/src/compiler/phases/2-analyze/visitors/Identifier.js b/packages/svelte/src/compiler/phases/2-analyze/visitors/Identifier.js index 0b38815a40..c0509a5414 100644 --- a/packages/svelte/src/compiler/phases/2-analyze/visitors/Identifier.js +++ b/packages/svelte/src/compiler/phases/2-analyze/visitors/Identifier.js @@ -21,7 +21,6 @@ export function Identifier(node, context) { return; } - const expression_tag_parent = context.path.find((parent) => parent.type === 'ExpressionTag'); const attribute_parent = context.path.find((parent) => parent.type === 'Attribute'); /** @@ -29,11 +28,7 @@ export function Identifier(node, context) { * before marking the subtree as dynamic. This is because if it's inlinable it will be inlined in the template * directly making the whole thing actually static. */ - if ( - !attribute_parent || - !expression_tag_parent || - !is_inlinable_expression(expression_tag_parent, context.state.scope) - ) { + if (!attribute_parent || !is_inlinable_expression(attribute_parent, context.state.scope)) { mark_subtree_dynamic(context.path); } 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 e3792edddc..649762994a 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 @@ -578,10 +578,7 @@ function build_element_attribute_update_assignment(element, node_id, attribute, ); } - const inlinable_expression = - attribute.value === true - ? false // not an expression - : is_inlinable_expression(attribute.value, context.state.scope); + const inlinable_expression = is_inlinable_expression(attribute, context.state.scope); if (attribute.metadata.expression.has_state) { if (has_call) { state.init.push(build_update(update)); diff --git a/packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/fragment.js b/packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/fragment.js index 2bfe44972a..2934df81f8 100644 --- a/packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/fragment.js +++ b/packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/fragment.js @@ -159,7 +159,7 @@ function is_static_element(node, state) { !is_text_attribute(attribute) && // If the attribute is not a text attribute but is inlinable we will directly inline it in the // the template so before returning false we need to check that the attribute is not inlinable - !is_inlinable_expression(attribute.value, state.scope) + !is_inlinable_expression(attribute, state.scope) ) { return false; } diff --git a/packages/svelte/src/compiler/phases/utils.js b/packages/svelte/src/compiler/phases/utils.js index 10b82c2a71..116f03ca91 100644 --- a/packages/svelte/src/compiler/phases/utils.js +++ b/packages/svelte/src/compiler/phases/utils.js @@ -1,4 +1,5 @@ /** @import { AST, Binding } from '#compiler' */ +/** @import { Scope } from './scope' */ /** * Whether a variable can be referenced directly from template string. @@ -16,11 +17,12 @@ function can_inline_variable(binding) { } /** - * @param {(AST.Text | AST.ExpressionTag) | (AST.Text | AST.ExpressionTag)[]} node_or_nodes - * @param {import('./scope.js').Scope} scope + * @param {AST.Attribute} attribute + * @param {Scope} scope */ -export function is_inlinable_expression(node_or_nodes, scope) { - let nodes = Array.isArray(node_or_nodes) ? node_or_nodes : [node_or_nodes]; +export function is_inlinable_expression(attribute, scope) { + if (attribute.value === true) return false; // not an expression + let nodes = Array.isArray(attribute.value) ? attribute.value : [attribute.value]; let has_expression_tag = false; for (let value of nodes) { if (value.type === 'ExpressionTag') {