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

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
« no previous file with comments | « lib/compiler/implementation/scanner/listener.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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(' ');
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}";
Anton Muhin 2012/08/30 10:24:16 shouldn't we provide explicit empty string delimit
Roman 2012/08/30 10:40:51 I think it's just a matter of agreement. I didn't
Anton Muhin 2012/08/30 12:01:53 In this case, please, adjust interpolation case.
+ 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() != '=>') {
Anton Muhin 2012/08/30 10:24:16 I don't like this difference between beginToken ab
Roman 2012/08/30 10:40:51 Changed to beginToken.value
sb.add(' ');
- visit(node.expression);
}
+ visit(node.expression);
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(' ');
Anton Muhin 2012/08/30 10:24:16 shouldn't this logic belong to Block unparsing?
Roman 2012/08/30 10:40:51 body may be any statement, not necessary a block.
Anton Muhin 2012/08/30 12:01:53 Ok. On 2012/08/30 10:40:51, Roman wrote:
Anton Muhin 2012/08/30 12:01:53 overall, instead of checking body type, shouldn't
Roman 2012/08/30 12:16:04 Well, ideally yes. But that would complicate thing
Anton Muhin 2012/08/30 12:22:00 Up to you to decide. BTW, it won't complicate thi
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);
}
« no previous file with comments | « lib/compiler/implementation/scanner/listener.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698