fix: improve props spreading logic (#10574)

pull/10571/head
Dominic Gannaway 7 months ago committed by GitHub
parent 96eae28ed2
commit 802bfcabec
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
"svelte": patch
---
fix: improve props spreading logic

@ -2337,14 +2337,7 @@ const rest_props_handler = {
return key in target.props;
},
ownKeys(target) {
/** @type {Array<string | symbol>} */
const keys = [];
for (let key in target.props) {
if (!target.exclude.includes(key)) keys.push(key);
}
return keys;
return Reflect.ownKeys(target.props).filter((key) => !target.exclude.includes(key));
}
};

@ -0,0 +1,7 @@
<script>
let { ...props } = $props();
</script>
<button {...props}>
Hello world
</button>

@ -0,0 +1,10 @@
import { test } from '../../test';
export default test({
async test({ assert, target }) {
assert.htmlEqual(
target.innerHTML,
`<button data-attr="">Hello world</button><button data-attr="">Hello world</button>`
);
}
});

@ -0,0 +1,16 @@
<script>
import Button from "./Button.svelte";
const attrs = {};
Object.defineProperty(attrs, "data-attr", {
value: "",
enumerable: true
});
</script>
<button {...attrs}>
Hello world
</button>
<Button {...attrs} />
Loading…
Cancel
Save