@@ -13,9 +13,10 @@
1313--
1414-----------------------------------------------------------------------------
1515
16−module Language.PureScript.Optimizer.Blocks (
17− collapseNestedBlocks
18−) where
16+module Language.PureScript.Optimizer.Blocks
17+ ( collapseNestedBlocks
18+ , collapseNestedIfs
19+ ) where
1920
2021import Language.PureScript.CodeGen.JS.AST
2122
@@ -31,3 +32,11 @@ collapseNestedBlocks = everywhereOnJS collapse
3132 go :: JS -> [JS]
3233 go (JSBlock sts) = sts
3334 go s = [s]
35+
36+collapseNestedIfs :: JS -> JS
37+collapseNestedIfs = everywhereOnJS collapse
38+ where
39+ collapse :: JS -> JS
40+ collapse (JSIfElse cond1 (JSBlock [JSIfElse cond2 body Nothing]) Nothing) =
41+ JSIfElse (JSBinary And cond1 cond2) body Nothing
42+ collapse js = js