Skip to content

Commit

Permalink
fix: read index as a source in legacy keyed each block (#14208)
Browse files Browse the repository at this point in the history
Fixes #14203
  • Loading branch information
paoloricciuti authored Nov 7, 2024
1 parent ea0d80e commit 53af138
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/late-dodos-film.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: read index as a source in legacy keyed each block
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export function EachBlock(node, context) {
// forbidden in runes mode
return b.member(
each_node_meta.array_name ? b.call(each_node_meta.array_name) : collection,
index,
(flags & EACH_INDEX_REACTIVE) !== 0 ? get_value(index) : index,
true
);
}
Expand All @@ -208,7 +208,7 @@ export function EachBlock(node, context) {

const left = b.member(
each_node_meta.array_name ? b.call(each_node_meta.array_name) : collection,
index,
(flags & EACH_INDEX_REACTIVE) !== 0 ? get_value(index) : index,
true
);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script>
export let item;
console.log(item);
item = 1;
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { test } from '../../test';

export default test({
async test({ assert, target, logs }) {
const p = target.querySelector('p');
assert.equal(p?.innerHTML, '1');
assert.deepEqual(logs, [0]);
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<script>
import Component from './Component.svelte';
const items = [0];
</script>

{#each items as item, idx(item)}
<Component bind:item />
{/each}

<p>{items}</p>

0 comments on commit 53af138

Please sign in to comment.