From 3f43154b321bec345844f2836ddfbee2a5a47b88 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Mon, 20 Nov 2023 18:00:32 -0500 Subject: [PATCH 1/2] delete weird code --- .../3-transform/client/visitors/template.js | 33 ++----------------- 1 file changed, 2 insertions(+), 31 deletions(-) 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 615fafd88080..92775fdd9281 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 @@ -1533,37 +1533,8 @@ function serialize_template_literal(values, visit, state) { if (node.type === 'ExpressionTag' && node.metadata.contains_call_expression) { contains_call_expression = true; } - let expression = visit(node.expression); - if (node.expression.type === 'Identifier') { - const name = node.expression.name; - const binding = scope.get(name); - // When we combine expressions as part of a single template element, we might - // be referencing variables that can be mutated, but are not actually state. - // In order to prevent this undesired behavior, we need ensure we cache the - // latest value we have of that variable before we process the template, enforcing - // the value remains static through the lifetime of the template. - if (binding !== null && binding.kind === 'normal' && binding.mutated) { - let has_already_cached = false; - // Check if we already create a const of this expression - for (let node of state.init) { - if ( - node.type === 'VariableDeclaration' && - node.declarations[0].id.type === 'Identifier' && - node.declarations[0].id.name === name + '_const' - ) { - has_already_cached = true; - expression = b.id(name + '_const'); - break; - } - } - if (!has_already_cached) { - const tmp_id = scope.generate(name + '_const'); - state.init.push(b.const(tmp_id, expression)); - expression = b.id(tmp_id); - } - } - } - expressions.push(b.call('$.stringify', expression)); + + expressions.push(b.call('$.stringify', visit(node.expression))); quasis.push(b.quasi('', i + 1 === values.length)); } } From 90a7aec920ff4fd543e4cda88bfe896bec75c68b Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Mon, 20 Nov 2023 18:02:12 -0500 Subject: [PATCH 2/2] changeset --- .changeset/witty-camels-warn.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/witty-camels-warn.md diff --git a/.changeset/witty-camels-warn.md b/.changeset/witty-camels-warn.md new file mode 100644 index 000000000000..cdcccd6ac654 --- /dev/null +++ b/.changeset/witty-camels-warn.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +chore: prevent some unused variable creation