Skip to content

Commit 3a4a091

Browse files
authored
fix: improve whitespace handling (#9912)
revert
1 parent f2d1112 commit 3a4a091

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

.changeset/dull-mangos-wave.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: improve whitespace handling

packages/svelte/src/compiler/phases/3-transform/utils.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,9 @@ export function clean_nodes(
177177
node.data = node.data.replace(regex_whitespaces_strict, ' ');
178178
node.raw = node.raw.replace(regex_whitespaces_strict, ' ');
179179
if (
180-
(last_text === null || !regex_ends_with_whitespaces.test(last_text.data)) &&
181-
(!can_remove_entirely || node.data !== ' ')
180+
(last_text === null && !can_remove_entirely) ||
181+
node.data !== ' ' ||
182+
node.data.charCodeAt(0) === 160 // non-breaking space
182183
) {
183184
trimmed.push(node);
184185
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { test } from '../../test';
2+
3+
export default test({
4+
compileOptions: {
5+
dev: true // Render in dev mode to check that the validation error is not thrown
6+
},
7+
html: `A\nB\nC\nD`
8+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
A
2+
{#snippet snip()}C{/snippet}
3+
B
4+
{@render snip()}
5+
D

0 commit comments

Comments
 (0)