fix: allow deletion of $$restProps properties (#12736)

pull/12718/head
Dominic Gannaway 5 months ago committed by GitHub
parent e66416bec7
commit 76cb89c750
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: allow deletion of $$restProps properties

@ -126,6 +126,13 @@ const legacy_rest_props_handler = {
}; };
} }
}, },
deleteProperty(target, key) {
// Svelte 4 allowed for deletions on $$restProps
if (target.exclude.includes(key)) return false;
target.exclude.push(key);
update(target.version);
return true;
},
has(target, key) { has(target, key) {
if (target.exclude.includes(key)) return false; if (target.exclude.includes(key)) return false;
return key in target.props; return key in target.props;

@ -0,0 +1,10 @@
<script>
function prune() {
$$restProps.a
delete $$restProps.a
}
</script>
<button on:click={prune}>delete a</button>
{JSON.stringify($$restProps)}

@ -0,0 +1,15 @@
import { flushSync } from 'svelte';
import { test } from '../../test';
export default test({
html: `<button>delete a</button>\n{"a":1,"b":2}`,
test({ assert, target }) {
const [btn1] = target.querySelectorAll('button');
btn1.click();
flushSync();
assert.htmlEqual(target.innerHTML, `<button>delete a</button>\n{"b":2}`);
}
});

@ -0,0 +1,5 @@
<script>
import App from "./App.svelte";
</script>
<App a={1} b={2} />
Loading…
Cancel
Save