Skip to content

Commit a9a5b11

Browse files
authored
fix: improve props aliasing (#9900)
1 parent 0236cf8 commit a9a5b11

File tree

5 files changed

+60
-0
lines changed

5 files changed

+60
-0
lines changed

.changeset/beige-rabbits-shave.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: improve props aliasing

packages/svelte/src/compiler/phases/3-transform/client/utils.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ export function serialize_get_binding(node, state) {
8181
return b.call(node);
8282
}
8383

84+
if (binding.prop_alias) {
85+
return b.member(b.id('$$props'), b.id(binding.prop_alias));
86+
}
8487
return b.member(b.id('$$props'), node);
8588
}
8689

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<script>
2+
let { count: definedCount } = $props();
3+
</script>
4+
5+
<button on:click={() => definedCount++}>{definedCount}</button>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { test } from '../../test';
2+
3+
export default test({
4+
html: `
5+
<p>0 0 0 0</p>
6+
<button>0</button>
7+
<button>0</button>
8+
<button>0</button>
9+
<button>0</button>
10+
`,
11+
12+
async test({ assert, target, component }) {
13+
const [b1, b2, b3, b4] = target.querySelectorAll('button');
14+
15+
b1.click();
16+
b2.click();
17+
b3.click();
18+
b4.click();
19+
await Promise.resolve();
20+
21+
assert.htmlEqual(
22+
target.innerHTML,
23+
`
24+
<p>1 1 0 0</p>
25+
<button>1</button>
26+
<button>1</button>
27+
<button>1</button>
28+
<button>1</button>
29+
`
30+
);
31+
}
32+
});
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<script>
2+
import Counter from './Counter.svelte';
3+
4+
let bound = $state(0);
5+
let bound_nested = $state({count: 0});
6+
let unbound = $state(0);
7+
let unbound_nested = $state({count: 0});
8+
</script>
9+
10+
<p>{bound} {bound_nested.count} {unbound} {unbound_nested.count}</p>
11+
12+
<Counter bind:count={bound} />
13+
<Counter bind:count={bound_nested.count} />
14+
<Counter count={unbound} />
15+
<Counter count={unbound_nested.count} />

0 commit comments

Comments
 (0)