Skip to content

Commit

Permalink
fix: ensure we visit assignments during compilation (#9511)
Browse files Browse the repository at this point in the history
* fix: add missing visit for expressions

* fix: add missing visit for expressions

* Add test
  • Loading branch information
trueadm authored Nov 17, 2023
1 parent 4418ba6 commit 3780939
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/wicked-doors-train.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: add missing visitor for assignments during compilation
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
])
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script>
let { checked, ...rest } = $props();
</script>

<input type="checkbox" bind:checked {...rest} />
Original file line number Diff line number Diff line change
@@ -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`);
}
});
Original file line number Diff line number Diff line change
@@ -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}

1 comment on commit 3780939

@vercel
Copy link

@vercel vercel bot commented on 3780939 Nov 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

svelte-5-preview – ./sites/svelte-5-preview

svelte-5-preview-git-main-svelte.vercel.app
svelte-5-preview-svelte.vercel.app
svelte-5-preview.vercel.app
svelte-octane.vercel.app

Please sign in to comment.