From 2bdc3d401f8bce90ff92d8cd1d34c25f61293d7d Mon Sep 17 00:00:00 2001 From: Dominic Gannaway Date: Thu, 31 Oct 2024 17:16:06 +0000 Subject: [PATCH] fix: ensure compiler statements are correctly included (#14074) Fixes #14068 and fixes #14071 --- .changeset/nice-peas-lay.md | 5 +++++ .../3-transform/client/visitors/RegularElement.js | 1 + .../runtime-runes/samples/snippet-ref/_config.js | 8 ++++++++ .../runtime-runes/samples/snippet-ref/main.svelte | 11 +++++++++++ 4 files changed, 25 insertions(+) create mode 100644 .changeset/nice-peas-lay.md create mode 100644 packages/svelte/tests/runtime-runes/samples/snippet-ref/_config.js create mode 100644 packages/svelte/tests/runtime-runes/samples/snippet-ref/main.svelte diff --git a/.changeset/nice-peas-lay.md b/.changeset/nice-peas-lay.md new file mode 100644 index 000000000000..f37f92231ba9 --- /dev/null +++ b/.changeset/nice-peas-lay.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: ensure compiler statements are correctly included diff --git a/packages/svelte/src/compiler/phases/3-transform/client/visitors/RegularElement.js b/packages/svelte/src/compiler/phases/3-transform/client/visitors/RegularElement.js index bd881e0f7607..6ef29b621fe6 100644 --- a/packages/svelte/src/compiler/phases/3-transform/client/visitors/RegularElement.js +++ b/packages/svelte/src/compiler/phases/3-transform/client/visitors/RegularElement.js @@ -401,6 +401,7 @@ export function RegularElement(node, context) { context.state.init.push( b.block([ ...child_state.init, + ...element_state.init, child_state.update.length > 0 ? build_render_statement(child_state.update) : b.empty, ...child_state.after_update, ...element_state.after_update diff --git a/packages/svelte/tests/runtime-runes/samples/snippet-ref/_config.js b/packages/svelte/tests/runtime-runes/samples/snippet-ref/_config.js new file mode 100644 index 000000000000..9dc0bd3bd525 --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/snippet-ref/_config.js @@ -0,0 +1,8 @@ +import { test } from '../../test'; + +export default test({ + compileOptions: { + dev: true // Render in dev mode to check that the validation error is not thrown + }, + html: `
\nundefined` +}); diff --git a/packages/svelte/tests/runtime-runes/samples/snippet-ref/main.svelte b/packages/svelte/tests/runtime-runes/samples/snippet-ref/main.svelte new file mode 100644 index 000000000000..7e4e6fd0aa6a --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/snippet-ref/main.svelte @@ -0,0 +1,11 @@ + + +
+ {#snippet Bug()} + cool + {/snippet} +
+ +{typeof thisBug}