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

Unified Diff: lib/compiler/implementation/tree/unparser.dart

Issue 10894011: Do not emit some unnecessary whitespaces in unparser. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 4 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
Index: lib/compiler/implementation/tree/unparser.dart
diff --git a/lib/compiler/implementation/tree/unparser.dart b/lib/compiler/implementation/tree/unparser.dart
index 3e35c289b6f917e498b31e83cd6ae32a150e8dde..e0b3306abc8c3d3ca4a2686f5d9d76e7f3879319 100644
--- a/lib/compiler/implementation/tree/unparser.dart
+++ b/lib/compiler/implementation/tree/unparser.dart
@@ -168,7 +168,8 @@ class Unparser implements Visitor {
visit(node.condition);
visit(node.thenPart);
if (node.hasElsePart) {
- addToken(node.elseToken);
+ add(node.elseToken.value);
+ if (node.elsePart is !Block) sb.add(' ');
ahe 2012/08/30 10:42:45 This could probably be generalized if we didn't us
visit(node.elsePart);
}
}
@@ -209,7 +210,7 @@ class Unparser implements Visitor {
}
visitLiteralList(LiteralList node) {
- addToken(node.constKeyword);
+ if (node.constKeyword !== null) add(node.constKeyword.value);
visit(node.typeArguments);
visit(node.elements);
}
@@ -221,7 +222,7 @@ class Unparser implements Visitor {
*/
unparseNodeListFrom(NodeList node, Link<Node> from) {
if (from.isEmpty()) return;
- String delimiter = (node.delimiter === null) ? " " : "${node.delimiter}";
+ String delimiter = (node.delimiter === null) ? "" : "${node.delimiter}";
visit(from.head);
for (Link link = from.tail; !link.isEmpty(); link = link.tail) {
sb.add(delimiter);
@@ -230,7 +231,7 @@ class Unparser implements Visitor {
}
visitNodeList(NodeList node) {
- if (node.beginToken !== null) addToken(node.beginToken);
+ addToken(node.beginToken);
if (node.nodes !== null) {
unparseNodeListFrom(node, node.nodes);
}
@@ -243,10 +244,10 @@ class Unparser implements Visitor {
visitReturn(Return node) {
add(node.beginToken.value);
- if (node.hasExpression) {
+ if (node.hasExpression && node.getBeginToken().slowToString() != '=>') {
ahe 2012/08/30 10:42:45 Please do not use slowToString. That's why it has
Roman 2012/08/30 11:38:48 In the last patch I changed this to: node.beginTok
ahe 2012/08/30 11:51:07 Please don't use the _TOKEN variables. You really
Roman 2012/08/30 11:54:56 Changed to: node.beginToken.stringValue != '=>'
sb.add(' ');
- visit(node.expression);
}
+ visit(node.expression);
ahe 2012/08/30 10:42:45 Is this change intentional?
Roman 2012/08/30 11:38:48 Yes. visit() checks for null anyway and I didn't w
ahe 2012/08/30 11:51:07 Of course. I wasn't thinking.
if (node.endToken !== null) add(node.endToken.value);
}
@@ -339,10 +340,10 @@ class Unparser implements Visitor {
}
visitDoWhile(DoWhile node) {
- addToken(node.doKeyword);
+ add(node.doKeyword.value);
+ if (node.body is !Block) sb.add(' ');
visit(node.body);
- sb.add(' ');
- addToken(node.whileKeyword);
+ add(node.whileKeyword.value);
visit(node.condition);
sb.add(node.endToken.value);
}
@@ -350,7 +351,6 @@ class Unparser implements Visitor {
visitWhile(While node) {
addToken(node.whileKeyword);
visit(node.condition);
- sb.add(' ');
visit(node.body);
}
@@ -395,12 +395,12 @@ class Unparser implements Visitor {
visitForIn(ForIn node) {
add(node.forToken.value);
- sb.add(' (');
+ sb.add('(');
visit(node.declaredIdentifier);
sb.add(' ');
addToken(node.inToken);
visit(node.expression);
- sb.add(') ');
+ sb.add(')');
visit(node.body);
}
@@ -415,9 +415,7 @@ class Unparser implements Visitor {
}
visitLiteralMap(LiteralMap node) {
- if (node.constKeyword !== null) {
- add(node.constKeyword.value);
- }
+ if (node.constKeyword !== null) add(node.constKeyword.value);
if (node.typeArguments !== null) visit(node.typeArguments);
visit(node.entries);
}
@@ -425,21 +423,18 @@ class Unparser implements Visitor {
visitLiteralMapEntry(LiteralMapEntry node) {
visit(node.key);
add(node.colonToken.value);
- sb.add(' ');
visit(node.value);
}
visitNamedArgument(NamedArgument node) {
visit(node.name);
add(node.colonToken.value);
- sb.add(' ');
visit(node.expression);
}
visitSwitchStatement(SwitchStatement node) {
addToken(node.switchKeyword);
visit(node.parenthesizedExpression);
- sb.add(' ');
visit(node.cases);
}
@@ -458,7 +453,7 @@ class Unparser implements Visitor {
visit(node.argument);
if (node.prefixIdentifier !== null) {
visit(node.prefixIdentifier);
- sb.add(': ');
+ sb.add(':');
visit(node.prefix);
}
sb.add(')');
@@ -466,11 +461,10 @@ class Unparser implements Visitor {
}
visitTryStatement(TryStatement node) {
- addToken(node.tryKeyword);
+ add(node.tryKeyword.value);
visit(node.tryBlock);
visit(node.catchBlocks);
if (node.finallyKeyword !== null) {
- sb.add(' ');
addToken(node.finallyKeyword);
visit(node.finallyBlock);
}
@@ -485,11 +479,12 @@ class Unparser implements Visitor {
visitCatchBlock(CatchBlock node) {
addToken(node.onKeyword);
- visit(node.type);
- sb.add(' ');
- addToken(node.catchKeyword);
+ if (node.type !== null) {
+ visit(node.type);
+ sb.add(' ');
+ }
+ add(node.catchKeyword.value);
visit(node.formals);
- sb.add(' ');
visit(node.block);
}

Powered by Google App Engine
This is Rietveld 408576698