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

handle css vars in <style> tags #796

Merged
merged 1 commit into from
Aug 29, 2017
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/css/Stylesheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,15 @@ class Declaration {

minify(code: MagicString) {
const c = this.node.start + this.node.property.length;
const first = this.node.value.children[0];
const first = this.node.value.children ?
this.node.value.children[0] :
this.node.value;

if (first.start - c > 1) {
code.overwrite(c, first.start, ':');
let start = first.start;
while (/\s/.test(code.original[start])) start += 1;

if (start - c > 1) {
code.overwrite(c, start, ':');
}
}
}
Expand Down
1 change: 1 addition & 0 deletions test/css/samples/css-vars/expected.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
div[svelte-xyz],[svelte-xyz] div{--test:10}
7 changes: 7 additions & 0 deletions test/css/samples/css-vars/input.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div></div>

<style>
div {
--test: 10;
}
</style>