Skip to content

Commit

Permalink
Support CSS @starting-style rule (#866)
Browse files Browse the repository at this point in the history
* Support CSS `@starting-style` rule

From: evanw/esbuild#3249

* More tests for `@starting-style`

* Add changeset
  • Loading branch information
nix6839 committed Sep 19, 2023
1 parent 2169e80 commit 7579d7c
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/giant-chicken-arrive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/compiler': minor
---

Support CSS `@starting-style` rule (From: https://github.com/evanw/esbuild/pull/3249)
5 changes: 5 additions & 0 deletions internal/transform/scope-css_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,11 @@ func TestScopeStyle(t *testing.T) {
source: "@layer theme, layout, utilities; @layer special { .item { color: rebeccapurple; }}",
want: "@layer theme,layout,utilities;@layer special{.item:where(.astro-xxxxxx){color:rebeccapurple}}",
},
{
name: "@starting-style",
source: "@starting-style{.class{}}",
want: "@starting-style{.class:where(.astro-xxxxxx){}}",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
3 changes: 3 additions & 0 deletions lib/esbuild/css_parser/css_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,9 @@ var specialAtRules = map[string]atRuleKind{
// Reference: https://github.com/w3c/csswg-drafts/issues?q=is%3Aissue+label%3Acss-contain-3+
"container": atRuleInheritContext,

// Reference: https://drafts.csswg.org/css-transitions-2/#defining-before-change-style-the-starting-style-rule
"starting-style": atRuleInheritContext,

// Reference: https://drafts.csswg.org/css-nesting-1/
"nest": atRuleDeclarations,
}
Expand Down
30 changes: 30 additions & 0 deletions lib/esbuild/css_parser/css_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,36 @@ func TestAtCharset(t *testing.T) {
expectParseError(t, "@charset url(\"UTF-8\");", "<stdin>: WARNING: Expected string token but found \"url(\"\n")
expectParseError(t, "@charset \"UTF-8\" ", "<stdin>: WARNING: Expected \";\" but found whitespace\n")
expectParseError(t, "@charset \"UTF-8\"{}", "<stdin>: WARNING: Expected \";\" but found \"{\"\n")

// https://drafts.csswg.org/css-transitions-2/#defining-before-change-style-the-starting-style-rule
expectPrinted(t, `
@starting-style {
h1 {
background-color: transparent;
}
@layer foo {
div {
height: 100px;
}
}
}
`, `@starting-style {
h1 {
background-color: transparent;
}
@layer foo {
div {
height: 100px;
}
}
}
`)

expectPrintedMinify(t, `@starting-style {
h1 {
background-color: transparent;
}
}`, "@starting-style{h1{background-color:transparent}}")
}

func TestAtImport(t *testing.T) {
Expand Down
7 changes: 7 additions & 0 deletions lib/esbuild/css_printer/css_printer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,13 @@ func TestAtPage(t *testing.T) {
expectPrintedMinify(t, "@page :first { margin: 1cm }", "@page :first{margin:1cm}")
}

func TestAtStartingStyle(t *testing.T) {
expectPrinted(t, "@starting-style { div { color: red } }", "@starting-style {\n div {\n color: red;\n }\n}\n")
expectPrinted(t, "@starting-style{div{color:red}}", "@starting-style {\n div {\n color: red;\n }\n}\n")
expectPrintedMinify(t, "@starting-style { div { color: red } }", "@starting-style{div{color:red}}")
expectPrintedMinify(t, "@starting-style{div{color:red}}", "@starting-style{div{color:red}}")
}

func TestMsGridColumnsWhitespace(t *testing.T) {
// Must not insert a space between the "]" and the "("
expectPrinted(t, "div { -ms-grid-columns: (1fr)[3] }", "div {\n -ms-grid-columns: (1fr)[3];\n}\n")
Expand Down

0 comments on commit 7579d7c

Please sign in to comment.