Skip to content

fix: allow runes for variable declarations in the template #10879

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/red-poets-study.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"svelte": patch
---

fix: allow runes for variable declarations in the template
Original file line number Diff line number Diff line change
Expand Up @@ -3223,5 +3223,6 @@ export const template_visitors = {
node: b.id('$.document')
});
},
CallExpression: javascript_visitors_runes.CallExpression
CallExpression: javascript_visitors_runes.CallExpression,
VariableDeclaration: javascript_visitors_runes.VariableDeclaration
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { flushSync } from 'svelte';
import { test } from '../../test';

export default test({
html: `<form><input name="name"><button>Add</button></form>`,

async test({ assert, target }) {
const btn = target.querySelector('button');

flushSync(() => {
btn?.click();
});

assert.htmlEqual(
target.innerHTML,
`<form><input name="name"><button>Add</button></form><div></div>`
);
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<script>
import { Set } from 'svelte/reactivity';
const set = new Set();
</script>

<form onsubmit={e => {
e.preventDefault();
const data = new FormData(e.target);
const state = $state({ name: data.get('name') });
set.add(state);
e.target.reset();
}}>
<input name="name" />
<button>Add</button>
</form>

{#each set as item}
<div>{item.name}</div>
{/each}