Skip to content

Commit a579bd8

Browse files
committed
fix #3452: insert space in font when minifying
1 parent cd91337 commit a579bd8

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,27 @@
22

33
## Unreleased
44

5+
* Fix a CSS `font` property minification bug ([#3452](https://github.com/evanw/esbuild/issues/3452))
6+
7+
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:
8+
9+
```css
10+
/* Original code */
11+
.foo { font: 16px"Menlo"; }
12+
13+
/* Old output (with --minify) */
14+
.foo{font:16pxMenlo}
15+
16+
/* New output (with --minify) */
17+
.foo{font:16px Menlo}
18+
```
19+
520
* Update to Unicode 15.1.0
621

722
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.
823

24+
This upgrade was contributed by [@JLHwung](https://github.com/JLHwung).
25+
926
## 0.19.4
1027

1128
* Fix printing of JavaScript decorators in tricky cases ([#3396](https://github.com/evanw/esbuild/issues/3396))

internal/css_parser/css_decls_font.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ func (p *parser) mangleFont(tokens []css_ast.Token) []css_ast.Token {
9797

9898
// <font-family>
9999
if family, ok := p.mangleFontFamily(tokens[pos:]); ok {
100+
if len(result) > 0 && len(family) > 0 && family[0].Kind != css_lexer.TString {
101+
family[0].Whitespace |= css_ast.WhitespaceBefore
102+
}
100103
return append(result, family...)
101104
}
102105
return tokens

internal/css_parser/css_parser_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2215,6 +2215,14 @@ func TestFont(t *testing.T) {
22152215

22162216
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}", "")
22172217
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}", "")
2218+
2219+
// See: https://github.com/evanw/esbuild/issues/3452
2220+
expectPrinted(t, "a { font: 10px'foo' }", "a {\n font: 10px\"foo\";\n}\n", "")
2221+
expectPrinted(t, "a { font: 10px'123' }", "a {\n font: 10px\"123\";\n}\n", "")
2222+
expectPrintedMangle(t, "a { font: 10px'foo' }", "a {\n font: 10px foo;\n}\n", "")
2223+
expectPrintedMangle(t, "a { font: 10px'123' }", "a {\n font: 10px\"123\";\n}\n", "")
2224+
expectPrintedMangleMinify(t, "a { font: 10px'foo' }", "a{font:10px foo}", "")
2225+
expectPrintedMangleMinify(t, "a { font: 10px'123' }", "a{font:10px\"123\"}", "")
22182226
}
22192227

22202228
func TestWarningUnexpectedCloseBrace(t *testing.T) {

0 commit comments

Comments
 (0)