From aa661cf6cdc4e745f00799a6167fb15ae02e2f73 Mon Sep 17 00:00:00 2001 From: Tan Li Hau Date: Thu, 18 Jun 2020 21:28:31 +0800 Subject: [PATCH 1/2] fix extract names from ThisExpression --- src/compiler/compile/nodes/shared/Expression.ts | 7 ++----- .../samples/this-in-function-expressions/_config.js | 10 ++++++++++ .../samples/this-in-function-expressions/main.svelte | 2 ++ 3 files changed, 14 insertions(+), 5 deletions(-) create mode 100644 test/runtime/samples/this-in-function-expressions/_config.js create mode 100644 test/runtime/samples/this-in-function-expressions/main.svelte diff --git a/src/compiler/compile/nodes/shared/Expression.ts b/src/compiler/compile/nodes/shared/Expression.ts index f7c9897d586c..c7c66940fddb 100644 --- a/src/compiler/compile/nodes/shared/Expression.ts +++ b/src/compiler/compile/nodes/shared/Expression.ts @@ -120,12 +120,9 @@ export default class Expression { if (function_expression) { if (node.type === 'AssignmentExpression') { deep = node.left.type === 'MemberExpression'; - names = deep - ? [get_object(node.left).name] - : extract_names(node.left); + names = extract_names(deep ? get_object(node.left) : node.left); } else if (node.type === 'UpdateExpression') { - const { name } = get_object(node.argument); - names = [name]; + names = extract_names(get_object(node.argument)); } } diff --git a/test/runtime/samples/this-in-function-expressions/_config.js b/test/runtime/samples/this-in-function-expressions/_config.js new file mode 100644 index 000000000000..4110d05a48a0 --- /dev/null +++ b/test/runtime/samples/this-in-function-expressions/_config.js @@ -0,0 +1,10 @@ +export default { + async test({ assert, component, target, window, raf }) { + const [_, btn] = target.querySelectorAll("button"); + const clickEvent = new window.MouseEvent("click"); + + await btn.dispatchEvent(clickEvent); + + assert.equal(btn.x, 1); + }, +}; diff --git a/test/runtime/samples/this-in-function-expressions/main.svelte b/test/runtime/samples/this-in-function-expressions/main.svelte new file mode 100644 index 000000000000..af732920e9e3 --- /dev/null +++ b/test/runtime/samples/this-in-function-expressions/main.svelte @@ -0,0 +1,2 @@ +