Skip to content

Commit

Permalink
JS: fix grouped statement ending parenthesis for objects, fixes #429
Browse files Browse the repository at this point in the history
  • Loading branch information
tdewolff committed Jul 29, 2021
1 parent f571872 commit 9f73f9d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
7 changes: 5 additions & 2 deletions js/js.go
Original file line number Diff line number Diff line change
Expand Up @@ -1057,9 +1057,9 @@ func (m *jsMinifier) minifyExpr(i js.IExpr, prec js.OpPrec) {
case *js.ObjectExpr:
parentInFor := m.inFor
m.inFor = false
if m.expectExpr != expectAny {
groupedStmt := m.expectExpr != expectAny
if groupedStmt {
m.write(openParenBracketBytes)
m.groupedStmt = true
} else {
m.write(openBraceBytes)
}
Expand All @@ -1070,6 +1070,9 @@ func (m *jsMinifier) minifyExpr(i js.IExpr, prec js.OpPrec) {
m.minifyProperty(item)
}
m.write(closeBraceBytes)
if groupedStmt {
m.groupedStmt = true
}
m.inFor = parentInFor
case *js.TemplateExpr:
if expr.Tag != nil {
Expand Down
1 change: 1 addition & 0 deletions js/js_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,7 @@ func TestJS(t *testing.T) {
{`export function a(b){}`, `export function a(b){}`}, // #375
{`switch(a){case 0:b=c;d=e}`, `switch(a){case 0:b=c,d=e}`}, // #426
{`if(a){const b=0}`, ``}, // #428
{`()=>({a(){b=!b}})`, `()=>({a(){b=!b}})`}, // #429
}

m := minify.New()
Expand Down

0 comments on commit 9f73f9d

Please sign in to comment.