@@ -430,7 +430,16 @@ mixin PieceFactory {
430430 // The update clauses.
431431 if (forParts.updaters.isNotEmpty) {
432432 partsList.addCommentsBefore (forParts.updaters.first.beginToken);
433- partsList.add (createCommaSeparated (forParts.updaters));
433+
434+ // Create a nested list builder for the updaters so that they can
435+ // remain unsplit even while the clauses split.
436+ var updaterBuilder = DelimitedListBuilder (
437+ this , const ListStyle (commas: Commas .nonTrailing));
438+ forParts.updaters.forEach (updaterBuilder.visit);
439+
440+ // Add the updater builder to the clause builder so that any comments
441+ // around a trailing comma after the updaters don't get dropped.
442+ partsList.addInnerBuilder (updaterBuilder);
434443 }
435444
436445 partsList.rightBracket (rightParenthesis);
@@ -1083,7 +1092,7 @@ mixin PieceFactory {
10831092 elements[i - 1 ].endToken, element.beginToken)) {
10841093 // This element begins a new line. Add the elements on the previous
10851094 // line to the list builder and start a new line.
1086- builder.addLineBuilder (lineBuilder);
1095+ builder.addInnerBuilder (lineBuilder);
10871096 lineBuilder = DelimitedListBuilder (this , lineStyle);
10881097 atLineStart = true ;
10891098 }
@@ -1099,7 +1108,7 @@ mixin PieceFactory {
10991108 }
11001109
11011110 // Finish the last line if there is anything on it.
1102- if (! atLineStart) builder.addLineBuilder (lineBuilder);
1111+ if (! atLineStart) builder.addInnerBuilder (lineBuilder);
11031112 }
11041113
11051114 /// Writes a [VariablePiece] for a named or wildcard variable pattern.
0 commit comments