Skip to content
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

fix: read index as a source in legacy keyed each block #14208

Merged
merged 1 commit into from
Nov 7, 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/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>
Loading