fix: improve text node output

pull/10081/head
Dominic Gannaway 3 years ago
parent 570884eabd
commit d016532732

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: improve text node output

@ -1531,6 +1531,7 @@ 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];
@ -1538,7 +1539,12 @@ function process_children(nodes, parent, { visit, state }) {
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 = [];
}

@ -0,0 +1,5 @@
import { test } from '../../test';
export default test({
html: `<p>A<br>B<br>C<br></p>`
});

@ -0,0 +1,9 @@
<script>
let array = $state(['A', 'B', 'C']);
</script>
<p>
{#each array as a}
{a}<br/>
{/each}
</p>

@ -1,11 +0,0 @@
import { test } from '../../test';
export default test({
html: '<button>clicks: 0</button>',
async test({ assert, target }) {
const btn = target.querySelector('button');
await btn?.click();
assert.htmlEqual(target.innerHTML, `<button>clicks: 1</button>`);
}
});

@ -1,23 +0,0 @@
<script context="module" lang="ts">
interface Hello { message: 'hello' }
type Goodbye = { message: 'goodbye' };
export type { Hello };
</script>
<script>
import type { Foo } from './types';
import { type Bar, type Baz } from './types';
let count = $state(0);
const person = {
message: 'goodbye'
} satisfies Goodbye;
</script>
<button
on:click={(e: MouseEvent) => {
const next: number = count + 1;
count = next! as number;
}}
>clicks: {count}</button>

@ -1,3 +0,0 @@
export interface Foo {}
export interface Bar {}
export interface Baz {}
Loading…
Cancel
Save