Skip to content

Commit

Permalink
fix: correctly transform pre with no content
Browse files Browse the repository at this point in the history
  • Loading branch information
paoloricciuti committed Jan 10, 2025
1 parent 41fb513 commit 7777880
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/spicy-insects-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: correctly transform `pre` with no content
2 changes: 1 addition & 1 deletion packages/svelte/src/compiler/phases/3-transform/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ export function clean_nodes(
var first = trimmed[0];

// initial newline inside a `<pre>` is disregarded, if not followed by another newline
if (parent.type === 'RegularElement' && parent.name === 'pre' && first.type === 'Text') {
if (parent.type === 'RegularElement' && parent.name === 'pre' && first?.type === 'Text') {
const text = first.data.replace(regex_starts_with_newline, '');
if (text !== first.data) {
const tmp = text.replace(regex_starts_with_newline, '');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { test } from '../../test';

export default test({
html: `<pre></pre>`
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<pre></pre>

0 comments on commit 7777880

Please sign in to comment.