From cb1ea1f2dbfedde5db4468e6f79abcde2dc83438 Mon Sep 17 00:00:00 2001 From: Simon H <5968653+dummdidumm@users.noreply.github.com> Date: Thu, 30 Nov 2023 11:15:38 +0100 Subject: [PATCH] fix: ensure `$$slots` exists in runes mode (#9718) fixes #9683 --- .changeset/flat-melons-protect.md | 5 +++++ packages/svelte/src/compiler/phases/2-analyze/index.js | 5 +++++ .../svelte/tests/runtime-runes/samples/slot/_config.js | 6 ++++++ .../svelte/tests/runtime-runes/samples/slot/main.svelte | 7 +++++++ .../svelte/tests/runtime-runes/samples/slot/slot.svelte | 3 +++ 5 files changed, 26 insertions(+) create mode 100644 .changeset/flat-melons-protect.md create mode 100644 packages/svelte/tests/runtime-runes/samples/slot/_config.js create mode 100644 packages/svelte/tests/runtime-runes/samples/slot/main.svelte create mode 100644 packages/svelte/tests/runtime-runes/samples/slot/slot.svelte diff --git a/.changeset/flat-melons-protect.md b/.changeset/flat-melons-protect.md new file mode 100644 index 0000000000..43a8c45754 --- /dev/null +++ b/.changeset/flat-melons-protect.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: ensure `$$slots` exists in runes mode diff --git a/packages/svelte/src/compiler/phases/2-analyze/index.js b/packages/svelte/src/compiler/phases/2-analyze/index.js index ef5d807bb9..71295b7059 100644 --- a/packages/svelte/src/compiler/phases/2-analyze/index.js +++ b/packages/svelte/src/compiler/phases/2-analyze/index.js @@ -892,6 +892,11 @@ const common_visitors = { const parent = /** @type {import('estree').Node} */ (context.path.at(-1)); if (!is_reference(node, parent)) return; + if (node.name === '$$slots') { + context.state.analysis.uses_slots = true; + return; + } + const binding = context.state.scope.get(node.name); // if no binding, means some global variable diff --git a/packages/svelte/tests/runtime-runes/samples/slot/_config.js b/packages/svelte/tests/runtime-runes/samples/slot/_config.js new file mode 100644 index 0000000000..c69314e244 --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/slot/_config.js @@ -0,0 +1,6 @@ +import { test } from '../../test'; + +// Test that $$slots exists in runes mode +export default test({ + html: `

bar

` +}); diff --git a/packages/svelte/tests/runtime-runes/samples/slot/main.svelte b/packages/svelte/tests/runtime-runes/samples/slot/main.svelte new file mode 100644 index 0000000000..e6490ab098 --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/slot/main.svelte @@ -0,0 +1,7 @@ + + + +

bar

+
diff --git a/packages/svelte/tests/runtime-runes/samples/slot/slot.svelte b/packages/svelte/tests/runtime-runes/samples/slot/slot.svelte new file mode 100644 index 0000000000..f58504ca4b --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/slot/slot.svelte @@ -0,0 +1,3 @@ +{#if $$slots} + +{/if}