From e965e57aafe00c97e48814985f53b92d314ade67 Mon Sep 17 00:00:00 2001 From: Simon Holthausen Date: Mon, 26 Aug 2024 18:03:35 +0200 Subject: [PATCH] fix: don't reassign bound imports on the server fixes #13027 --- .changeset/heavy-insects-float.md | 5 ++++ .../server/visitors/shared/component.js | 28 +++++++++++-------- 2 files changed, 22 insertions(+), 11 deletions(-) create mode 100644 .changeset/heavy-insects-float.md diff --git a/.changeset/heavy-insects-float.md b/.changeset/heavy-insects-float.md new file mode 100644 index 0000000000..b57aa4d4f5 --- /dev/null +++ b/.changeset/heavy-insects-float.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: don't reassign bound imports on the server diff --git a/packages/svelte/src/compiler/phases/3-transform/server/visitors/shared/component.js b/packages/svelte/src/compiler/phases/3-transform/server/visitors/shared/component.js index 941088228a..3ae6d7ff06 100644 --- a/packages/svelte/src/compiler/phases/3-transform/server/visitors/shared/component.js +++ b/packages/svelte/src/compiler/phases/3-transform/server/visitors/shared/component.js @@ -80,22 +80,28 @@ export function build_inline_component(node, expression, context) { const value = build_attribute_value(attribute.value, context, false, true); push_prop(b.prop('init', b.key(attribute.name), value)); } else if (attribute.type === 'BindDirective' && attribute.name !== 'this') { - // TODO this needs to turn the whole thing into a while loop because the binding could be mutated eagerly in the child push_prop( b.get(attribute.name, [ b.return(/** @type {Expression} */ (context.visit(attribute.expression))) ]) ); - push_prop( - b.set(attribute.name, [ - b.stmt( - /** @type {Expression} */ ( - context.visit(b.assignment('=', attribute.expression, b.id('$$value'))) - ) - ), - b.stmt(b.assignment('=', b.id('$$settled'), b.false)) - ]) - ); + if ( + // Don't reassign imports + attribute.expression.type !== 'Identifier' || + attribute.expression.name !== attribute.name || + context.state.scope.get(attribute.name)?.declaration_kind !== 'import' + ) { + push_prop( + b.set(attribute.name, [ + b.stmt( + /** @type {Expression} */ ( + context.visit(b.assignment('=', attribute.expression, b.id('$$value'))) + ) + ), + b.stmt(b.assignment('=', b.id('$$settled'), b.false)) + ]) + ); + } } }