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

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: More comment fixes 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
« no previous file with comments | « lib/src/js/nodes.dart ('k') | test/browser/runtime_tests.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/js/printer.dart
diff --git a/lib/src/js/printer.dart b/lib/src/js/printer.dart
index f95a64d976700c0dd8e53d18230015aaf9fb1781..0eb5ff8dd7f62f77a9eee5cf5a7fe56972413bc9 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-definitions
+ 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(",");
« no previous file with comments | « lib/src/js/nodes.dart ('k') | test/browser/runtime_tests.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698