| ... | @@ -1448,17 +1448,17 @@ fn renderExpression( | ... | @@ -1448,17 +1448,17 @@ fn renderExpression( |
| 1448 | const has_payload = for_node.payload != null; | 1448 | const has_payload = for_node.payload != null; |
| 1449 | const body_is_block = for_node.body.id == ast.Node.Id.Block; | 1449 | const body_is_block = for_node.body.id == ast.Node.Id.Block; |
| 1450 | const src_one_line_to_body = !body_is_block and tree.tokensOnSameLine(rparen, for_node.body.firstToken()); | 1450 | const src_one_line_to_body = !body_is_block and tree.tokensOnSameLine(rparen, for_node.body.firstToken()); |
| 1451 | const body_indent = if (!body_is_block and !src_one_line_to_body) indent + indent_delta else indent; | 1451 | const body_on_same_line = body_is_block or src_one_line_to_body; |
| 1452 | | 1452 | |
| 1453 | const rparen_space = if (has_payload or body_is_block or src_one_line_to_body) Space.Space else Space.Newline; | 1453 | const space_after_rparen = if (has_payload or body_on_same_line) Space.Space else Space.Newline; |
| 1454 | try renderToken(tree, stream, rparen, body_indent, start_col, rparen_space); // ) | 1454 | try renderToken(tree, stream, rparen, indent, start_col, space_after_rparen); // ) |
| 1455 | | 1455 | |
| 1456 | if (for_node.payload) |payload| { | 1456 | if (for_node.payload) |payload| { |
| 1457 | const payload_space = if (body_is_block or src_one_line_to_body) Space.Space else Space.Newline; | 1457 | const space_after_payload = if (body_on_same_line) Space.Space else Space.Newline; |
| 1458 | try renderExpression(allocator, stream, tree, body_indent, start_col, payload, payload_space); // |x| | 1458 | try renderExpression(allocator, stream, tree, indent, start_col, payload, space_after_payload); // |x| |
| 1459 | } | 1459 | } |
| 1460 | | 1460 | |
| 1461 | const body_space = blk: { | 1461 | const space_after_body = blk: { |
| 1462 | if (for_node.@"else") |@"else"| { | 1462 | if (for_node.@"else") |@"else"| { |
| 1463 | const src_one_line_to_else = tree.tokensOnSameLine(for_node.body.lastToken(), @"else".firstToken()); | 1463 | const src_one_line_to_else = tree.tokensOnSameLine(for_node.body.lastToken(), @"else".firstToken()); |
| 1464 | if (body_is_block or src_one_line_to_else) { | 1464 | if (body_is_block or src_one_line_to_else) { |
| ... | @@ -1471,11 +1471,13 @@ fn renderExpression( | ... | @@ -1471,11 +1471,13 @@ fn renderExpression( |
| 1471 | } | 1471 | } |
| 1472 | }; | 1472 | }; |
| 1473 | | 1473 | |
| 1474 | if (!body_is_block and !src_one_line_to_body) try stream.writeByteNTimes(' ', body_indent); | 1474 | const body_indent = if (body_on_same_line) indent else indent + indent_delta; |
| 1475 | try renderExpression(allocator, stream, tree, body_indent, start_col, for_node.body, body_space); | 1475 | if (!body_on_same_line) try stream.writeByteNTimes(' ', body_indent); |
| | 1476 | try renderExpression(allocator, stream, tree, body_indent, start_col, for_node.body, space_after_body); // { body } |
| 1476 | | 1477 | |
| 1477 | if (for_node.@"else") |@"else"| { | 1478 | if (for_node.@"else") |@"else"| { |
| 1478 | return renderExpression(allocator, stream, tree, body_indent, start_col, &@"else".base, space); | 1479 | if (space_after_body == Space.Newline) try stream.writeByteNTimes(' ', indent); |
| | 1480 | return renderExpression(allocator, stream, tree, indent, start_col, &@"else".base, space); // else |
| 1479 | } | 1481 | } |
| 1480 | }, | 1482 | }, |
| 1481 | | 1483 | |