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 {
648648 builder.leftBracket (node.leftBracket);
649649
650650 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+ }
651656 builder.addCommentsBefore (constant.firstNonCommentToken);
652657 builder.add (
653658 createEnumConstant (
654659 constant,
655- isLastConstant: constant == node.constants.last ,
660+ isLastConstant: treatAsLast ,
656661 semicolon: node.semicolon,
657662 ),
658663 );
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+ }
659671 }
660672
661673 // 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,;}
2525enum E {
2626 e,
2727}
28- >>> Remove trailing comma and split if there are members.
28+ >>> Preserve trailing comma and split if there are members.
2929enum E { a, b, c,; int x; }
3030<<<
3131enum E {
3232 a,
3333 b,
34- c;
34+ c,
35+ ;
3536
3637 int x;
3738}
You can’t perform that action at this time.
0 commit comments