Skip to content

Commit

Permalink
fix: improve text node output (#10081)
Browse files Browse the repository at this point in the history
* fix: improve text node output

* revert
  • Loading branch information
trueadm committed Jan 4, 2024
1 parent e9b0908 commit 94aab90
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/dry-eggs-play.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: improve text node output
Original file line number Diff line number Diff line change
Expand Up @@ -1531,14 +1531,20 @@ function process_children(nodes, parent, { visit, state }) {
expression = b.call('$.sibling', text_id);
}

let is_fragment = false;
for (let i = 0; i < nodes.length; i += 1) {
const node = nodes[i];

if (node.type === 'Text' || node.type === 'ExpressionTag') {
sequence.push(node);
} else {
if (sequence.length > 0) {
flush_sequence(sequence, true);
flush_sequence(sequence, is_fragment);
// Ensure we move to the next sibling for the case where we move reference within a fragment
if (!is_fragment && sequence.length === 1 && sequence[0].type === 'ExpressionTag') {
expression = b.call('$.sibling', expression);
is_fragment = true;
}
sequence = [];
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { test } from '../../test';

export default test({
html: `<p>A<br>B<br>C<br></p>`
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<script>
let array = $state(['A', 'B', 'C']);
</script>

<p>
{#each array as a}
{a}<br/>
{/each}
</p>

1 comment on commit 94aab90

@vercel
Copy link

@vercel vercel bot commented on 94aab90 Jan 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

svelte-5-preview – ./sites/svelte-5-preview

svelte-5-preview.vercel.app
svelte-octane.vercel.app
svelte-5-preview-svelte.vercel.app
svelte-5-preview-git-main-svelte.vercel.app

Please sign in to comment.