diff --git a/src/compiler/compile/render_dom/wrappers/shared/add_actions.ts b/src/compiler/compile/render_dom/wrappers/shared/add_actions.ts index 3d8c4fbbc0..7c0c6252a3 100644 --- a/src/compiler/compile/render_dom/wrappers/shared/add_actions.ts +++ b/src/compiler/compile/render_dom/wrappers/shared/add_actions.ts @@ -26,11 +26,19 @@ export function add_action(block: Block, target: string, action: Action) { block.add_variable(id); - const fn = block.renderer.reference(action.name); + const [obj, ...property] = action.name.split('.'); - block.event_listeners.push( - x`@action_destroyer(${id} = ${fn}.call(null, ${target}, ${snippet}))` - ); + const fn = block.renderer.reference(obj); + + if (property.length) { + block.event_listeners.push( + x`@action_destroyer(${id} = ${fn}.${property.join('.')}(${target}, ${snippet}))` + ); + } else { + block.event_listeners.push( + x`@action_destroyer(${id} = ${fn}.call(null, ${target}, ${snippet}))` + ); + } if (dependencies && dependencies.length > 0) { let condition = x`${id} && @is_function(${id}.update)`; diff --git a/test/runtime/samples/action-object/_config.js b/test/runtime/samples/action-object/_config.js new file mode 100644 index 0000000000..7fdc11af2b --- /dev/null +++ b/test/runtime/samples/action-object/_config.js @@ -0,0 +1,8 @@ +export default { + html: ` + + `, + async test({ assert, target, window }) { + assert.equal(target.querySelector('button').foo, 'bar1337'); + } +}; diff --git a/test/runtime/samples/action-object/main.svelte b/test/runtime/samples/action-object/main.svelte new file mode 100644 index 0000000000..f15e319e6f --- /dev/null +++ b/test/runtime/samples/action-object/main.svelte @@ -0,0 +1,10 @@ + + + \ No newline at end of file