From 378093941d45259931d0c232a6029f3090184b5a Mon Sep 17 00:00:00 2001 From: Dominic Gannaway Date: Fri, 17 Nov 2023 13:03:51 +0000 Subject: [PATCH] fix: ensure we visit assignments during compilation (#9511) * fix: add missing visit for expressions * fix: add missing visit for expressions * Add test --- .changeset/wicked-doors-train.md | 5 +++++ .../3-transform/client/visitors/template.js | 2 +- .../bind-state-property/CheckBox.svelte | 5 +++++ .../samples/bind-state-property/_config.js | 12 ++++++++++++ .../samples/bind-state-property/main.svelte | 18 ++++++++++++++++++ 5 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 .changeset/wicked-doors-train.md create mode 100644 packages/svelte/tests/runtime-runes/samples/bind-state-property/CheckBox.svelte create mode 100644 packages/svelte/tests/runtime-runes/samples/bind-state-property/_config.js create mode 100644 packages/svelte/tests/runtime-runes/samples/bind-state-property/main.svelte diff --git a/.changeset/wicked-doors-train.md b/.changeset/wicked-doors-train.md new file mode 100644 index 0000000000..28b3271046 --- /dev/null +++ b/.changeset/wicked-doors-train.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: add missing visitor for assignments during compilation 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 942bfab8c6..615fafd880 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 @@ -775,7 +775,7 @@ function serialize_inline_component(node, component_name, context) { const assignment = b.assignment('=', attribute.expression, b.id('$$value')); push_prop( b.set(attribute.name, [ - b.stmt(serialize_set_binding(assignment, context, () => assignment)) + b.stmt(serialize_set_binding(assignment, context, () => context.visit(assignment))) ]) ); } diff --git a/packages/svelte/tests/runtime-runes/samples/bind-state-property/CheckBox.svelte b/packages/svelte/tests/runtime-runes/samples/bind-state-property/CheckBox.svelte new file mode 100644 index 0000000000..172b699205 --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/bind-state-property/CheckBox.svelte @@ -0,0 +1,5 @@ + + + diff --git a/packages/svelte/tests/runtime-runes/samples/bind-state-property/_config.js b/packages/svelte/tests/runtime-runes/samples/bind-state-property/_config.js new file mode 100644 index 0000000000..921fa71980 --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/bind-state-property/_config.js @@ -0,0 +1,12 @@ +import { test } from '../../test'; + +export default test({ + html: `
\nChecked:\nfalse`, + + async test({ assert, target }) { + const input = target.querySelector('input'); + + await input?.click(); + assert.htmlEqual(target.innerHTML, `
\nChecked:\ntrue`); + } +}); diff --git a/packages/svelte/tests/runtime-runes/samples/bind-state-property/main.svelte b/packages/svelte/tests/runtime-runes/samples/bind-state-property/main.svelte new file mode 100644 index 0000000000..2a571c5dd1 --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/bind-state-property/main.svelte @@ -0,0 +1,18 @@ + + +{#if true} + {@const obj = wrap()} + +{/if} +
+Checked: {checked}