Skip to content

Commit

Permalink
fix evanw#2117: support @font-feature-values
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw authored and zhusjfaker committed Mar 28, 2022
1 parent 03fdb1a commit 9add575
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
9 changes: 5 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@

## Unreleased

* Add support for some new CSS rules ([#2115](https://github.com/evanw/esbuild/issues/2115), [#2116](https://github.com/evanw/esbuild/issues/2116))
* Add support for some new CSS rules ([#2115](https://github.com/evanw/esbuild/issues/2115), [#2116](https://github.com/evanw/esbuild/issues/2116), [#2117](https://github.com/evanw/esbuild/issues/2117))

This release adds support for [`@font-palette-values`](https://drafts.csswg.org/css-fonts-4/#font-palette-values) and [`@counter-style`](https://developer.mozilla.org/en-US/docs/Web/CSS/@counter-style):
This release adds support for [`@font-palette-values`](https://drafts.csswg.org/css-fonts-4/#font-palette-values), [`@counter-style`](https://developer.mozilla.org/en-US/docs/Web/CSS/@counter-style), and [`@font-feature-values`](https://developer.mozilla.org/en-US/docs/Web/CSS/@font-feature-values). This means esbuild will now pretty-print and minify these rules better since it now better understands the internal structure of these rules:

```css
/* Original code */
@font-palette-values Foo { base-palette: 1; }
@counter-style bar { symbols: b a r; }
@font-feature-values Bop { @styleset { test: 1; } }

/* Old output (with --minify) */
@font-palette-values Foo{base-palette: 1;}@counter-style bar{symbols: b a r;}
@font-palette-values Foo{base-palette: 1;}@counter-style bar{symbols: b a r;}@font-feature-values Bop{@styleset {test: 1;}}

/* New output (with --minify) */
@font-palette-values Foo{base-palette:1}@counter-style bar{symbols:b a r}
@font-palette-values Foo{base-palette:1}@counter-style bar{symbols:b a r}@font-feature-values Bop{@styleset{test:1}}
```

## 0.14.27
Expand Down
11 changes: 11 additions & 0 deletions internal/css_parser/css_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,17 @@ var specialAtRules = map[string]atRuleKind{
// Documentation: https://developer.mozilla.org/en-US/docs/Web/CSS/@counter-style
// Reference: https://drafts.csswg.org/css-counter-styles/#the-counter-style-rule
"counter-style": atRuleDeclarations,

// Documentation: https://developer.mozilla.org/en-US/docs/Web/CSS/@font-feature-values
// Reference: https://drafts.csswg.org/css-fonts/#font-feature-values
"font-feature-values": atRuleDeclarations,
"annotation": atRuleDeclarations,
"character-variant": atRuleDeclarations,
"historical-forms": atRuleDeclarations,
"ornaments": atRuleDeclarations,
"styleset": atRuleDeclarations,
"stylistic": atRuleDeclarations,
"swash": atRuleDeclarations,
}

type atRuleValidity uint8
Expand Down
20 changes: 20 additions & 0 deletions internal/css_parser/css_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,26 @@ func TestAtRule(t *testing.T) {
symbols: ◰ ◳ ◲ ◱;
suffix: ": ";
}
`)

// https://drafts.csswg.org/css-fonts/#font-feature-values
expectPrinted(t, `
@font-feature-values Roboto {
font-display: swap;
}
`, `@font-feature-values Roboto {
font-display: swap;
}
`)
expectPrinted(t, `
@font-feature-values Bongo {
@swash { ornate: 1 }
}
`, `@font-feature-values Bongo {
@swash {
ornate: 1;
}
}
`)
}

Expand Down

0 comments on commit 9add575

Please sign in to comment.