mirror of https://github.com/sveltejs/svelte
fix: follow-up formatting in `print()` for block-level elements (#17699)
Follow-up to #17319. The `Fragment` visitor in `print()` only flushed sequences on `RegularElement`, causing block-level elements (`Component`, `SvelteHead`, `SvelteBoundary`, etc.) to be lumped into the same sequence as adjacent nodes. This broke tools that programmatically manipulate the AST (e.g. [sveltejs/cli#915](https://github.com/sveltejs/cli/pull/915)). The fix flushes before and after all block-level element types, ensuring they get their own sequence and proper line separation. ### Before ```svelte <svelte:head><title>Page Title</title></svelte:head><div>no space</div> <Component /><Component /> <Component><span>child</span></Component><div>after component</div> <svelte:boundary><div>boundary content</div></svelte:boundary><div>after boundary</div> <!--comment--><div>after comment</div> <div>before comment</div> <!--comment--> {#each items as item} <div>{item}</div> {/each}<div>after each</div> {@render children()}<div>after render</div> <div>before render</div> {@render children()} ``` ### After ```svelte <svelte:head><title>Page Title</title></svelte:head> <div>no space</div> <Component /> <Component /> <Component><span>child</span></Component> <div>after component</div> <svelte:boundary><div>boundary content</div></svelte:boundary> <div>after boundary</div> <!--comment--> <div>after comment</div> <div>before comment</div> <!--comment--> {#each items as item} <div>{item}</div> {/each} <div>after each</div> {@render children()} <div>after render</div> <div>before render</div> {@render children()} ```pull/17693/head
parent
0565dca1f7
commit
86d5522096
@ -0,0 +1,5 @@
|
||||
---
|
||||
"svelte": patch
|
||||
---
|
||||
|
||||
fix: follow-up formatting in `print()` — flush block-level elements into separate sequences
|
||||
@ -0,0 +1,25 @@
|
||||
<svelte:head><title>Page Title</title></svelte:head><div>no space</div>
|
||||
<Component /><Component />
|
||||
<Component><span>child</span></Component><div>after component</div>
|
||||
<svelte:boundary><div>boundary content</div></svelte:boundary><div>after boundary</div>
|
||||
<!--comment--><div>after comment</div>
|
||||
<div>before comment</div><!--comment-->
|
||||
{#each items as item}<div>{item}</div>{/each}<div>after each</div>
|
||||
{@render children()}<div>after render</div>
|
||||
<div>before render</div>{@render children()}
|
||||
|
||||
<Component /> <div>with spaces</div>
|
||||
<Component><span>child</span></Component> <div>spaces after component</div>
|
||||
<!--comment--> <div>spaces after comment</div>
|
||||
{@render children()} <div>spaces after render</div>
|
||||
|
||||
<Component />
|
||||
<div>newline between</div>
|
||||
<!--comment-->
|
||||
<div>newline after comment</div>
|
||||
{#each items as item}
|
||||
<div>{item}</div>
|
||||
{/each}
|
||||
<div>newline after each</div>
|
||||
{@render children()}
|
||||
<div>after render</div>
|
||||
@ -0,0 +1,42 @@
|
||||
<svelte:head><title>Page Title</title></svelte:head>
|
||||
<div>no space</div>
|
||||
<Component />
|
||||
<Component />
|
||||
<Component><span>child</span></Component>
|
||||
<div>after component</div>
|
||||
<svelte:boundary><div>boundary content</div></svelte:boundary>
|
||||
<div>after boundary</div>
|
||||
<!--comment-->
|
||||
<div>after comment</div>
|
||||
<div>before comment</div>
|
||||
<!--comment-->
|
||||
|
||||
{#each items as item}
|
||||
<div>{item}</div>
|
||||
{/each}
|
||||
|
||||
<div>after each</div>
|
||||
{@render children()}
|
||||
<div>after render</div>
|
||||
<div>before render</div>
|
||||
{@render children()}
|
||||
<Component />
|
||||
<div>with spaces</div>
|
||||
<Component><span>child</span></Component>
|
||||
<div>spaces after component</div>
|
||||
<!--comment-->
|
||||
<div>spaces after comment</div>
|
||||
{@render children()}
|
||||
<div>spaces after render</div>
|
||||
<Component />
|
||||
<div>newline between</div>
|
||||
<!--comment-->
|
||||
<div>newline after comment</div>
|
||||
|
||||
{#each items as item}
|
||||
<div>{item}</div>
|
||||
{/each}
|
||||
|
||||
<div>newline after each</div>
|
||||
{@render children()}
|
||||
<div>after render</div>
|
||||
Loading…
Reference in new issue