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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « lib/runtime/dart/typed_data.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of js_ast; 5 part of js_ast;
6 6
7 7
8 class JavaScriptPrintingOptions { 8 class JavaScriptPrintingOptions {
9 final bool shouldCompressOutput; 9 final bool shouldCompressOutput;
10 final bool minifyLocalVariables; 10 final bool minifyLocalVariables;
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 if (shouldCompressOutput) { 174 if (shouldCompressOutput) {
175 pendingSemicolon = true; 175 pendingSemicolon = true;
176 } else { 176 } else {
177 out(";"); 177 out(";");
178 forceLine(); 178 forceLine();
179 } 179 }
180 } 180 }
181 181
182 void outIndent(String str) { indent(); out(str); } 182 void outIndent(String str) { indent(); out(str); }
183 void outIndentLn(String str) { indent(); outLn(str); } 183 void outIndentLn(String str) { indent(); outLn(str); }
184
185 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.
186 void skipNextIndent() {
187 _skipNextIndent = true;
188 }
184 void indent() { 189 void indent() {
190 if (_skipNextIndent) {
191 _skipNextIndent = false;
192 return;
193 }
185 if (!shouldCompressOutput) { 194 if (!shouldCompressOutput) {
186 out(indentation); 195 out(indentation);
187 } 196 }
188 } 197 }
189 198
190 visit(Node node) { 199 visit(Node node) {
191 context.enterNode(node); 200 context.enterNode(node);
192 node.accept(this); 201 node.accept(this);
193 context.exitNode(node); 202 context.exitNode(node);
194 } 203 }
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 then = new Block(<Statement>[then]); 301 then = new Block(<Statement>[then]);
293 } 302 }
294 } 303 }
295 if (shouldIndent) indent(); 304 if (shouldIndent) indent();
296 out("if"); 305 out("if");
297 spaceOut(); 306 spaceOut();
298 out("("); 307 out("(");
299 visitNestedExpression(node.condition, EXPRESSION, 308 visitNestedExpression(node.condition, EXPRESSION,
300 newInForInit: false, newAtStatementBegin: false); 309 newInForInit: false, newAtStatementBegin: false);
301 out(")"); 310 out(")");
302 bool thenWasBlock = 311 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 :
303 blockBody(then, needsSeparation: false, needsNewline: !hasElse); 312 if (!hasElse && then is! Block) {
313 thenWasBlock = false;
314 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!
315 skipNextIndent();
316 visit(then);
317 } else {
318 thenWasBlock = blockBody(then, needsSeparation: false, needsNewline: !hasE lse);
Jennifer Messerly 2015/12/15 23:57:10 long line
ochafik 2015/12/16 02:00:37 Done.
319 }
304 if (hasElse) { 320 if (hasElse) {
305 if (thenWasBlock) { 321 if (thenWasBlock) {
306 spaceOut(); 322 spaceOut();
307 } else { 323 } else {
308 indent(); 324 indent();
309 } 325 }
310 out("else"); 326 out("else");
311 if (elsePart is If) { 327 if (elsePart is If) {
312 pendingSpace = true; 328 pendingSpace = true;
313 ifOut(elsePart, false); 329 ifOut(elsePart, false);
(...skipping 1294 matching lines...) Expand 10 before | Expand all | Expand 10 after
1608 declare(node.name); 1624 declare(node.name);
1609 node.function.accept(this); 1625 node.function.accept(this);
1610 } 1626 }
1611 1627
1612 visitClassExpression(ClassExpression node) { 1628 visitClassExpression(ClassExpression node) {
1613 declare(node.name); 1629 declare(node.name);
1614 if (node.heritage != null) node.heritage.accept(this); 1630 if (node.heritage != null) node.heritage.accept(this);
1615 for (Method element in node.methods) element.accept(this); 1631 for (Method element in node.methods) element.accept(this);
1616 } 1632 }
1617 } 1633 }
OLDNEW
« 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