Skip to content

Commit 317282d

Browse files
committed
simplify
1 parent bab6e9d commit 317282d

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

packages/svelte/src/compiler/phases/3-transform/client/visitors/RegularElement.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -613,10 +613,10 @@ function build_element_attribute_update_assignment(element, node_id, attribute,
613613
);
614614
}
615615

616-
const { has_expression_tag, can_inline } =
616+
const inlinable_expression =
617617
attribute.value === true
618-
? { has_expression_tag: false, can_inline: true }
619-
: can_inline_all_nodes(
618+
? false // not an expression
619+
: is_inlinable_expression(
620620
Array.isArray(attribute.value) ? attribute.value : [attribute.value],
621621
context.state
622622
);
@@ -628,7 +628,7 @@ function build_element_attribute_update_assignment(element, node_id, attribute,
628628
}
629629
return true;
630630
} else {
631-
if (has_expression_tag && can_inline) {
631+
if (inlinable_expression) {
632632
push_template_quasi(context.state, ` ${name}="`);
633633
push_template_expression(context.state, value);
634634
push_template_quasi(context.state, '"');
@@ -643,23 +643,24 @@ function build_element_attribute_update_assignment(element, node_id, attribute,
643643
* @param {(AST.Text | AST.ExpressionTag)[]} nodes
644644
* @param {import('../types.js').ComponentClientTransformState} state
645645
*/
646-
function can_inline_all_nodes(nodes, state) {
647-
let can_inline = true;
646+
function is_inlinable_expression(nodes, state) {
648647
let has_expression_tag = false;
649648
for (let value of nodes) {
650649
if (value.type === 'ExpressionTag') {
651650
if (value.expression.type === 'Identifier') {
652651
const binding = state.scope
653652
.owner(value.expression.name)
654653
?.declarations.get(value.expression.name);
655-
can_inline &&= can_inline_variable(binding);
654+
if (!can_inline_variable(binding)) {
655+
return false;
656+
}
656657
} else {
657-
can_inline = false;
658+
return false;
658659
}
659660
has_expression_tag = true;
660661
}
661662
}
662-
return { can_inline, has_expression_tag };
663+
return has_expression_tag;
663664
}
664665

665666
/**

0 commit comments

Comments
 (0)