Skip to content

Commit

Permalink
Revert "JS: remove else in second/third/... else-if when preceded by …
Browse files Browse the repository at this point in the history
…a return/break/continue/throw statement", fixes #509

This reverts commit a665158.
  • Loading branch information
tdewolff committed Jul 1, 2022
1 parent 2669ff7 commit 6e2dbbd
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 4 deletions.
1 change: 0 additions & 1 deletion js/js_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ func TestJS(t *testing.T) {
{`if(a){}else{while(b);}`, `if(a);else for(;b;);`},
{`if(a){return b}else{while(c);}`, `if(a)return b;for(;c;);`},
{`if(a){return b}else{while(c);d}`, `if(a)return b;for(;c;);d`},
{`if(a)b;else if(c)return d;else if(e)return f`, `if(a)b;else if(c)return d;if(e)return f`},
{`if(!a){while(b);c}`, `if(!a){for(;b;);c}`},
{`while(a){if(b)continue;if(c)continue;else d}`, `for(;a;){if(b)continue;if(c)continue;d}`},
{`while(a)if(b)continue;else c`, `for(;a;){if(b)continue;c}`},
Expand Down
3 changes: 0 additions & 3 deletions js/stmtlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ func optimizeStmtList(list []js.IStmt, blockType blockType) []js.IStmt {
for i := 0; i < len(list); i++ { // read index
if ifStmt, ok := list[i].(*js.IfStmt); ok && !isEmptyStmt(ifStmt.Else) {
// if(!a)b;else c => if(a)c; else b
IfElseLoop:
if unary, ok := ifStmt.Cond.(*js.UnaryExpr); ok && unary.Op == js.NotToken && isFlowStmt(lastStmt(ifStmt.Else)) {
ifStmt.Cond = unary.X
ifStmt.Body, ifStmt.Else = ifStmt.Else, ifStmt.Body
Expand All @@ -160,8 +159,6 @@ func optimizeStmtList(list []js.IStmt, blockType blockType) []js.IStmt {
list = append(list[:i+1], append([]js.IStmt{ifStmt.Else}, list[i+1:]...)...)
}
ifStmt.Else = nil
} else if ifStmt, ok = ifStmt.Else.(*js.IfStmt); ok && !isEmptyStmt(ifStmt.Else) {
goto IfElseLoop
}
}

Expand Down

0 comments on commit 6e2dbbd

Please sign in to comment.