chore: simplify `<pre>` cleaning (#15980)

pull/15982/head
Rich Harris 4 months ago committed by GitHub
parent 4e72b7d28b
commit c03ea47e4e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
chore: simplify `<pre>` cleaning

@ -271,19 +271,12 @@ export function clean_nodes(
var first = trimmed[0];
// initial newline inside a `<pre>` is disregarded, if not followed by another newline
// if first text node inside a <pre> is a single newline, discard it, because otherwise
// the browser will do it for us which could break hydration
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, '');
if (text === tmp) {
first.data = text;
first.raw = first.raw.replace(regex_starts_with_newline, '');
if (first.data === '') {
trimmed.shift();
first = trimmed[0];
}
}
if (first.data === '\n' || first.data === '\r\n') {
trimmed.shift();
first = trimmed[0];
}
}

Loading…
Cancel
Save