Skip to content

Commit c3eac30

Browse files
committed
fix: correctly handle action member expression keys
1 parent 9eb969d commit c3eac30

File tree

4 files changed

+28
-4
lines changed

4 files changed

+28
-4
lines changed

.changeset/grumpy-students-drop.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: correctly handle action member expression keys

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2413,12 +2413,17 @@ export const template_visitors = {
24132413
if (node.expression) {
24142414
params.push(b.id('$$props'));
24152415
}
2416+
let callee;
2417+
if (node.name.includes('.')) {
2418+
const parts = node.name.split('.');
2419+
const key = b.key(parts[1]);
2420+
callee = b.member(serialize_get_binding(b.id(parts[0]), state), key, key.type === 'Literal');
2421+
} else {
2422+
callee = serialize_get_binding(b.id(node.name), state);
2423+
}
24162424

24172425
/** @type {import('estree').Expression[]} */
2418-
const args = [
2419-
state.node,
2420-
b.arrow(params, b.call(serialize_get_binding(b.id(node.name), state), ...params))
2421-
];
2426+
const args = [state.node, b.arrow(params, b.call(callee, ...params))];
24222427

24232428
if (node.expression) {
24242429
args.push(b.thunk(/** @type {import('estree').Expression} */ (visit(node.expression))));
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { test } from '../../test';
2+
3+
export default test({
4+
html: `
5+
<span style="color: red;">Text</span>
6+
`,
7+
ssrHtml: `
8+
<span>Text</span>
9+
`
10+
});
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<script>
2+
const a = { 'set-color': (node, c) => node.style.color = c };
3+
</script>
4+
<span use:a.set-color={'red'}>Text</span>

0 commit comments

Comments
 (0)