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 @@ -648,14 +648,26 @@ final class AstNodeVisitor extends ThrowingAstVisitor<void> with PieceFactory {
648
648
builder.leftBracket (node.leftBracket);
649
649
650
650
for (var constant in node.constants) {
651
+ var isLast = constant == node.constants.last;
652
+ var treatAsLast = isLast;
653
+ if (isLast && formatter.trailingCommas == TrailingCommas .preserve) {
654
+ treatAsLast = constant.commaAfter == null ;
655
+ }
651
656
builder.addCommentsBefore (constant.firstNonCommentToken);
652
657
builder.add (
653
658
createEnumConstant (
654
659
constant,
655
- isLastConstant: constant == node.constants.last ,
660
+ isLastConstant: treatAsLast ,
656
661
semicolon: node.semicolon,
657
662
),
658
663
);
664
+ // If this the last constant and wasn't treated as last, we need
665
+ // to append the ending semicolon.
666
+ if (isLast && ! treatAsLast) {
667
+ if (node.semicolon case var token? ) {
668
+ builder.add (tokenPiece (token));
669
+ }
670
+ }
659
671
}
660
672
661
673
// 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