From 82a645f8d08140b34a19f932ca4e59719e70dbf7 Mon Sep 17 00:00:00 2001 From: Paolo Ricciuti Date: Thu, 30 May 2024 00:24:05 +0200 Subject: [PATCH] fix: `$state.is` missing second argument on the server (#11835) * fix: `$state.is` missing second argument on the server * chore: update test --- .changeset/dull-donkeys-smell.md | 5 +++++ .../phases/3-transform/server/transform-server.js | 3 ++- .../samples/state-is/_expected.html | 4 ++++ .../server-side-rendering/samples/state-is/main.svelte | 10 ++++++++++ 4 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 .changeset/dull-donkeys-smell.md create mode 100644 packages/svelte/tests/server-side-rendering/samples/state-is/_expected.html create mode 100644 packages/svelte/tests/server-side-rendering/samples/state-is/main.svelte diff --git a/.changeset/dull-donkeys-smell.md b/.changeset/dull-donkeys-smell.md new file mode 100644 index 0000000000..31b1ac319d --- /dev/null +++ b/.changeset/dull-donkeys-smell.md @@ -0,0 +1,5 @@ +--- +"svelte": patch +--- + +fix: `$state.is` missing second argument on the server diff --git a/packages/svelte/src/compiler/phases/3-transform/server/transform-server.js b/packages/svelte/src/compiler/phases/3-transform/server/transform-server.js index 83bfc17d4e..0ac79f6655 100644 --- a/packages/svelte/src/compiler/phases/3-transform/server/transform-server.js +++ b/packages/svelte/src/compiler/phases/3-transform/server/transform-server.js @@ -791,7 +791,8 @@ const javascript_visitors_runes = { if (rune === '$state.is') { return b.call( 'Object.is', - /** @type {import('estree').Expression} */ (context.visit(node.arguments[0])) + /** @type {import('estree').Expression} */ (context.visit(node.arguments[0])), + /** @type {import('estree').Expression} */ (context.visit(node.arguments[1])) ); } diff --git a/packages/svelte/tests/server-side-rendering/samples/state-is/_expected.html b/packages/svelte/tests/server-side-rendering/samples/state-is/_expected.html new file mode 100644 index 0000000000..f9f47bcf0a --- /dev/null +++ b/packages/svelte/tests/server-side-rendering/samples/state-is/_expected.html @@ -0,0 +1,4 @@ +

true

+

true

+

true

+

true

\ No newline at end of file diff --git a/packages/svelte/tests/server-side-rendering/samples/state-is/main.svelte b/packages/svelte/tests/server-side-rendering/samples/state-is/main.svelte new file mode 100644 index 0000000000..17a859cd87 --- /dev/null +++ b/packages/svelte/tests/server-side-rendering/samples/state-is/main.svelte @@ -0,0 +1,10 @@ + + +

{a === obj}

+

{$state.is(a, obj)}

+

{a === b}

+

{$state.is(a, b)}