@@ -420,7 +420,16 @@ mixin PieceFactory {
420420 // The update clauses.
421421 if (forParts.updaters.isNotEmpty) {
422422 partsList.addCommentsBefore (forParts.updaters.first.beginToken);
423- partsList.add (createCommaSeparated (forParts.updaters));
423+
424+ // Create a nested list builder for the updaters so that they can
425+ // remain unsplit even while the clauses split.
426+ var updaterBuilder = DelimitedListBuilder (
427+ this , const ListStyle (commas: Commas .nonTrailing));
428+ forParts.updaters.forEach (updaterBuilder.visit);
429+
430+ // Add the updater builder to the clause builder so that any comments
431+ // around a trailing comma after the updaters don't get dropped.
432+ partsList.addInnerBuilder (updaterBuilder);
424433 }
425434
426435 partsList.rightBracket (rightParenthesis);
@@ -1076,7 +1085,7 @@ mixin PieceFactory {
10761085 elements[i - 1 ].endToken, element.beginToken)) {
10771086 // This element begins a new line. Add the elements on the previous
10781087 // line to the list builder and start a new line.
1079- builder.addLineBuilder (lineBuilder);
1088+ builder.addInnerBuilder (lineBuilder);
10801089 lineBuilder = DelimitedListBuilder (this , lineStyle);
10811090 atLineStart = true ;
10821091 }
@@ -1092,7 +1101,7 @@ mixin PieceFactory {
10921101 }
10931102
10941103 // Finish the last line if there is anything on it.
1095- if (! atLineStart) builder.addLineBuilder (lineBuilder);
1104+ if (! atLineStart) builder.addInnerBuilder (lineBuilder);
10961105 }
10971106
10981107 /// Writes a [VariablePiece] for a named or wildcard variable pattern.
0 commit comments