@@ -1407,57 +1407,59 @@ formatExpression' elmVersion importInfo context aexpr =
14071407 (fmap (formatPreCommentedExpression elmVersion importInfo SpaceSeparated ) args)
14081408 |> expressionParens SpaceSeparated context
14091409
1410- AST.Expression. If if' elseifs (elsComments, els) ->
1411- let
1412- opening key cond =
1413- case (key, cond) of
1414- (SingleLine key', SingleLine cond') ->
1415- line $ row
1416- [ key'
1417- , space
1418- , cond'
1419- , space
1420- , keyword " then"
1421- ]
1422- _ ->
1410+ AST.Expression. If (cond, body) elseifs (elsComments, els) multiline ->
1411+ case
1412+ ( multiline
1413+ , formatCommentedExpression elmVersion importInfo SyntaxSeparated cond
1414+ , formatCommented_ True (formatExpression elmVersion importInfo SyntaxSeparated ) body
1415+ , elseifs
1416+ , formatCommented_ True (formatExpression elmVersion importInfo SyntaxSeparated ) (AST. Commented elsComments els [] )
1417+ )
1418+ of
1419+ (False , SingleLine cond', SingleLine body', [] , SingleLine els') ->
1420+ line $ row
1421+ [ keyword " if" , space , cond' , space , keyword " then" , space , body' , space , keyword " else" , space , els' ]
1422+ (_, ifCond, thenBody, _, elseBody) ->
1423+ let
1424+ opening (SingleLine key) (SingleLine cond') =
1425+ line $ row [ key , space , cond' , space , keyword " then" ]
1426+ opening key cond' =
14231427 stack1
14241428 [ key
1425- , cond |> indent
1429+ , cond' |> indent
14261430 , line $ keyword " then"
14271431 ]
14281432
1429- formatIf (cond, body) =
1433+ formatElseIf (ifComments, (cond', body')) =
1434+ let
1435+ key =
1436+ case (formatHeadCommented id (ifComments, line $ keyword " if" )) of
1437+ SingleLine key' ->
1438+ line $ row [ keyword " else" , space, key' ]
1439+ key' ->
1440+ stack1
1441+ [ line $ keyword " else"
1442+ , key'
1443+ ]
1444+ in
1445+ stack1
1446+ [ blankLine
1447+ , opening key $ formatCommentedExpression elmVersion importInfo SyntaxSeparated cond'
1448+ , indent $ formatCommented_ True (formatExpression elmVersion importInfo SyntaxSeparated ) body'
1449+ ]
1450+ in
14301451 stack1
1431- [ opening (line $ keyword " if" ) $ formatCommentedExpression elmVersion importInfo SyntaxSeparated cond
1432- , indent $ formatCommented_ True (formatExpression elmVersion importInfo SyntaxSeparated ) body
1452+ [ opening (line $ keyword " if" ) ifCond
1453+ , indent thenBody
14331454 ]
1434-
1435- formatElseIf (ifComments, (cond, body)) =
1436- let
1437- key =
1438- case (formatHeadCommented id (ifComments, line $ keyword " if" )) of
1439- SingleLine key' ->
1440- line $ row [ keyword " else" , space, key' ]
1441- key' ->
1442- stack1
1443- [ line $ keyword " else"
1444- , key'
1455+ |> andThen (map formatElseIf elseifs)
1456+ |> andThen
1457+ [ blankLine
1458+ , line $ keyword " else"
1459+ , indent $ elseBody
14451460 ]
1446- in
1447- stack1
1448- [ blankLine
1449- , opening key $ formatCommentedExpression elmVersion importInfo SyntaxSeparated cond
1450- , indent $ formatCommented_ True (formatExpression elmVersion importInfo SyntaxSeparated ) body
1451- ]
1452- in
1453- formatIf if'
1454- |> andThen (map formatElseIf elseifs)
1455- |> andThen
1456- [ blankLine
1457- , line $ keyword " else"
1458- , indent $ formatCommented_ True (formatExpression elmVersion importInfo SyntaxSeparated ) (AST. Commented elsComments els [] )
1459- ]
1460- |> expressionParens AmbiguousEnd context
1461+ |> expressionParens AmbiguousEnd context
1462+
14611463
14621464 AST.Expression. Let defs bodyComments expr ->
14631465 let
0 commit comments