From 24113b405fbf1b18899860d9fd52dd5afa6dc8fc Mon Sep 17 00:00:00 2001 From: ComputerGuy <63362464+Ocean-OS@users.noreply.github.com> Date: Sat, 30 Nov 2024 23:30:53 -0800 Subject: [PATCH 01/10] Fix `$.update` and `$.update_pre` for bigints --- .../svelte/src/internal/client/runtime.js | 34 +++++++++++++++---- packages/svelte/tests/signals/test.ts | 16 +++++++++ 2 files changed, 43 insertions(+), 7 deletions(-) diff --git a/packages/svelte/src/internal/client/runtime.js b/packages/svelte/src/internal/client/runtime.js index e9f1c773e689..3910a1071d46 100644 --- a/packages/svelte/src/internal/client/runtime.js +++ b/packages/svelte/src/internal/client/runtime.js @@ -972,23 +972,43 @@ function get_parent_context(component_context) { } /** - * @param {Value} signal + * @template {number|bigint} T + * @param {Value} signal * @param {1 | -1} [d] - * @returns {number} + * @returns {T} */ export function update(signal, d = 1) { - var value = +get(signal); - set(signal, value + d); + var value = get(signal); + + if(typeof value === "bigint") { + //@ts-ignore + set(signal, value + BigInt(d)); + }else { + //@ts-ignore + set(signal, +value + d); + } + return value; } /** - * @param {Value} signal + * @template {number|bigint} T + * @param {Value} signal * @param {1 | -1} [d] - * @returns {number} + * @returns {T} */ export function update_pre(signal, d = 1) { - return set(signal, +get(signal) + d); + var value = get(signal); + + if(typeof value === "bigint") { + //@ts-ignore + d = BigInt(d); + }else { + //@ts-ignore + value = +value; + } + //@ts-ignore + return set(signal, value + d); } /** diff --git a/packages/svelte/tests/signals/test.ts b/packages/svelte/tests/signals/test.ts index e2d27267a3f5..f4a731b0f8a6 100644 --- a/packages/svelte/tests/signals/test.ts +++ b/packages/svelte/tests/signals/test.ts @@ -739,4 +739,20 @@ describe('signals', () => { assert.deepEqual(a.reactions, null); }; }); + + test('bigint states update correctly', () => { + return () => { + const count = state(0n); + + assert.doesNotThrow(() => $.update(count)); + assert.equal($.get(count), 1n); + assert.doesNotThrow(() => $.update(count, -1)); + assert.equal($.get(count), 0n); + + assert.doesNotThrow(() => $.update_pre(count)); + assert.equal($.get(count), 1n); + assert.doesNotThrow(() => $.update_pre(count, -1)); + assert.equal($.get(count), 0n); + } + }) }); From afe4dbedc2074fede9f602d937748219e4788620 Mon Sep 17 00:00:00 2001 From: ComputerGuy <63362464+Ocean-OS@users.noreply.github.com> Date: Sat, 30 Nov 2024 23:41:00 -0800 Subject: [PATCH 02/10] resolve conflicts --- packages/svelte/tests/signals/test.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/packages/svelte/tests/signals/test.ts b/packages/svelte/tests/signals/test.ts index f4a731b0f8a6..a428feaf08c8 100644 --- a/packages/svelte/tests/signals/test.ts +++ b/packages/svelte/tests/signals/test.ts @@ -740,6 +740,32 @@ describe('signals', () => { }; }); + test('nested deriveds clean up the relationships when used with untrack', () => { + return () => { + let a = render_effect(() => {}); + + const destroy = effect_root(() => { + a = render_effect(() => { + $.untrack(() => { + const b = derived(() => { + const c = derived(() => {}); + $.untrack(() => { + $.get(c); + }); + }); + $.get(b); + }); + }); + }); + + assert.deepEqual(a.deriveds?.length, 1); + + destroy(); + + assert.deepEqual(a.deriveds, null); + }; + }); + test('bigint states update correctly', () => { return () => { const count = state(0n); From 1654449880b8659f611d4cd7a2c1df9b22fa506e Mon Sep 17 00:00:00 2001 From: ComputerGuy <63362464+Ocean-OS@users.noreply.github.com> Date: Sat, 30 Nov 2024 23:52:58 -0800 Subject: [PATCH 03/10] fix some things --- packages/svelte/src/internal/client/runtime.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/packages/svelte/src/internal/client/runtime.js b/packages/svelte/src/internal/client/runtime.js index 59dbe7b91ffb..8881c7628d79 100644 --- a/packages/svelte/src/internal/client/runtime.js +++ b/packages/svelte/src/internal/client/runtime.js @@ -990,16 +990,17 @@ function get_parent_context(component_context) { * @returns {T} */ export function update(signal, d = 1) { - var value = get(signal); + //@ts-ignore + var value = +get(signal); if(typeof value === "bigint") { //@ts-ignore set(signal, value + BigInt(d)); }else { //@ts-ignore - set(signal, +value + d); + set(signal, value + d); } - + //@ts-ignore return value; } @@ -1010,14 +1011,12 @@ export function update(signal, d = 1) { * @returns {T} */ export function update_pre(signal, d = 1) { - var value = get(signal); + //@ts-ignore + var value = +get(signal); if(typeof value === "bigint") { //@ts-ignore d = BigInt(d); - }else { - //@ts-ignore - value = +value; } //@ts-ignore return set(signal, value + d); From b1f409c404d0ac65c438dfb2972d60876f2afc28 Mon Sep 17 00:00:00 2001 From: ComputerGuy <63362464+Ocean-OS@users.noreply.github.com> Date: Sat, 30 Nov 2024 23:56:52 -0800 Subject: [PATCH 04/10] fix thing i definitely didn't just break --- packages/svelte/src/internal/client/runtime.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/svelte/src/internal/client/runtime.js b/packages/svelte/src/internal/client/runtime.js index 8881c7628d79..14944ae9fbc6 100644 --- a/packages/svelte/src/internal/client/runtime.js +++ b/packages/svelte/src/internal/client/runtime.js @@ -990,15 +990,14 @@ function get_parent_context(component_context) { * @returns {T} */ export function update(signal, d = 1) { - //@ts-ignore - var value = +get(signal); + var value = get(signal); if(typeof value === "bigint") { //@ts-ignore set(signal, value + BigInt(d)); }else { //@ts-ignore - set(signal, value + d); + set(signal, +value + d); } //@ts-ignore return value; @@ -1011,12 +1010,14 @@ export function update(signal, d = 1) { * @returns {T} */ export function update_pre(signal, d = 1) { - //@ts-ignore - var value = +get(signal); + var value = get(signal); if(typeof value === "bigint") { //@ts-ignore d = BigInt(d); + }else{ + //@ts-ignore + value = +value; } //@ts-ignore return set(signal, value + d); From 93a6753549a36f7c0f557487569c9ec91a8ee82a Mon Sep 17 00:00:00 2001 From: ComputerGuy <63362464+Ocean-OS@users.noreply.github.com> Date: Sun, 1 Dec 2024 00:01:04 -0800 Subject: [PATCH 05/10] hopefully this will fix it --- packages/svelte/src/internal/client/runtime.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/packages/svelte/src/internal/client/runtime.js b/packages/svelte/src/internal/client/runtime.js index 14944ae9fbc6..026c1c63d27d 100644 --- a/packages/svelte/src/internal/client/runtime.js +++ b/packages/svelte/src/internal/client/runtime.js @@ -995,12 +995,13 @@ export function update(signal, d = 1) { if(typeof value === "bigint") { //@ts-ignore set(signal, value + BigInt(d)); + return value; }else { //@ts-ignore set(signal, +value + d); + //@ts-ignore + return +value; } - //@ts-ignore - return value; } /** @@ -1014,13 +1015,11 @@ export function update_pre(signal, d = 1) { if(typeof value === "bigint") { //@ts-ignore - d = BigInt(d); + return set(signal, value + BigInt(d)); }else{ //@ts-ignore - value = +value; + return set(signal, +value + d); } - //@ts-ignore - return set(signal, value + d); } /** From 9343188065f98aad1f1e146f6aa204dcd203758c Mon Sep 17 00:00:00 2001 From: ComputerGuy <63362464+Ocean-OS@users.noreply.github.com> Date: Sun, 1 Dec 2024 00:10:01 -0800 Subject: [PATCH 06/10] fix formatting --- packages/svelte/src/internal/client/runtime.js | 10 +++++----- packages/svelte/tests/signals/test.ts | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/svelte/src/internal/client/runtime.js b/packages/svelte/src/internal/client/runtime.js index 026c1c63d27d..cd4b7fc179f4 100644 --- a/packages/svelte/src/internal/client/runtime.js +++ b/packages/svelte/src/internal/client/runtime.js @@ -992,11 +992,11 @@ function get_parent_context(component_context) { export function update(signal, d = 1) { var value = get(signal); - if(typeof value === "bigint") { + if (typeof value === 'bigint') { //@ts-ignore set(signal, value + BigInt(d)); return value; - }else { + } else { //@ts-ignore set(signal, +value + d); //@ts-ignore @@ -1012,11 +1012,11 @@ export function update(signal, d = 1) { */ export function update_pre(signal, d = 1) { var value = get(signal); - - if(typeof value === "bigint") { + + if (typeof value === 'bigint') { //@ts-ignore return set(signal, value + BigInt(d)); - }else{ + } else { //@ts-ignore return set(signal, +value + d); } diff --git a/packages/svelte/tests/signals/test.ts b/packages/svelte/tests/signals/test.ts index a428feaf08c8..6796655cc8d2 100644 --- a/packages/svelte/tests/signals/test.ts +++ b/packages/svelte/tests/signals/test.ts @@ -779,6 +779,6 @@ describe('signals', () => { assert.equal($.get(count), 1n); assert.doesNotThrow(() => $.update_pre(count, -1)); assert.equal($.get(count), 0n); - } - }) + }; + }); }); From 244fb10aec038d3b57901894e8cf27997a3eb805 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sun, 1 Dec 2024 10:02:00 -0500 Subject: [PATCH 07/10] simplify --- packages/svelte/src/internal/client/runtime.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/packages/svelte/src/internal/client/runtime.js b/packages/svelte/src/internal/client/runtime.js index cd4b7fc179f4..093a2607e8a1 100644 --- a/packages/svelte/src/internal/client/runtime.js +++ b/packages/svelte/src/internal/client/runtime.js @@ -1013,13 +1013,8 @@ export function update(signal, d = 1) { export function update_pre(signal, d = 1) { var value = get(signal); - if (typeof value === 'bigint') { - //@ts-ignore - return set(signal, value + BigInt(d)); - } else { - //@ts-ignore - return set(signal, +value + d); - } + // @ts-expect-error + return set(signal, d === 1 ? ++value : --value); } /** From a4977fb6f0b1fa488dd570e0ed3057e11e3e75e6 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sun, 1 Dec 2024 10:03:17 -0500 Subject: [PATCH 08/10] style consistency --- packages/svelte/src/internal/client/runtime.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/svelte/src/internal/client/runtime.js b/packages/svelte/src/internal/client/runtime.js index 093a2607e8a1..d8e17d38264b 100644 --- a/packages/svelte/src/internal/client/runtime.js +++ b/packages/svelte/src/internal/client/runtime.js @@ -984,7 +984,7 @@ function get_parent_context(component_context) { } /** - * @template {number|bigint} T + * @template {number | bigint} T * @param {Value} signal * @param {1 | -1} [d] * @returns {T} @@ -993,19 +993,19 @@ export function update(signal, d = 1) { var value = get(signal); if (typeof value === 'bigint') { - //@ts-ignore + // @ts-expect-error set(signal, value + BigInt(d)); return value; - } else { - //@ts-ignore - set(signal, +value + d); - //@ts-ignore - return +value; } + + // @ts-expect-error + set(signal, +value + d); + // @ts-expect-error + return +value; } /** - * @template {number|bigint} T + * @template {number | bigint} T * @param {Value} signal * @param {1 | -1} [d] * @returns {T} From 99c354d872258838289addbfc90fc326fb0feded Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sun, 1 Dec 2024 10:06:20 -0500 Subject: [PATCH 09/10] simplify --- packages/svelte/src/internal/client/runtime.js | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/packages/svelte/src/internal/client/runtime.js b/packages/svelte/src/internal/client/runtime.js index d8e17d38264b..c2188b187cfe 100644 --- a/packages/svelte/src/internal/client/runtime.js +++ b/packages/svelte/src/internal/client/runtime.js @@ -991,17 +991,12 @@ function get_parent_context(component_context) { */ export function update(signal, d = 1) { var value = get(signal); + var result = d === 1 ? value++ : value--; - if (typeof value === 'bigint') { - // @ts-expect-error - set(signal, value + BigInt(d)); - return value; - } + set(signal, value); // @ts-expect-error - set(signal, +value + d); - // @ts-expect-error - return +value; + return result; } /** From 5e47532541cf3b84bbff200a92fb8846633459a2 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sun, 1 Dec 2024 10:11:27 -0500 Subject: [PATCH 10/10] changeset --- .changeset/young-beds-beam.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/young-beds-beam.md diff --git a/.changeset/young-beds-beam.md b/.changeset/young-beds-beam.md new file mode 100644 index 000000000000..4349d82dd9f2 --- /dev/null +++ b/.changeset/young-beds-beam.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: correctly increment/decrement bigints