Skip to content

Commit 2a37d4d

Browse files
committed
release notes and an additional fix for #2270
1 parent f798118 commit 2a37d4d

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
* 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))
6+
7+
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.
8+
9+
This fix was contributed by [@susiwen8](https://github.com/susiwen8).
10+
311
## 0.14.40
412

513
* Correct esbuild's implementation of `"preserveValueImports": true` ([#2268](https://github.com/evanw/esbuild/issues/2268))

internal/js_parser/js_parser.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10382,7 +10382,7 @@ func (p *parser) visitClass(nameScopeLoc logger.Loc, class *js_ast.Class, defaul
1038210382

1038310383
if p.options.minifySyntax {
1038410384
if str, ok := key.Data.(*js_ast.EString); ok {
10385-
if numberValue, ok := stringToEquivalentNumberValue(str.Value); ok {
10385+
if numberValue, ok := stringToEquivalentNumberValue(str.Value); ok && numberValue >= 0 {
1038610386
// "class { '123' }" => "class { 123 }"
1038710387
property.Key.Data = &js_ast.ENumber{Value: numberValue}
1038810388
property.Flags &= ^js_ast.PropertyIsComputed
@@ -13183,7 +13183,7 @@ func (p *parser) visitExprInOut(expr js_ast.Expr, in exprIn) (js_ast.Expr, exprO
1318313183
// "{ '123': 4 }" => "{ 123: 4 }" (this is done late to allow "'123'" to be mangled)
1318413184
if p.options.minifySyntax {
1318513185
if str, ok := property.Key.Data.(*js_ast.EString); ok {
13186-
if numberValue, ok := stringToEquivalentNumberValue(str.Value); numberValue >= 0 && ok {
13186+
if numberValue, ok := stringToEquivalentNumberValue(str.Value); ok && numberValue >= 0 {
1318713187
property.Key.Data = &js_ast.ENumber{Value: numberValue}
1318813188
}
1318913189
}

internal/js_parser/js_parser_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1578,15 +1578,15 @@ func TestClass(t *testing.T) {
15781578
// Check the string-to-int optimization
15791579
expectPrintedMangle(t, "class x { '0' = y }", "class x {\n 0 = y;\n}\n")
15801580
expectPrintedMangle(t, "class x { '123' = y }", "class x {\n 123 = y;\n}\n")
1581-
expectPrintedMangle(t, "class x { ['-123'] = y }", "class x {\n -123 = y;\n}\n")
1581+
expectPrintedMangle(t, "class x { ['-123'] = y }", "class x {\n \"-123\" = y;\n}\n")
15821582
expectPrintedMangle(t, "class x { '-0' = y }", "class x {\n \"-0\" = y;\n}\n")
15831583
expectPrintedMangle(t, "class x { '01' = y }", "class x {\n \"01\" = y;\n}\n")
15841584
expectPrintedMangle(t, "class x { '-01' = y }", "class x {\n \"-01\" = y;\n}\n")
15851585
expectPrintedMangle(t, "class x { '0x1' = y }", "class x {\n \"0x1\" = y;\n}\n")
15861586
expectPrintedMangle(t, "class x { '-0x1' = y }", "class x {\n \"-0x1\" = y;\n}\n")
15871587
expectPrintedMangle(t, "class x { '2147483647' = y }", "class x {\n 2147483647 = y;\n}\n")
15881588
expectPrintedMangle(t, "class x { '2147483648' = y }", "class x {\n \"2147483648\" = y;\n}\n")
1589-
expectPrintedMangle(t, "class x { ['-2147483648'] = y }", "class x {\n -2147483648 = y;\n}\n")
1589+
expectPrintedMangle(t, "class x { ['-2147483648'] = y }", "class x {\n \"-2147483648\" = y;\n}\n")
15901590
expectPrintedMangle(t, "class x { ['-2147483649'] = y }", "class x {\n \"-2147483649\" = y;\n}\n")
15911591
}
15921592

0 commit comments

Comments
 (0)