Skip to content

Commit 3780939

Browse files
authored
fix: ensure we visit assignments during compilation (#9511)
* fix: add missing visit for expressions * fix: add missing visit for expressions * Add test
1 parent 4418ba6 commit 3780939

File tree

5 files changed

+41
-1
lines changed

5 files changed

+41
-1
lines changed

.changeset/wicked-doors-train.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+
fix: add missing visitor for assignments during compilation

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ function serialize_inline_component(node, component_name, context) {
775775
const assignment = b.assignment('=', attribute.expression, b.id('$$value'));
776776
push_prop(
777777
b.set(attribute.name, [
778-
b.stmt(serialize_set_binding(assignment, context, () => assignment))
778+
b.stmt(serialize_set_binding(assignment, context, () => context.visit(assignment)))
779779
])
780780
);
781781
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<script>
2+
let { checked, ...rest } = $props();
3+
</script>
4+
5+
<input type="checkbox" bind:checked {...rest} />
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { test } from '../../test';
2+
3+
export default test({
4+
html: `<input type="checkbox"><br>\nChecked:\nfalse`,
5+
6+
async test({ assert, target }) {
7+
const input = target.querySelector('input');
8+
9+
await input?.click();
10+
assert.htmlEqual(target.innerHTML, `<input type="checkbox"><br>\nChecked:\ntrue`);
11+
}
12+
});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<script>
2+
import CheckBox from './CheckBox.svelte';
3+
4+
let checked = $state(false);
5+
function wrap() {
6+
return {
7+
get checked() { return checked },
8+
set checked(v) { checked = v },
9+
}
10+
}
11+
</script>
12+
13+
{#if true}
14+
{@const obj = wrap()}
15+
<CheckBox type="checkbox" bind:checked={obj.checked} />
16+
{/if}
17+
<br/>
18+
Checked: {checked}

0 commit comments

Comments
 (0)