Skip to content

Commit

Permalink
JS: fix merging of assignments with let/const declarations, fixes #474
Browse files Browse the repository at this point in the history
  • Loading branch information
tdewolff committed Apr 8, 2022
1 parent 5322465 commit d0c7dfa
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions js/js_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,7 @@ func TestJS(t *testing.T) {
{`var a=1;function f(){return 1}var{min,max}=Math;function g(){return 2}`, `a=1;function f(){return 1}var{min,max}=Math,a;function g(){return 2}`}, // #445
{`const f=x=>void console.log(x)`, `const f=x=>void console.log(x)`}, // #463
{`(function(){var a=b;var c=d.x,e=f.y})()`, `(function(){var a=b,c=d.x,e=f.y})()`}, // #472
{`var a=1;g();a=2;let b=3`, `var a=1;g(),a=2;let b=3`}, // #474
}

m := minify.New()
Expand Down
2 changes: 1 addition & 1 deletion js/stmtlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func optimizeStmtList(list []js.IStmt, blockType blockType) []js.IStmt {
} else if ifStmt, ok := list[i].(*js.IfStmt); ok {
ifStmt.Cond = commaExpr(left.Value, ifStmt.Cond)
j--
} else if varDecl, ok := list[i].(*js.VarDecl); ok {
} else if varDecl, ok := list[i].(*js.VarDecl); ok && varDecl.TokenType == js.VarToken {
if merge := mergeVarDeclExprStmt(varDecl, left, true); merge {
j--
}
Expand Down

0 comments on commit d0c7dfa

Please sign in to comment.