fix: allow binding to const with spread in legacy mode (#13849)

pull/13870/head
Paolo Ricciuti 3 months ago committed by GitHub
parent 4fbd2a6f10
commit 04c38b089f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: allow binding to const with spread in legacy mode

@ -177,6 +177,19 @@ const spread_props_handler = {
if (typeof p === 'object' && p !== null && key in p) return p[key];
}
},
set(target, key, value) {
let i = target.props.length;
while (i--) {
let p = target.props[i];
if (is_function(p)) p = p();
const desc = get_descriptor(p, key);
if (desc && desc.set) {
desc.set(value);
return true;
}
}
return false;
},
getOwnPropertyDescriptor(target, key) {
let i = target.props.length;
while (i--) {

@ -270,7 +270,12 @@ export function spread_props(props) {
for (let i = 0; i < props.length; i++) {
const obj = props[i];
for (key in obj) {
merged_props[key] = obj[key];
const desc = Object.getOwnPropertyDescriptor(obj, key);
if (desc) {
Object.defineProperty(merged_props, key, desc);
} else {
merged_props[key] = obj[key];
}
}
}
return merged_props;

@ -0,0 +1,9 @@
import { test } from '../../test';
export default test({
html: `<p>42</p>`,
async test({ target, assert }) {
const p = target.querySelector('p');
assert.equal(p?.innerHTML, '42');
}
});

@ -0,0 +1,11 @@
<script>
import Test from "./Test.svelte";
let x;
</script>
<Test
bind:x
{...{}}
/>
<p>{x}</p>
Loading…
Cancel
Save