| ... | ... | @@ -693,39 +693,27 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void { |
| 693 | 693 | return renderToken(r, datas[node].rhs, space); |
| 694 | 694 | }, |
| 695 | 695 | |
| 696 | | .@"break" => { |
| 696 | .@"break", .@"continue" => { |
| 697 | 697 | const main_token = main_tokens[node]; |
| 698 | 698 | const label_token = datas[node].lhs; |
| 699 | 699 | const target = datas[node].rhs; |
| 700 | 700 | if (label_token == 0 and target == 0) { |
| 701 | | try renderToken(r, main_token, space); // break keyword |
| 701 | try renderToken(r, main_token, space); // break/continue |
| 702 | 702 | } else if (label_token == 0 and target != 0) { |
| 703 | | try renderToken(r, main_token, .space); // break keyword |
| 703 | try renderToken(r, main_token, .space); // break/continue |
| 704 | 704 | try renderExpression(r, target, space); |
| 705 | 705 | } else if (label_token != 0 and target == 0) { |
| 706 | | try renderToken(r, main_token, .space); // break keyword |
| 707 | | try renderToken(r, label_token - 1, .none); // colon |
| 706 | try renderToken(r, main_token, .space); // break/continue |
| 707 | try renderToken(r, label_token - 1, .none); // : |
| 708 | 708 | try renderIdentifier(r, label_token, space, .eagerly_unquote); // identifier |
| 709 | 709 | } else if (label_token != 0 and target != 0) { |
| 710 | | try renderToken(r, main_token, .space); // break keyword |
| 711 | | try renderToken(r, label_token - 1, .none); // colon |
| 710 | try renderToken(r, main_token, .space); // break/continue |
| 711 | try renderToken(r, label_token - 1, .none); // : |
| 712 | 712 | try renderIdentifier(r, label_token, .space, .eagerly_unquote); // identifier |
| 713 | 713 | try renderExpression(r, target, space); |
| 714 | 714 | } |
| 715 | 715 | }, |
| 716 | 716 | |
| 717 | | .@"continue" => { |
| 718 | | const main_token = main_tokens[node]; |
| 719 | | const label = datas[node].lhs; |
| 720 | | if (label != 0) { |
| 721 | | try renderToken(r, main_token, .space); // continue |
| 722 | | try renderToken(r, label - 1, .none); // : |
| 723 | | return renderIdentifier(r, label, space, .eagerly_unquote); // label |
| 724 | | } else { |
| 725 | | return renderToken(r, main_token, space); // continue |
| 726 | | } |
| 727 | | }, |
| 728 | | |
| 729 | 717 | .@"return" => { |
| 730 | 718 | if (datas[node].lhs != 0) { |
| 731 | 719 | try renderToken(r, main_tokens[node], .space); |
| ... | ... | @@ -845,26 +833,29 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void { |
| 845 | 833 | .@"switch", |
| 846 | 834 | .switch_comma, |
| 847 | 835 | => { |
| 848 | | const switch_token = main_tokens[node]; |
| 849 | | const condition = datas[node].lhs; |
| 850 | | const extra = tree.extraData(datas[node].rhs, Ast.Node.SubRange); |
| 851 | | const cases = tree.extra_data[extra.start..extra.end]; |
| 852 | | const rparen = tree.lastToken(condition) + 1; |
| 836 | const full = tree.switchFull(node); |
| 853 | 837 | |
| 854 | | try renderToken(r, switch_token, .space); // switch keyword |
| 855 | | try renderToken(r, switch_token + 1, .none); // lparen |
| 856 | | try renderExpression(r, condition, .none); // condition expression |
| 857 | | try renderToken(r, rparen, .space); // rparen |
| 838 | if (full.label_token) |label_token| { |
| 839 | try renderIdentifier(r, label_token, .none, .eagerly_unquote); // label |
| 840 | try renderToken(r, label_token + 1, .space); // : |
| 841 | } |
| 842 | |
| 843 | const rparen = tree.lastToken(full.ast.condition) + 1; |
| 844 | |
| 845 | try renderToken(r, full.ast.switch_token, .space); // switch |
| 846 | try renderToken(r, full.ast.switch_token + 1, .none); // ( |
| 847 | try renderExpression(r, full.ast.condition, .none); // condition expression |
| 848 | try renderToken(r, rparen, .space); // ) |
| 858 | 849 | |
| 859 | 850 | ais.pushIndentNextLine(); |
| 860 | | if (cases.len == 0) { |
| 861 | | try renderToken(r, rparen + 1, .none); // lbrace |
| 851 | if (full.ast.cases.len == 0) { |
| 852 | try renderToken(r, rparen + 1, .none); // { |
| 862 | 853 | } else { |
| 863 | | try renderToken(r, rparen + 1, .newline); // lbrace |
| 864 | | try renderExpressions(r, cases, .comma); |
| 854 | try renderToken(r, rparen + 1, .newline); // { |
| 855 | try renderExpressions(r, full.ast.cases, .comma); |
| 865 | 856 | } |
| 866 | 857 | ais.popIndent(); |
| 867 | | return renderToken(r, tree.lastToken(node), space); // rbrace |
| 858 | return renderToken(r, tree.lastToken(node), space); // } |
| 868 | 859 | }, |
| 869 | 860 | |
| 870 | 861 | .switch_case_one, |