From b20e1b7182fbb6ede852ff60b5fd42f421ce1870 Mon Sep 17 00:00:00 2001 From: Tan Li Hau Date: Fri, 18 Sep 2020 00:34:44 +0800 Subject: [PATCH 1/3] fix set store direct property assignment --- src/compiler/compile/render_dom/invalidate.ts | 2 +- .../_config.js | 32 +++++++++++++++++++ .../main.svelte | 24 ++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 test/runtime/samples/store-assignment-updates-property/_config.js create mode 100644 test/runtime/samples/store-assignment-updates-property/main.svelte diff --git a/src/compiler/compile/render_dom/invalidate.ts b/src/compiler/compile/render_dom/invalidate.ts index c7d9759ccd0..b045db079f3 100644 --- a/src/compiler/compile/render_dom/invalidate.ts +++ b/src/compiler/compile/render_dom/invalidate.ts @@ -62,7 +62,7 @@ export function invalidate(renderer: Renderer, scope: Scope, node: Node, names: } let invalidate = is_store_value - ? x`@set_store_value(${head.name.slice(1)}, ${node}, ${extra_args})` + ? x`@set_store_value(${head.name.slice(1)}, ${node}, ${head.name})` : !main_execution_context ? x`$$invalidate(${renderer.context_lookup.get(head.name).index}, ${node}, ${extra_args})` : extra_args.length diff --git a/test/runtime/samples/store-assignment-updates-property/_config.js b/test/runtime/samples/store-assignment-updates-property/_config.js new file mode 100644 index 00000000000..65df38f9e4b --- /dev/null +++ b/test/runtime/samples/store-assignment-updates-property/_config.js @@ -0,0 +1,32 @@ +export default { + html: ` +

a: {"foo":3,"bar":2}

+

b: {"foo":3}

+ + + `, + skip_if_ssr: true, + + async test({ assert, component, target, window }) { + const [btn1, btn2] = target.querySelectorAll('button'); + const click = new window.MouseEvent('click'); + + await btn1.dispatchEvent(click); + + assert.htmlEqual(target.innerHTML, ` +

a: {"foo":4,"bar":2}

+

b: {"foo":4,"baz":0}

+ + + `); + + await btn2.dispatchEvent(click); + + assert.htmlEqual(target.innerHTML, ` +

a: {"foo":5,"bar":2}

+

b: {"foo":5,"qux":0}

+ + + `); + } +}; \ No newline at end of file diff --git a/test/runtime/samples/store-assignment-updates-property/main.svelte b/test/runtime/samples/store-assignment-updates-property/main.svelte new file mode 100644 index 00000000000..16d69e9e0f4 --- /dev/null +++ b/test/runtime/samples/store-assignment-updates-property/main.svelte @@ -0,0 +1,24 @@ + + +

a: {JSON.stringify($a)}

+

b: {JSON.stringify($b)}

+ +