@@ -309,8 +309,11 @@ generateLet givenDefs givenBody =
309309-- GENERATE IFS
310310
311311generateIf :: [(Canonical.Expr, Canonical.Expr)] -> Canonical.Expr -> State Int Code
312−generateIf branches finally =
312+generateIf givenBranches givenFinally =
313313 let
314+ (branches, finally) =
315+ combineIfs givenBranches givenFinally
316+
314317 convertBranch (condition, expr) =
315318 (,) <$> exprToJsExpr condition <*> exprToCode expr
316319
@@ -330,6 +333,19 @@ generateIf branches finally =
330333 jsExpr (foldr ifExpression (toExpr jsFinally) (map (second toExpr) jsBranches))
331334
332335
336+combineIfs
337+ :: [(Canonical.Expr, Canonical.Expr)]
338+ -> Canonical.Expr
339+ -> ([(Canonical.Expr, Canonical.Expr)], Canonical.Expr)
340+combineIfs branches finally =
341+ case finally of
342+ A.A _ (MultiIf subBranches subFinally) ->
343+ combineIfs (branches ++ subBranches) subFinally
344+
345+ _ ->
346+ (branches, finally)
347+
348+
333349-- DEFINITIONS
334350
335351defToStatements :: Canonical.Def -> State Int [Statement ()]