Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] do not collapse whitespace-only css vars #7303

Merged
merged 3 commits into from Mar 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/compiler/compile/css/Stylesheet.ts
Expand Up @@ -145,6 +145,10 @@ class Declaration {
? this.node.value.children[0]
: this.node.value;

// Don't minify whitespace in custom properties, since some browsers (Chromium < 99)
// treat --foo: ; and --foo:; differently
if (first.type === 'Raw' && /^\s+$/.test(first.value)) return;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked that the below statement is a syntax error. So this regex is ok.

div {
  --foo:;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@geoffrich Perhaps it would be useful to put a code comment here as to why we check this, since this applies specifically to chrome only.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added an explanatory comment, thanks for the suggestion!


let start = first.start;
while (/\s/.test(code.original[start])) start += 1;

Expand Down
2 changes: 1 addition & 1 deletion test/css/samples/css-vars/expected.css
@@ -1 +1 @@
:root{--root-test:20}div.svelte-xyz{--test:10}
:root{--root-test:20}div.svelte-xyz{--test:10}div.svelte-xyz{--foo: ;--bar: !important}
5 changes: 5 additions & 0 deletions test/css/samples/css-vars/input.svelte
Expand Up @@ -7,4 +7,9 @@
div {
--test: 10;
}

div {
--foo: ;
--bar: !important;
}
</style>