fix: ensure we visit assignments during compilation (#9511)

* fix: add missing visit for expressions

* fix: add missing visit for expressions

* Add test
pull/9492/head
Dominic Gannaway 1 year ago committed by GitHub
parent 4418ba6535
commit 378093941d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: add missing visitor for assignments during compilation

@ -775,7 +775,7 @@ function serialize_inline_component(node, component_name, context) {
const assignment = b.assignment('=', attribute.expression, b.id('$$value')); const assignment = b.assignment('=', attribute.expression, b.id('$$value'));
push_prop( push_prop(
b.set(attribute.name, [ b.set(attribute.name, [
b.stmt(serialize_set_binding(assignment, context, () => assignment)) b.stmt(serialize_set_binding(assignment, context, () => context.visit(assignment)))
]) ])
); );
} }

@ -0,0 +1,5 @@
<script>
let { checked, ...rest } = $props();
</script>
<input type="checkbox" bind:checked {...rest} />

@ -0,0 +1,12 @@
import { test } from '../../test';
export default test({
html: `<input type="checkbox"><br>\nChecked:\nfalse`,
async test({ assert, target }) {
const input = target.querySelector('input');
await input?.click();
assert.htmlEqual(target.innerHTML, `<input type="checkbox"><br>\nChecked:\ntrue`);
}
});

@ -0,0 +1,18 @@
<script>
import CheckBox from './CheckBox.svelte';
let checked = $state(false);
function wrap() {
return {
get checked() { return checked },
set checked(v) { checked = v },
}
}
</script>
{#if true}
{@const obj = wrap()}
<CheckBox type="checkbox" bind:checked={obj.checked} />
{/if}
<br/>
Checked: {checked}
Loading…
Cancel
Save