From 6e2dbbde3aee8bb2eeafcebe2190318f313451f5 Mon Sep 17 00:00:00 2001 From: Taco de Wolff Date: Fri, 1 Jul 2022 18:12:27 -0400 Subject: [PATCH] Revert "JS: remove else in second/third/... else-if when preceded by a return/break/continue/throw statement", fixes #509 This reverts commit a66515866912e7c4bfc38e1a04866efe2385e05d. --- js/js_test.go | 1 - js/stmtlist.go | 3 --- 2 files changed, 4 deletions(-) diff --git a/js/js_test.go b/js/js_test.go index 02712a1666..77e5e26e53 100644 --- a/js/js_test.go +++ b/js/js_test.go @@ -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}`}, diff --git a/js/stmtlist.go b/js/stmtlist.go index 7e32830ba4..a1d3e2ef9f 100644 --- a/js/stmtlist.go +++ b/js/stmtlist.go @@ -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 @@ -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 } }