Skip to content

Commit

Permalink
handle css vars in <style> tags (fixes #757)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Aug 29, 2017
1 parent 87ef5ff commit ff2e169
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
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>

0 comments on commit ff2e169

Please sign in to comment.