File tree Expand file tree Collapse file tree 2 files changed +16
-3
lines changed
test/tall/preserve_trailing_commas Expand file tree Collapse file tree 2 files changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -626,14 +626,26 @@ final class AstNodeVisitor extends ThrowingAstVisitor<void> with PieceFactory {
626
626
builder.leftBracket (node.leftBracket);
627
627
628
628
for (var constant in node.constants) {
629
+ var isLast = constant == node.constants.last;
630
+ var treatAsLast = isLast;
631
+ if (isLast && formatter.trailingCommas == TrailingCommas .preserve) {
632
+ treatAsLast = constant.commaAfter == null ;
633
+ }
629
634
builder.addCommentsBefore (constant.firstNonCommentToken);
630
635
builder.add (
631
636
createEnumConstant (
632
637
constant,
633
- isLastConstant: constant == node.constants.last ,
638
+ isLastConstant: treatAsLast ,
634
639
semicolon: node.semicolon,
635
640
),
636
641
);
642
+ // If this the last constant and wasn't treated as last, we need
643
+ // to append the ending semicolon.
644
+ if (isLast && ! treatAsLast) {
645
+ if (node.semicolon case var token? ) {
646
+ builder.add (tokenPiece (token));
647
+ }
648
+ }
637
649
}
638
650
639
651
// Insert a blank line between the constants and members.
Original file line number Diff line number Diff line change @@ -25,13 +25,14 @@ enum E {e,;}
25
25
enum E {
26
26
e,
27
27
}
28
- >>> Remove trailing comma and split if there are members.
28
+ >>> Preserve trailing comma and split if there are members.
29
29
enum E { a, b, c,; int x; }
30
30
<<<
31
31
enum E {
32
32
a,
33
33
b,
34
- c;
34
+ c,
35
+ ;
35
36
36
37
int x;
37
38
}
You can’t perform that action at this time.
0 commit comments