Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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>
- Loading branch information
1 parent
8318b3d
commit 0cf6d56
Showing
4 changed files
with
51 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"svelte": patch | ||
--- | ||
|
||
fix: coerce incremented/decremented sources |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
packages/svelte/tests/runtime-runes/samples/increment-and-decrement-strings/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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]); | ||
} | ||
}); |
20 changes: 20 additions & 0 deletions
20
packages/svelte/tests/runtime-runes/samples/increment-and-decrement-strings/main.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |