Skip to content

Commit

Permalink
fix: create fewer deriveds for concatenated strings (#15041)
Browse files Browse the repository at this point in the history
* fix: create fewer deriveds for concatenated strings

* stringified_text -> expression
  • Loading branch information
Rich-Harris authored Jan 17, 2025
1 parent 2aefc54 commit 509ba56
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/rich-donkeys-wink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: create fewer deriveds for concatenated strings
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ export function build_template_chunk(values, visit, state) {
quasi.value.cooked += node.expression.value + '';
}
} else {
if (contains_multiple_call_expression) {
const id = b.id(state.scope.generate('stringified_text'));
if (node.metadata.expression.has_call && contains_multiple_call_expression) {
const id = b.id(state.scope.generate('expression'));
state.init.push(
b.const(
id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ export default function Text_nodes_deriveds($$anchor) {
}

var p = root();
const stringified_text = $.derived(() => text1() ?? '');
const stringified_text_1 = $.derived(() => text2() ?? '');
const expression = $.derived(() => text1() ?? '');
const expression_1 = $.derived(() => text2() ?? '');
var text = $.child(p);

$.template_effect(() => $.set_text(text, `${$.get(stringified_text)}${$.get(stringified_text_1)}`));
$.template_effect(() => $.set_text(text, `${$.get(expression)}${$.get(expression_1)}`));
$.reset(p);
$.append($$anchor, p);
}

0 comments on commit 509ba56

Please sign in to comment.