From 527d099a0973e6d542a820fc17b9f9104c26f946 Mon Sep 17 00:00:00 2001 From: Simon H <5968653+dummdidumm@users.noreply.github.com> Date: Mon, 8 Jan 2024 20:09:59 +0100 Subject: [PATCH] fix: transform `{@render ...}` expression (#10116) fixes #10059 --- .changeset/tidy-buses-whisper.md | 5 +++++ .../phases/3-transform/server/transform-server.js | 5 +++-- .../runtime-runes/samples/snippet-store/_config.js | 5 +++++ .../runtime-runes/samples/snippet-store/main.svelte | 11 +++++++++++ 4 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 .changeset/tidy-buses-whisper.md create mode 100644 packages/svelte/tests/runtime-runes/samples/snippet-store/_config.js create mode 100644 packages/svelte/tests/runtime-runes/samples/snippet-store/main.svelte diff --git a/.changeset/tidy-buses-whisper.md b/.changeset/tidy-buses-whisper.md new file mode 100644 index 0000000000..eaf2950165 --- /dev/null +++ b/.changeset/tidy-buses-whisper.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: transform `{@render ...}` expression 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 e5fcdd415d..f00091a20b 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 @@ -1120,9 +1120,10 @@ const template_visitors = { state.init.push(anchor); state.template.push(t_expression(anchor_id)); + const expression = /** @type {import('estree').Expression} */ (context.visit(node.expression)); const snippet_function = state.options.dev - ? b.call('$.validate_snippet', node.expression) - : node.expression; + ? b.call('$.validate_snippet', expression) + : expression; if (node.argument) { state.template.push( t_statement( diff --git a/packages/svelte/tests/runtime-runes/samples/snippet-store/_config.js b/packages/svelte/tests/runtime-runes/samples/snippet-store/_config.js new file mode 100644 index 0000000000..33e7def9f1 --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/snippet-store/_config.js @@ -0,0 +1,5 @@ +import { test } from '../../test'; + +export default test({ + html: `
hello world
` +}); diff --git a/packages/svelte/tests/runtime-runes/samples/snippet-store/main.svelte b/packages/svelte/tests/runtime-runes/samples/snippet-store/main.svelte new file mode 100644 index 0000000000..bf84fc2f67 --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/snippet-store/main.svelte @@ -0,0 +1,11 @@ + + +{#snippet hello()} +hello world
+{/snippet} + +{@render $snippet()}