Skip to content

Commit 48e78e4

Browse files
authored
chore: remove static value handling (#9571)
The deleted code ensured that a static variable wouldn't update when it's in the same text expression as a reactive variable. We solved this through emitting a warning about this instead, marking it as undefined behavior.
1 parent 5836c1c commit 48e78e4

File tree

2 files changed

+7
-31
lines changed

2 files changed

+7
-31
lines changed

.changeset/witty-camels-warn.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
chore: prevent some unused variable creation

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

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1598,37 +1598,8 @@ function serialize_template_literal(values, visit, state) {
15981598
if (node.type === 'ExpressionTag' && node.metadata.contains_call_expression) {
15991599
contains_call_expression = true;
16001600
}
1601-
let expression = visit(node.expression);
1602-
if (node.expression.type === 'Identifier') {
1603-
const name = node.expression.name;
1604-
const binding = scope.get(name);
1605-
// When we combine expressions as part of a single template element, we might
1606-
// be referencing variables that can be mutated, but are not actually state.
1607-
// In order to prevent this undesired behavior, we need ensure we cache the
1608-
// latest value we have of that variable before we process the template, enforcing
1609-
// the value remains static through the lifetime of the template.
1610-
if (binding !== null && binding.kind === 'normal' && binding.mutated) {
1611-
let has_already_cached = false;
1612-
// Check if we already create a const of this expression
1613-
for (let node of state.init) {
1614-
if (
1615-
node.type === 'VariableDeclaration' &&
1616-
node.declarations[0].id.type === 'Identifier' &&
1617-
node.declarations[0].id.name === name + '_const'
1618-
) {
1619-
has_already_cached = true;
1620-
expression = b.id(name + '_const');
1621-
break;
1622-
}
1623-
}
1624-
if (!has_already_cached) {
1625-
const tmp_id = scope.generate(name + '_const');
1626-
state.init.push(b.const(tmp_id, expression));
1627-
expression = b.id(tmp_id);
1628-
}
1629-
}
1630-
}
1631-
expressions.push(b.call('$.stringify', expression));
1601+
1602+
expressions.push(b.call('$.stringify', visit(node.expression)));
16321603
quasis.push(b.quasi('', i + 1 === values.length));
16331604
}
16341605
}

0 commit comments

Comments
 (0)