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

Support CSS @starting-style rule #866

Merged
merged 3 commits into from
Sep 19, 2023
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
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
Loading