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

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

Issue 1524843002: JS: Format if statements with no else on a single line (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Cleanup Created 5 years 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/runtime/dart/typed_data.js ('k') | no next file » | 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 155ce854febd115c28cde134099c0378b465deba..a7de5939c2da7fc95d32c1ca83c6560ff7596e26 100644
--- a/lib/src/js/printer.dart
+++ b/lib/src/js/printer.dart
@@ -181,7 +181,16 @@ class Printer implements NodeVisitor {
void outIndent(String str) { indent(); out(str); }
void outIndentLn(String str) { indent(); outLn(str); }
+
+ bool _skipNextIndent = false;
Jennifer Messerly 2015/12/15 23:57:10 style nit: it looks like they're keeping all field
ochafik 2015/12/16 02:00:37 Done.
+ void skipNextIndent() {
+ _skipNextIndent = true;
+ }
void indent() {
+ if (_skipNextIndent) {
+ _skipNextIndent = false;
+ return;
+ }
if (!shouldCompressOutput) {
out(indentation);
}
@@ -299,8 +308,15 @@ class Printer implements NodeVisitor {
visitNestedExpression(node.condition, EXPRESSION,
newInForInit: false, newAtStatementBegin: false);
out(")");
- bool thenWasBlock =
- blockBody(then, needsSeparation: false, needsNewline: !hasElse);
+ bool thenWasBlock;
Jennifer Messerly 2015/12/15 23:57:10 nice readability improvement. Would it be possibl
ochafik 2015/12/16 02:00:37 Done (didn't realize the contamination potential :
+ if (!hasElse && then is! Block) {
+ thenWasBlock = false;
+ if (!shouldCompressOutput) spaceOut();
Jennifer Messerly 2015/12/15 23:57:10 spaceOut() already does the shouldCompressOutput,
ochafik 2015/12/16 02:00:37 D'oh!
+ skipNextIndent();
+ visit(then);
+ } else {
+ thenWasBlock = blockBody(then, needsSeparation: false, needsNewline: !hasElse);
Jennifer Messerly 2015/12/15 23:57:10 long line
ochafik 2015/12/16 02:00:37 Done.
+ }
if (hasElse) {
if (thenWasBlock) {
spaceOut();
« no previous file with comments | « lib/runtime/dart/typed_data.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698