diff --git a/.changeset/chilled-seas-jog.md b/.changeset/chilled-seas-jog.md new file mode 100644 index 0000000000..7862a5e2cd --- /dev/null +++ b/.changeset/chilled-seas-jog.md @@ -0,0 +1,5 @@ +--- +"svelte": patch +--- + +fix: coerce incremented/decremented sources diff --git a/packages/svelte/src/internal/client/runtime.js b/packages/svelte/src/internal/client/runtime.js index a9dee752e1..0311102f1e 100644 --- a/packages/svelte/src/internal/client/runtime.js +++ b/packages/svelte/src/internal/client/runtime.js @@ -1011,7 +1011,7 @@ function get_parent_context(component_context) { * @returns {number} */ export function update(signal, d = 1) { - const value = get(signal); + var value = +get(signal); set(signal, value + d); return value; } @@ -1022,9 +1022,7 @@ export function update(signal, d = 1) { * @returns {number} */ export function update_pre(signal, d = 1) { - const value = get(signal) + d; - set(signal, value); - return value; + return set(signal, +get(signal) + d); } /** diff --git a/packages/svelte/tests/runtime-runes/samples/increment-and-decrement-strings/_config.js b/packages/svelte/tests/runtime-runes/samples/increment-and-decrement-strings/_config.js new file mode 100644 index 0000000000..9e8999e0a1 --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/increment-and-decrement-strings/_config.js @@ -0,0 +1,24 @@ +import { flushSync } from 'svelte'; +import { test } from '../../test'; + +export default test({ + html: ` + +
0, 0, 0, 0
+ `, + + test({ target, assert, logs }) { + const btn = target.querySelector('button'); + flushSync(() => btn?.click()); + + assert.htmlEqual( + target.innerHTML, + ` + +1, -1, 1, -1
+ ` + ); + + assert.deepEqual(logs, [0, 0, 1, -1]); + } +}); diff --git a/packages/svelte/tests/runtime-runes/samples/increment-and-decrement-strings/main.svelte b/packages/svelte/tests/runtime-runes/samples/increment-and-decrement-strings/main.svelte new file mode 100644 index 0000000000..9d8c678858 --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/increment-and-decrement-strings/main.svelte @@ -0,0 +1,20 @@ + + + +{a}, {b}, {c}, {d}