diff --git a/.changeset/wet-donkeys-fry.md b/.changeset/wet-donkeys-fry.md new file mode 100644 index 0000000000..5ebba7a29b --- /dev/null +++ b/.changeset/wet-donkeys-fry.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: join text nodes separated by comments diff --git a/packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/fragment.js b/packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/fragment.js index 9251870c27..963bbade82 100644 --- a/packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/fragment.js +++ b/packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/fragment.js @@ -60,9 +60,9 @@ export function process_children(nodes, initial, is_element, { visit, state }) { * @param {Sequence} sequence */ function flush_sequence(sequence) { - if (sequence.length === 1 && sequence[0].type === 'Text') { + if (sequence.every((node) => node.type === 'Text')) { skipped += 1; - state.template.push(sequence[0].raw); + state.template.push(sequence.map((node) => node.raw).join('')); return; } diff --git a/packages/svelte/tests/runtime-runes/samples/comment-separated-text/_config.js b/packages/svelte/tests/runtime-runes/samples/comment-separated-text/_config.js new file mode 100644 index 0000000000..ce74a6ecde --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/comment-separated-text/_config.js @@ -0,0 +1,5 @@ +import { test } from '../../test'; + +export default test({ + html: '
foobar
' +}); diff --git a/packages/svelte/tests/runtime-runes/samples/comment-separated-text/main.svelte b/packages/svelte/tests/runtime-runes/samples/comment-separated-text/main.svelte new file mode 100644 index 0000000000..cd9acb60fb --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/comment-separated-text/main.svelte @@ -0,0 +1 @@ +
foobar