diff --git a/CHANGELOG.md b/CHANGELOG.md index 26ad1fb0d76..63c52394467 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -77,6 +77,10 @@ } ``` +* Formatting support for the `@position-try` rule ([#3773](https://github.com/evanw/esbuild/issues/3773)) + + Chrome shipped this new CSS at-rule in version 125 as part of the [CSS anchor positioning API](https://developer.chrome.com/blog/anchor-positioning-api). With this release, esbuild now knows to expect a declaration list inside of the `@position-try` body block and will format it appropriately. + ## 0.21.3 * Implement the decorator metadata proposal ([#3760](https://github.com/evanw/esbuild/issues/3760)) diff --git a/internal/css_parser/css_parser.go b/internal/css_parser/css_parser.go index 6fbcbeea011..131ec5edfcd 100644 --- a/internal/css_parser/css_parser.go +++ b/internal/css_parser/css_parser.go @@ -1102,6 +1102,10 @@ var specialAtRules = map[string]atRuleKind{ // Defining before-change style: the @starting-style rule // Reference: https://drafts.csswg.org/css-transitions-2/#defining-before-change-style-the-starting-style-rule "starting-style": atRuleInheritContext, + + // Anchor Positioning + // Reference: https://drafts.csswg.org/css-anchor-position-1/#at-ruledef-position-try + "position-try": atRuleDeclarations, } var atKnownRuleCanBeRemovedIfEmpty = map[string]bool{ diff --git a/internal/css_parser/css_parser_test.go b/internal/css_parser/css_parser_test.go index fd4dee7d64c..c4daa21fd9e 100644 --- a/internal/css_parser/css_parser_test.go +++ b/internal/css_parser/css_parser_test.go @@ -1539,6 +1539,14 @@ func TestAtRule(t *testing.T) { } } `, "") + + // https://drafts.csswg.org/css-anchor-position-1/#at-ruledef-position-try + expectPrinted(t, `@position-try --foo { top: 0 }`, + `@position-try --foo { + top: 0; +} +`, "") + expectPrintedMinify(t, `@position-try --foo { top: 0; }`, `@position-try --foo{top:0}`, "") } func TestAtCharset(t *testing.T) {