Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(726)

Unified Diff: pkg/analyzer_experimental/lib/src/services/formatter_impl.dart

Issue 23451037: Optional trailing comma support for list and map literals. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/analyzer_experimental/test/services/formatter_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer_experimental/lib/src/services/formatter_impl.dart
===================================================================
--- pkg/analyzer_experimental/lib/src/services/formatter_impl.dart (revision 27343)
+++ pkg/analyzer_experimental/lib/src/services/formatter_impl.dart (working copy)
@@ -799,6 +799,7 @@
visit(node.typeArguments);
token(node.leftBracket);
visitNodes(node.elements, separatedBy: commaSeperator);
+ optionalTrailingComma(node.rightBracket);
token(node.rightBracket);
}
@@ -807,9 +808,10 @@
visitNode(node.typeArguments, followedBy: space);
token(node.leftBracket);
visitNodes(node.entries, separatedBy: commaSeperator);
+ optionalTrailingComma(node.rightBracket);
token(node.rightBracket);
}
-
+
visitMapLiteralEntry(MapLiteralEntry node) {
visit(node.key);
token(node.separator);
@@ -1153,13 +1155,19 @@
token(modifier, followedBy: space);
}
-
/// Indicate that at least one newline should be emitted and possibly more
/// if the source has them.
newlines() {
needsNewline = true;
}
+ /// Optionally emit a trailing comma.
+ optionalTrailingComma(Token rightBracket) {
+ if (rightBracket.previous.lexeme == ',') {
+ comma();
+ }
+ }
+
token(Token token, {precededBy(), followedBy(), int minNewlines: 0}) {
if (token != null) {
if (needsNewline) {
@@ -1169,7 +1177,7 @@
if (emitted > 0) {
needsNewline = false;
}
- if (precededBy !=null) {
+ if (precededBy != null) {
precededBy();
}
append(token.lexeme);
« no previous file with comments | « no previous file | pkg/analyzer_experimental/test/services/formatter_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698