Skip to content

Commit 08a24f1

Browse files
committed
fix, add test
1 parent 9071bd4 commit 08a24f1

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -298,18 +298,13 @@ export function EachBlock(node, context) {
298298
let key_function = b.id('$.index');
299299

300300
if (node.metadata.keyed) {
301-
const pattern = node.context;
302301
const expression = /** @type {Expression} */ (
303302
context.visit(/** @type {Expression} */ (node.key), key_state)
304303
);
305-
/** @type {Pattern[]} */
306-
const args = [];
307-
if (pattern) {
308-
args.push(pattern);
309-
}
310-
if (key_uses_index) {
311-
args.push(index);
312-
}
304+
305+
const args = [node.context ?? b.id('$$')];
306+
if (key_uses_index) args.push(index);
307+
313308
key_function = b.arrow(args, expression);
314309
}
315310

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { flushSync } from 'svelte';
2+
import { test } from '../../test';
3+
4+
export default test({
5+
html: `<button>update</button><p>3</p><p>2</p><p>1</p>`,
6+
7+
async test({ target, assert }) {
8+
const [button] = target.querySelectorAll('button');
9+
10+
flushSync(() => button.click());
11+
assert.htmlEqual(target.innerHTML, `<button>update</button><p>1</p><p>2</p><p>3</p>`);
12+
}
13+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<script>
2+
let items = $state([{ id: 3 }, { id: 2 }, { id: 1 }]);
3+
</script>
4+
5+
<button onclick={() => items = [{ id: 1 }, { id: 2 }, { id: 3 }]}>
6+
update
7+
</button>
8+
9+
{#each items, i (items[i].id)}
10+
<p>{items[i].id}</p>
11+
{/each}

0 commit comments

Comments
 (0)