From d8e9d1117a2abeaf827387b80d36396283aaa92f Mon Sep 17 00:00:00 2001 From: Geoff Rich <4992896+geoffrich@users.noreply.github.com> Date: Tue, 22 Feb 2022 08:57:17 -0800 Subject: [PATCH] fix: do not collapse whitespace-only css vars --- src/compiler/compile/css/Stylesheet.ts | 2 ++ test/css/samples/css-vars/expected.css | 2 +- test/css/samples/css-vars/input.svelte | 4 ++++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/compiler/compile/css/Stylesheet.ts b/src/compiler/compile/css/Stylesheet.ts index 8f88f0cbd4..7f0c0b52ca 100644 --- a/src/compiler/compile/css/Stylesheet.ts +++ b/src/compiler/compile/css/Stylesheet.ts @@ -145,6 +145,8 @@ class Declaration { ? this.node.value.children[0] : this.node.value; + if (first.type === 'Raw' && /^\s+$/.test(first.value)) return; + let start = first.start; while (/\s/.test(code.original[start])) start += 1; diff --git a/test/css/samples/css-vars/expected.css b/test/css/samples/css-vars/expected.css index c2bd56375b..3c252b8d05 100644 --- a/test/css/samples/css-vars/expected.css +++ b/test/css/samples/css-vars/expected.css @@ -1 +1 @@ -:root{--root-test:20}div.svelte-xyz{--test:10} \ No newline at end of file +:root{--root-test:20}div.svelte-xyz{--test:10}div.svelte-xyz{--foo: } \ No newline at end of file diff --git a/test/css/samples/css-vars/input.svelte b/test/css/samples/css-vars/input.svelte index 7aa48617a4..3679e0d453 100644 --- a/test/css/samples/css-vars/input.svelte +++ b/test/css/samples/css-vars/input.svelte @@ -7,4 +7,8 @@ div { --test: 10; } + + div { + --foo: ; + }