From 1a7753722536f3c1e451d9b19719487e4601ad56 Mon Sep 17 00:00:00 2001 From: Tan Li Hau Date: Sat, 2 Jan 2021 01:35:44 +0800 Subject: [PATCH] fix deep object property for action --- .../render_dom/wrappers/shared/add_actions.ts | 3 ++- test/runtime/samples/action-object-deep/_config.js | 8 ++++++++ test/runtime/samples/action-object-deep/main.svelte | 12 ++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 test/runtime/samples/action-object-deep/_config.js create mode 100644 test/runtime/samples/action-object-deep/main.svelte 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 6ca7de9a22..85aee6cd36 100644 --- a/src/compiler/compile/render_dom/wrappers/shared/add_actions.ts +++ b/src/compiler/compile/render_dom/wrappers/shared/add_actions.ts @@ -31,8 +31,9 @@ export function add_action(block: Block, target: string, action: Action) { const fn = block.renderer.reference(obj); if (properties.length) { + const member_expression = properties.reduce((lhs, rhs) => x`${lhs}.${rhs}`, fn); block.event_listeners.push( - x`@action_destroyer(${id} = ${fn}.${properties.join('.')}(${target}, ${snippet}))` + x`@action_destroyer(${id} = ${member_expression}(${target}, ${snippet}))` ); } else { block.event_listeners.push( diff --git a/test/runtime/samples/action-object-deep/_config.js b/test/runtime/samples/action-object-deep/_config.js new file mode 100644 index 0000000000..7fdc11af2b --- /dev/null +++ b/test/runtime/samples/action-object-deep/_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-deep/main.svelte b/test/runtime/samples/action-object-deep/main.svelte new file mode 100644 index 0000000000..75c35d628d --- /dev/null +++ b/test/runtime/samples/action-object-deep/main.svelte @@ -0,0 +1,12 @@ + + + \ No newline at end of file