Skip to content

Commit f6dd323

Browse files
committed
fix: allow runes for variable declarations in the template
1 parent 3eef1cb commit f6dd323

File tree

4 files changed

+45
-1
lines changed

4 files changed

+45
-1
lines changed

.changeset/red-poets-study.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: allow runes for variable declarations in the template

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3223,5 +3223,6 @@ export const template_visitors = {
32233223
node: b.id('$.document')
32243224
});
32253225
},
3226-
CallExpression: javascript_visitors_runes.CallExpression
3226+
CallExpression: javascript_visitors_runes.CallExpression,
3227+
VariableDeclaration: javascript_visitors_runes.VariableDeclaration
32273228
};
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { flushSync } from 'svelte';
2+
import { test } from '../../test';
3+
4+
export default test({
5+
html: `<form><input name="name"><button>Add</button></form>`,
6+
7+
async test({ assert, target }) {
8+
const btn = target.querySelector('button');
9+
10+
flushSync(() => {
11+
btn?.click();
12+
});
13+
14+
assert.htmlEqual(
15+
target.innerHTML,
16+
`<form><input name="name"><button>Add</button></form><div></div>`
17+
);
18+
}
19+
});
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<script>
2+
import { Set } from 'svelte/reactivity';
3+
const set = new Set();
4+
</script>
5+
6+
<form onsubmit={e => {
7+
e.preventDefault();
8+
const data = new FormData(e.target);
9+
const state = $state({ name: data.get('name') });
10+
set.add(state);
11+
e.target.reset();
12+
}}>
13+
<input name="name" />
14+
<button>Add</button>
15+
</form>
16+
17+
{#each set as item}
18+
<div>{item.name}</div>
19+
{/each}

0 commit comments

Comments
 (0)