fix: correctly handle action member expression keys

pull/9464/head
Dominic Gannaway 3 years ago
parent 9eb969ddd4
commit c3eac309b3

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: correctly handle action member expression keys

@ -2413,12 +2413,17 @@ export const template_visitors = {
if (node.expression) {
params.push(b.id('$$props'));
}
let callee;
if (node.name.includes('.')) {
const parts = node.name.split('.');
const key = b.key(parts[1]);
callee = b.member(serialize_get_binding(b.id(parts[0]), state), key, key.type === 'Literal');
} else {
callee = serialize_get_binding(b.id(node.name), state);
}
/** @type {import('estree').Expression[]} */
const args = [
state.node,
b.arrow(params, b.call(serialize_get_binding(b.id(node.name), state), ...params))
];
const args = [state.node, b.arrow(params, b.call(callee, ...params))];
if (node.expression) {
args.push(b.thunk(/** @type {import('estree').Expression} */ (visit(node.expression))));

@ -0,0 +1,10 @@
import { test } from '../../test';
export default test({
html: `
<span style="color: red;">Text</span>
`,
ssrHtml: `
<span>Text</span>
`
});

@ -0,0 +1,4 @@
<script>
const a = { 'set-color': (node, c) => node.style.color = c };
</script>
<span use:a.set-color={'red'}>Text</span>
Loading…
Cancel
Save