Skip to content

Commit

Permalink
release notes and an additional fix for #2270
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed May 27, 2022
1 parent f798118 commit 2a37d4d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## Unreleased

* Fix a minification regression in 0.14.40 ([#2270](https://github.com/evanw/esbuild/issues/2270), [#2271](https://github.com/evanw/esbuild/issues/2271), [#2273](https://github.com/evanw/esbuild/pull/2273))

Version 0.14.40 substituted string property keys with numeric property keys if the number has the same string representation as the original string. This was done in three places: computed member expressions, object literal properties, and class fields. However, negative numbers are only valid in computed member expressions while esbuild incorrectly applied this substitution for negative numbers in all places. This release fixes the regression by only doing this substitution for negative numbers in computed member expressions.

This fix was contributed by [@susiwen8](https://github.com/susiwen8).

## 0.14.40

* Correct esbuild's implementation of `"preserveValueImports": true` ([#2268](https://github.com/evanw/esbuild/issues/2268))
Expand Down
4 changes: 2 additions & 2 deletions internal/js_parser/js_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -10382,7 +10382,7 @@ func (p *parser) visitClass(nameScopeLoc logger.Loc, class *js_ast.Class, defaul

if p.options.minifySyntax {
if str, ok := key.Data.(*js_ast.EString); ok {
if numberValue, ok := stringToEquivalentNumberValue(str.Value); ok {
if numberValue, ok := stringToEquivalentNumberValue(str.Value); ok && numberValue >= 0 {
// "class { '123' }" => "class { 123 }"
property.Key.Data = &js_ast.ENumber{Value: numberValue}
property.Flags &= ^js_ast.PropertyIsComputed
Expand Down Expand Up @@ -13183,7 +13183,7 @@ func (p *parser) visitExprInOut(expr js_ast.Expr, in exprIn) (js_ast.Expr, exprO
// "{ '123': 4 }" => "{ 123: 4 }" (this is done late to allow "'123'" to be mangled)
if p.options.minifySyntax {
if str, ok := property.Key.Data.(*js_ast.EString); ok {
if numberValue, ok := stringToEquivalentNumberValue(str.Value); numberValue >= 0 && ok {
if numberValue, ok := stringToEquivalentNumberValue(str.Value); ok && numberValue >= 0 {
property.Key.Data = &js_ast.ENumber{Value: numberValue}
}
}
Expand Down
4 changes: 2 additions & 2 deletions internal/js_parser/js_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1578,15 +1578,15 @@ func TestClass(t *testing.T) {
// Check the string-to-int optimization
expectPrintedMangle(t, "class x { '0' = y }", "class x {\n 0 = y;\n}\n")
expectPrintedMangle(t, "class x { '123' = y }", "class x {\n 123 = y;\n}\n")
expectPrintedMangle(t, "class x { ['-123'] = y }", "class x {\n -123 = y;\n}\n")
expectPrintedMangle(t, "class x { ['-123'] = y }", "class x {\n \"-123\" = y;\n}\n")
expectPrintedMangle(t, "class x { '-0' = y }", "class x {\n \"-0\" = y;\n}\n")
expectPrintedMangle(t, "class x { '01' = y }", "class x {\n \"01\" = y;\n}\n")
expectPrintedMangle(t, "class x { '-01' = y }", "class x {\n \"-01\" = y;\n}\n")
expectPrintedMangle(t, "class x { '0x1' = y }", "class x {\n \"0x1\" = y;\n}\n")
expectPrintedMangle(t, "class x { '-0x1' = y }", "class x {\n \"-0x1\" = y;\n}\n")
expectPrintedMangle(t, "class x { '2147483647' = y }", "class x {\n 2147483647 = y;\n}\n")
expectPrintedMangle(t, "class x { '2147483648' = y }", "class x {\n \"2147483648\" = y;\n}\n")
expectPrintedMangle(t, "class x { ['-2147483648'] = y }", "class x {\n -2147483648 = y;\n}\n")
expectPrintedMangle(t, "class x { ['-2147483648'] = y }", "class x {\n \"-2147483648\" = y;\n}\n")
expectPrintedMangle(t, "class x { ['-2147483649'] = y }", "class x {\n \"-2147483649\" = y;\n}\n")
}

Expand Down

0 comments on commit 2a37d4d

Please sign in to comment.