mirror of https://github.com/sveltejs/svelte
fix: increment and decrement edge case (#11506)
* fix: increment and decrement edge case * fix/simplify test * simplify * Apply suggestions from code review * golf --------- Co-authored-by: Rich Harris <rich.harris@vercel.com> Co-authored-by: Rich Harris <hello@rich-harris.dev>pull/11512/head
parent
8318b3d142
commit
0cf6d56ffe
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"svelte": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: coerce incremented/decremented sources
|
@ -0,0 +1,24 @@
|
|||||||
|
import { flushSync } from 'svelte';
|
||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
html: `
|
||||||
|
<button>update</button>
|
||||||
|
<p>0, 0, 0, 0</p>
|
||||||
|
`,
|
||||||
|
|
||||||
|
test({ target, assert, logs }) {
|
||||||
|
const btn = target.querySelector('button');
|
||||||
|
flushSync(() => btn?.click());
|
||||||
|
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`
|
||||||
|
<button>update</button>
|
||||||
|
<p>1, -1, 1, -1</p>
|
||||||
|
`
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.deepEqual(logs, [0, 0, 1, -1]);
|
||||||
|
}
|
||||||
|
});
|
@ -0,0 +1,20 @@
|
|||||||
|
<script>
|
||||||
|
let a = $state("0");
|
||||||
|
let b = $state("0");
|
||||||
|
let c = $state("0");
|
||||||
|
let d = $state("0");
|
||||||
|
|
||||||
|
function update() {
|
||||||
|
// @ts-expect-error
|
||||||
|
console.log(a++);
|
||||||
|
// @ts-expect-error
|
||||||
|
console.log(b--);
|
||||||
|
// @ts-expect-error
|
||||||
|
console.log(++c);
|
||||||
|
// @ts-expect-error
|
||||||
|
console.log(--d);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button onclick={update}>update</button>
|
||||||
|
<p>{a}, {b}, {c}, {d}</p>
|
Loading…
Reference in new issue