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

pull/10869/head
Dominic Gannaway 1 year ago committed by GitHub
parent 852eca4ee6
commit 83f30bf0e8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
"svelte": patch
---
fix: allow runes for variable declarations in the template

@ -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
};

@ -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>`
);
}
});

@ -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}
Loading…
Cancel
Save