Skip to content

Commit

Permalink
fix #3452: insert space in font when minifying
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed Oct 16, 2023
1 parent cd91337 commit a579bd8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,27 @@

## Unreleased

* Fix a CSS `font` property minification bug ([#3452](https://github.com/evanw/esbuild/issues/3452))

This release fixes a bug where esbuild's CSS minifier didn't insert a space between the font size and the font family in the `font` CSS shorthand property in the edge case where the original source code didn't already have a space and the leading string token was shortened to an identifier:

```css
/* Original code */
.foo { font: 16px"Menlo"; }

/* Old output (with --minify) */
.foo{font:16pxMenlo}

/* New output (with --minify) */
.foo{font:16px Menlo}
```

* Update to Unicode 15.1.0

The character tables that determine which characters form valid JavaScript identifiers have been updated from Unicode version 15.0.0 to the newly-released Unicode version 15.1.0. I'm not putting an example in the release notes because all of the new characters will likely just show up as little squares since fonts haven't been updated yet. But you can read https://www.unicode.org/versions/Unicode15.1.0/#Summary for more information about the changes.

This upgrade was contributed by [@JLHwung](https://github.com/JLHwung).

## 0.19.4

* Fix printing of JavaScript decorators in tricky cases ([#3396](https://github.com/evanw/esbuild/issues/3396))
Expand Down
3 changes: 3 additions & 0 deletions internal/css_parser/css_decls_font.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ func (p *parser) mangleFont(tokens []css_ast.Token) []css_ast.Token {

// <font-family>
if family, ok := p.mangleFontFamily(tokens[pos:]); ok {
if len(result) > 0 && len(family) > 0 && family[0].Kind != css_lexer.TString {
family[0].Whitespace |= css_ast.WhitespaceBefore
}
return append(result, family...)
}
return tokens
Expand Down
8 changes: 8 additions & 0 deletions internal/css_parser/css_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2215,6 +2215,14 @@ func TestFont(t *testing.T) {

expectPrintedMangleMinify(t, "a { font: italic small-caps bold ultra-condensed 1rem/1.2 'aaa bbb' }", "a{font:italic small-caps 700 ultra-condensed 1rem/1.2 aaa bbb}", "")
expectPrintedMangleMinify(t, "a { font: italic small-caps bold ultra-condensed 1rem / 1.2 'aaa bbb' }", "a{font:italic small-caps 700 ultra-condensed 1rem/1.2 aaa bbb}", "")

// See: https://github.com/evanw/esbuild/issues/3452
expectPrinted(t, "a { font: 10px'foo' }", "a {\n font: 10px\"foo\";\n}\n", "")
expectPrinted(t, "a { font: 10px'123' }", "a {\n font: 10px\"123\";\n}\n", "")
expectPrintedMangle(t, "a { font: 10px'foo' }", "a {\n font: 10px foo;\n}\n", "")
expectPrintedMangle(t, "a { font: 10px'123' }", "a {\n font: 10px\"123\";\n}\n", "")
expectPrintedMangleMinify(t, "a { font: 10px'foo' }", "a{font:10px foo}", "")
expectPrintedMangleMinify(t, "a { font: 10px'123' }", "a{font:10px\"123\"}", "")
}

func TestWarningUnexpectedCloseBrace(t *testing.T) {
Expand Down

0 comments on commit a579bd8

Please sign in to comment.