Skip to content

Commit

Permalink
fix: negative number is illegal attribute for object (#2273)
Browse files Browse the repository at this point in the history
  • Loading branch information
susiwen8 authored May 27, 2022
1 parent a5bad10 commit f798118
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion internal/js_parser/js_parser.go
Original file line number Diff line number Diff line change
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); ok {
if numberValue, ok := stringToEquivalentNumberValue(str.Value); numberValue >= 0 && ok {
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 @@ -1222,15 +1222,15 @@ func TestObject(t *testing.T) {
// Check the string-to-int optimization
expectPrintedMangle(t, "x = { '0': y }", "x = { 0: y };\n")
expectPrintedMangle(t, "x = { '123': y }", "x = { 123: y };\n")
expectPrintedMangle(t, "x = { '-123': y }", "x = { -123: y };\n")
expectPrintedMangle(t, "x = { '-123': y }", "x = { \"-123\": y };\n")
expectPrintedMangle(t, "x = { '-0': y }", "x = { \"-0\": y };\n")
expectPrintedMangle(t, "x = { '01': y }", "x = { \"01\": y };\n")
expectPrintedMangle(t, "x = { '-01': y }", "x = { \"-01\": y };\n")
expectPrintedMangle(t, "x = { '0x1': y }", "x = { \"0x1\": y };\n")
expectPrintedMangle(t, "x = { '-0x1': y }", "x = { \"-0x1\": y };\n")
expectPrintedMangle(t, "x = { '2147483647': y }", "x = { 2147483647: y };\n")
expectPrintedMangle(t, "x = { '2147483648': y }", "x = { \"2147483648\": y };\n")
expectPrintedMangle(t, "x = { '-2147483648': y }", "x = { -2147483648: y };\n")
expectPrintedMangle(t, "x = { '-2147483648': y }", "x = { \"-2147483648\": y };\n")
expectPrintedMangle(t, "x = { '-2147483649': y }", "x = { \"-2147483649\": y };\n")
}

Expand Down

0 comments on commit f798118

Please sign in to comment.