mirror of https://github.com/sveltejs/svelte
fix: transform computed keys in keyed each block destructuring patterns (#18521)
fixes #18519pull/18528/head
parent
8e4f26552c
commit
b4d1583ae2
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: transform computed keys in keyed `{#each}` destructuring patterns
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
<script>
|
||||||
|
let { labelKey, valueKey, options } = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#each options as { [labelKey]: label, [valueKey]: value } (value)}
|
||||||
|
<p>{label}: {value}</p>
|
||||||
|
{/each}
|
||||||
@ -0,0 +1,29 @@
|
|||||||
|
import { flushSync } from 'svelte';
|
||||||
|
import { ok, test } from '../../test';
|
||||||
|
|
||||||
|
// https://github.com/sveltejs/svelte/issues/18519
|
||||||
|
export default test({
|
||||||
|
html: `
|
||||||
|
<button>reverse</button>
|
||||||
|
<p>1: a1</p>
|
||||||
|
<p>2: a2</p>
|
||||||
|
<p>3: a3</p>
|
||||||
|
`,
|
||||||
|
|
||||||
|
test({ assert, target }) {
|
||||||
|
const btn = target.querySelector('button');
|
||||||
|
ok(btn);
|
||||||
|
|
||||||
|
flushSync(() => btn.click());
|
||||||
|
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`
|
||||||
|
<button>reverse</button>
|
||||||
|
<p>3: a3</p>
|
||||||
|
<p>2: a2</p>
|
||||||
|
<p>1: a1</p>
|
||||||
|
`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
@ -0,0 +1,12 @@
|
|||||||
|
<script>
|
||||||
|
import Child from './Child.svelte';
|
||||||
|
|
||||||
|
let options = $state([
|
||||||
|
{ a: 1, v: 'a1' },
|
||||||
|
{ a: 2, v: 'a2' },
|
||||||
|
{ a: 3, v: 'a3' }
|
||||||
|
]);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button onclick={() => options.reverse()}>reverse</button>
|
||||||
|
<Child {options} labelKey="a" valueKey="v" />
|
||||||
Loading…
Reference in new issue