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

Unified Diff: sdk/lib/_internal/compiler/implementation/js/printer.dart

Issue 11602016: Emit classes using ASTs (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 12 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: sdk/lib/_internal/compiler/implementation/js/printer.dart
diff --git a/sdk/lib/_internal/compiler/implementation/js/printer.dart b/sdk/lib/_internal/compiler/implementation/js/printer.dart
index 048dc71a00d20065768637dcd62e8c6dc5638a64..14e286f278bcf28868e55fbbe38d55a18b3f3b03 100644
--- a/sdk/lib/_internal/compiler/implementation/js/printer.dart
+++ b/sdk/lib/_internal/compiler/implementation/js/printer.dart
@@ -31,11 +31,15 @@ class Printer implements NodeVisitor {
? new MinifyRenamer() : new IdentityNamer();
}
+ void newLine() {
floitsch 2013/01/04 10:31:03 do we really need this? If yes, please add comment
sra1 2013/01/04 23:47:52 Done.
+ out("\n");
+ }
+
void spaceOut() {
if (!shouldCompressOutput) out(" ");
}
void lineOut() {
- if (!shouldCompressOutput) out("\n");
+ if (!shouldCompressOutput) newLine();
}
String lastAddedString = null;
@@ -70,7 +74,8 @@ class Printer implements NodeVisitor {
if (shouldCompressOutput) {
pendingSemicolon = true;
} else {
- out(";\n");
+ out(";");
+ newLine();
}
}
@@ -672,8 +677,10 @@ class Printer implements NodeVisitor {
return false;
}
}
- // TODO(floitsch): normally we should also check that the field is not
- // a reserved word.
+ // TODO(floitsch): normally we should also check that the field is not a
+ // reserved word. We don't generate fields with reserved word names except
+ // for 'super'.
+ if (field == '"super"') return false;
return true;
}
@@ -758,15 +765,28 @@ class Printer implements NodeVisitor {
}
visitObjectInitializer(ObjectInitializer node) {
- out("{");
+ // Print all the properties on one line until we see a function-valued
+ // property. Ideally, we would use a proper pretty-printer to make the
+ // decision based on layout.
+ bool onePerLine = false;
List<Property> properties = node.properties;
+ out("{");
+ ++indentLevel;
for (int i = 0; i < properties.length; i++) {
+ Expression value = properties[i].value;
+ if (value is Fun || value is NamedFunction) onePerLine = true;
if (i != 0) {
out(",");
- spaceOut();
+ if (!onePerLine) spaceOut();
+ }
+ if (onePerLine) {
+ newLine();
floitsch 2013/01/04 10:31:03 why "newLine" and not "lineOut" ?
sra1 2013/01/04 23:47:52 To force newlines even under --minify. We can play
floitsch 2013/01/04 23:58:20 Fine with me, but I wouldn't consider readability
+ indent();
}
visitProperty(properties[i]);
}
+ --indentLevel;
+ if (onePerLine) lineOut();
out("}");
}

Powered by Google App Engine
This is Rietveld 408576698