Skip to content

Commit

Permalink
fixing parsing for CSS variables in style parsing (#125)
Browse files Browse the repository at this point in the history
* fixing parsing for CSS variables in style parsing

* adding a changeset

Co-authored-by: Tony Sullivan <[email protected]>
  • Loading branch information
Tony Sullivan and Tony Sullivan authored Oct 31, 2021
1 parent 5e0b559 commit f052465
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/chilled-socks-buy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/compiler': patch
---

Fix CSS variable parsing in the scoped CSS transform
7 changes: 6 additions & 1 deletion internal/transform/scope-css.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,14 @@ outer:
out += ","
}
default:
out += string(data)
strData := string(data)
out += strData
for _, val := range p.Values() {
strVal := string(val.Data)
// handle CSS variables
if strings.HasPrefix(strData, "--") {
out += ":"
}
out += strVal
}
out += ";"
Expand Down
5 changes: 5 additions & 0 deletions internal/transform/scope-css_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,11 @@ func TestScopeStyle(t *testing.T) {
source: "body{background-image:url('/assets/bg.jpg');clip-path:polygon(0% 0%,100% 0%,100% 100%,0% 100%);}",
want: "body{background-image:url('/assets/bg.jpg');clip-path:polygon(0% 0%,100% 0%,100% 100%,0% 100%);}",
},
{
name: "variables",
source: "body{--bg:red;background:var(--bg);color:black;}",
want: "body{--bg:red;background:var(--bg);color:black;}",
},
{
name: "keyframes",
source: "@keyframes shuffle{from{transform:rotate(0deg);}to{transform:rotate(360deg);}}",
Expand Down

0 comments on commit f052465

Please sign in to comment.