From 62acfb9e25994d688726cf7e7fffcbb1e7757e40 Mon Sep 17 00:00:00 2001 From: Tan Li Hau Date: Thu, 21 May 2020 17:55:57 +0800 Subject: [PATCH] called reactive functions for reassignments --- src/compiler/compile/nodes/Binding.ts | 2 +- .../_config.js | 27 +++++++++++++++++++ .../main.svelte | 10 +++++++ 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 test/runtime/samples/reactive-function-called-reassigned/_config.js create mode 100644 test/runtime/samples/reactive-function-called-reassigned/main.svelte diff --git a/src/compiler/compile/nodes/Binding.ts b/src/compiler/compile/nodes/Binding.ts index 2f199709c8..af2d279bf3 100644 --- a/src/compiler/compile/nodes/Binding.ts +++ b/src/compiler/compile/nodes/Binding.ts @@ -60,7 +60,7 @@ export default class Binding extends Node { scope.dependencies_for_name.get(name).forEach(name => { const variable = component.var_lookup.get(name); if (variable) { - variable[this.expression.node.type === 'MemberExpression' ? 'mutated' : 'reassigned'] = true; + variable['mutated'] = true; } }); } else { diff --git a/test/runtime/samples/reactive-function-called-reassigned/_config.js b/test/runtime/samples/reactive-function-called-reassigned/_config.js new file mode 100644 index 0000000000..317173f8eb --- /dev/null +++ b/test/runtime/samples/reactive-function-called-reassigned/_config.js @@ -0,0 +1,27 @@ +let value; +let called = 0; +function callback(_value) { + called ++; + value = _value; +} + +export default { + props: { + callback, + }, + async test({ assert, component, target, window }) { + assert.equal(called, 1); + + const input = target.querySelector('input'); + + const event = new window.Event('input'); + input.value = 'h'; + await input.dispatchEvent(event); + + assert.equal(called, 2); + assert.equal(value.length, 3); + assert.equal(value[0], 'h'); + assert.equal(value[1], '2'); + assert.equal(value[2], '3'); + } +}; diff --git a/test/runtime/samples/reactive-function-called-reassigned/main.svelte b/test/runtime/samples/reactive-function-called-reassigned/main.svelte new file mode 100644 index 0000000000..10a3c79d14 --- /dev/null +++ b/test/runtime/samples/reactive-function-called-reassigned/main.svelte @@ -0,0 +1,10 @@ + + +{#each refs as ref} + +{/each} \ No newline at end of file