chore: tidy up dynamic event handler generated code

pull/12553/head
Rich Harris 2 years ago
parent 90d6f573e3
commit 3558100bb5

@ -0,0 +1,5 @@
---
'svelte': patch
---
chore: tidy up dynamic event handler generated code

@ -1139,17 +1139,16 @@ function serialize_event_handler(node, { state, visit }) {
handler = node.expression;
// Event handlers can be dynamic (source/store/prop/conditional etc)
const dynamic_handler = () =>
b.function(
null,
const dynamic_handler = () => {
return b.arrow(
[b.rest(b.id('$$args'))],
b.block([
b.const('$$callback', /** @type {Expression} */ (visit(handler))),
b.return(
b.call(b.member(b.id('$$callback'), b.id('apply'), false, true), b.this, b.id('$$args'))
)
])
b.call(
b.member(/** @type {Expression} */ (visit(handler)), b.id('apply'), false, true),
b.this,
b.id('$$args')
)
);
};
if (handler.type === 'Identifier' || handler.type === 'MemberExpression') {
const id = object(handler);

Loading…
Cancel
Save