From 50b905a531eeb2983e051116e678d5db408af879 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Thu, 15 Aug 2024 05:28:24 -0400 Subject: [PATCH] fix: skip unnecessary `$$legacy` flag (#12850) --- .changeset/tricky-coats-shop.md | 5 +++++ .../phases/3-transform/client/visitors/shared/component.js | 5 ++++- .../samples/purity/_expected/client/index.svelte.js | 6 +----- 3 files changed, 10 insertions(+), 6 deletions(-) create mode 100644 .changeset/tricky-coats-shop.md diff --git a/.changeset/tricky-coats-shop.md b/.changeset/tricky-coats-shop.md new file mode 100644 index 0000000000..b3d45933a3 --- /dev/null +++ b/.changeset/tricky-coats-shop.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: skip unnecessary `$$legacy` flag diff --git a/packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/component.js b/packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/component.js index 44f943ddec..7c43f68a66 100644 --- a/packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/component.js +++ b/packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/component.js @@ -298,7 +298,10 @@ export function build_component(node, component_name, context, anchor = context. push_prop(b.init('$$slots', b.object(serialized_slots))); } - if (!context.state.analysis.runes) { + if ( + !context.state.analysis.runes && + node.attributes.some((attribute) => attribute.type === 'BindDirective') + ) { push_prop(b.init('$$legacy', b.true)); } diff --git a/packages/svelte/tests/snapshot/samples/purity/_expected/client/index.svelte.js b/packages/svelte/tests/snapshot/samples/purity/_expected/client/index.svelte.js index 2863caba49..062e52f8cf 100644 --- a/packages/svelte/tests/snapshot/samples/purity/_expected/client/index.svelte.js +++ b/packages/svelte/tests/snapshot/samples/purity/_expected/client/index.svelte.js @@ -23,10 +23,6 @@ export default function Purity($$anchor) { var node = $.sibling($.sibling(p_1, true)); - Child(node, { - prop: encodeURIComponent(value), - $$legacy: true - }); - + Child(node, { prop: encodeURIComponent(value) }); $.append($$anchor, fragment); } \ No newline at end of file