Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix invalidation in ++foo.bar #4395

Merged
merged 3 commits into from
Feb 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* Permit reserved keywords as destructuring keys in `{#each}` ([#4372](https://github.com/sveltejs/svelte/issues/4372))
* Disallow reserved keywords in `{expressions}` ([#4372](https://github.com/sveltejs/svelte/issues/4372))
* Fix code generation error with precedence of arrow functions ([#4384](https://github.com/sveltejs/svelte/issues/4384))
* Fix invalidation in expressions like `++foo.bar` ([#4393](https://github.com/sveltejs/svelte/issues/4393))

## 3.18.1

Expand Down
2 changes: 1 addition & 1 deletion src/compiler/compile/render_dom/invalidate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function invalidate(renderer: Renderer, scope: Scope, node: Node, names:
const pass_value = (
extra_args.length > 0 ||
(node.type === 'AssignmentExpression' && node.left.type !== 'Identifier') ||
(node.type === 'UpdateExpression' && !node.prefix)
(node.type === 'UpdateExpression' && (!node.prefix || node.argument.type !== 'Identifier'))
);

if (pass_value) {
Expand Down
31 changes: 31 additions & 0 deletions test/runtime/samples/instrumentation-update-expression/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
export default {
html: `
<p>0</p>
<button>foo++</button>
<button>++foo</button>
<p>0</p>
<button>bar.bar++</button>
<button>++bar.bar</button>
`,
async test({ assert, target, window }) {
const [foo, bar] = target.querySelectorAll('p');
const [button1, button2, button3, button4] = target.querySelectorAll('button');
const event = new window.MouseEvent('click');

await button1.dispatchEvent(event);
assert.equal(foo.innerHTML, '1');
assert.equal(bar.innerHTML, '0');

await button2.dispatchEvent(event);
assert.equal(foo.innerHTML, '2');
assert.equal(bar.innerHTML, '0');

await button3.dispatchEvent(event);
assert.equal(foo.innerHTML, '2');
assert.equal(bar.innerHTML, '1');

await button4.dispatchEvent(event);
assert.equal(foo.innerHTML, '2');
assert.equal(bar.innerHTML, '2');
}
};
14 changes: 14 additions & 0 deletions test/runtime/samples/instrumentation-update-expression/main.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<script>
let foo = 0;
let bar = { bar: 0 };
</script>

<p>{foo}</p>

<button on:click={() => foo++}>foo++</button>
<button on:click={() => ++foo}>++foo</button>

<p>{bar.bar}</p>

<button on:click={() => bar.bar++}>bar.bar++</button>
<button on:click={() => ++bar.bar}>++bar.bar</button>