fix: get spread + bind working (#10091)

fixes #10033
pull/10116/head
Simon H 12 months ago committed by GitHub
parent 6acf7f3fc3
commit 92408e1506
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: take into account setters when spreading and binding

@ -2646,8 +2646,13 @@ const spread_props_handler = {
if (typeof p === 'object' && p !== null && key in p) return p[key]; if (typeof p === 'object' && p !== null && key in p) return p[key];
} }
}, },
getOwnPropertyDescriptor() { getOwnPropertyDescriptor(target, key) {
return { enumerable: true, configurable: true }; let i = target.props.length;
while (i--) {
let p = target.props[i];
if (is_function(p)) p = p();
if (typeof p === 'object' && p !== null && key in p) return get_descriptor(p, key);
}
}, },
has(target, key) { has(target, key) {
for (let p of target.props) { for (let p of target.props) {

@ -0,0 +1,21 @@
import { test } from '../../test';
export default test({
html: `<button class="foo">0</button><button class="foo">0</button>`,
async test({ assert, target }) {
const [btn1, btn2] = target.querySelectorAll('button');
await btn1?.click();
assert.htmlEqual(
target.innerHTML,
`<button class="foo">1</button><button class="foo">1</button>`
);
await btn2?.click();
assert.htmlEqual(
target.innerHTML,
`<button class="foo">2</button><button class="foo">2</button>`
);
}
});

@ -0,0 +1,6 @@
<script>
let { value, ...props } = $props();
</script>
<button {...props} onclick={() => value++}>{value}</button>

@ -0,0 +1,12 @@
<script>
import Button from './button.svelte';
let value = $state(0);
const props = {
class: 'foo'
};
</script>
<Button {...props} bind:value />
<button {...props} onclick={() => value++}>{value}</button>
Loading…
Cancel
Save