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

Unified Diff: lib/src/js/printer.dart

Issue 1138793002: Tag closures with their types (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Address jmesserly's comments Created 5 years, 7 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/src/js/printer.dart
diff --git a/lib/src/js/printer.dart b/lib/src/js/printer.dart
index f95a64d976700c0dd8e53d18230015aaf9fb1781..fbb12ce852e939534d719b527bca44d834c3d758 100644
--- a/lib/src/js/printer.dart
+++ b/lib/src/js/printer.dart
@@ -861,8 +861,14 @@ class Printer implements NodeVisitor {
out("=>");
if (fun.body is Expression) {
spaceOut();
+ // Object initializers require parenthesis to disambiguate
+ // AssignmentExpression from FunctionBody. See:
+ // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-arrow-function-defi...
Jennifer Messerly 2015/05/19 22:49:48 `sec-arrow-function-definitions` seems to have got
Leaf 2015/05/19 23:24:07 Done.
+ var needsParen = fun.body is ObjectInitializer;
+ if (needsParen) out("(");
visitNestedExpression(fun.body, ASSIGNMENT,
newInForInit: false, newAtStatementBegin: false);
+ if (needsParen) out(")");
} else {
blockBody(fun.body, needsSeparation: false, needsNewline: false);
}
@@ -920,14 +926,11 @@ class Printer implements NodeVisitor {
}
visitObjectInitializer(ObjectInitializer node) {
- // 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.
List<Property> properties = node.properties;
out("{");
indentMore();
- var isOneLiner = !properties.any((p) => p.value is FunctionExpression);
+ var isOneLiner = !node.vertical;
for (int i = 0; i < properties.length; i++) {
if (i != 0) {
out(",");

Powered by Google App Engine
This is Rietveld 408576698