fix: improve props aliasing (#9900)

pull/9901/head
Dominic Gannaway 1 year ago committed by GitHub
parent 0236cf87e7
commit a9a5b11c78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: improve props aliasing

@ -81,6 +81,9 @@ export function serialize_get_binding(node, state) {
return b.call(node);
}
if (binding.prop_alias) {
return b.member(b.id('$$props'), b.id(binding.prop_alias));
}
return b.member(b.id('$$props'), node);
}

@ -0,0 +1,5 @@
<script>
let { count: definedCount } = $props();
</script>
<button on:click={() => definedCount++}>{definedCount}</button>

@ -0,0 +1,32 @@
import { test } from '../../test';
export default test({
html: `
<p>0 0 0 0</p>
<button>0</button>
<button>0</button>
<button>0</button>
<button>0</button>
`,
async test({ assert, target, component }) {
const [b1, b2, b3, b4] = target.querySelectorAll('button');
b1.click();
b2.click();
b3.click();
b4.click();
await Promise.resolve();
assert.htmlEqual(
target.innerHTML,
`
<p>1 1 0 0</p>
<button>1</button>
<button>1</button>
<button>1</button>
<button>1</button>
`
);
}
});

@ -0,0 +1,15 @@
<script>
import Counter from './Counter.svelte';
let bound = $state(0);
let bound_nested = $state({count: 0});
let unbound = $state(0);
let unbound_nested = $state({count: 0});
</script>
<p>{bound} {bound_nested.count} {unbound} {unbound_nested.count}</p>
<Counter bind:count={bound} />
<Counter bind:count={bound_nested.count} />
<Counter count={unbound} />
<Counter count={unbound_nested.count} />
Loading…
Cancel
Save