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

Unified Diff: pkg/compiler/lib/src/js/rewrite_async.dart

Issue 1916863002: dart2js: Avoid empty else clauses in generators. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 8 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/js/rewrite_async.dart
diff --git a/pkg/compiler/lib/src/js/rewrite_async.dart b/pkg/compiler/lib/src/js/rewrite_async.dart
index 2a9d8bff3080d0e70493a338fd830305793f5e34..1dcf30502b2adab28ffd540e84b03d04f92aad7a 100644
--- a/pkg/compiler/lib/src/js/rewrite_async.dart
+++ b/pkg/compiler/lib/src/js/rewrite_async.dart
@@ -1,4 +1,4 @@
-// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
+tra// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
sigurdm 2016/04/26 05:15:05 This looks like a mistake
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
@@ -967,7 +967,7 @@ abstract class AsyncRewriterBase extends js.NodeVisitor {
bool oldInsideUntranslatedBreakable = insideUntranslatedBreakable;
insideUntranslatedBreakable = true;
addStatement(js.js.statement('do {#} while (#)',
- [translateInBlock(node.body), visitExpression(node.condition)]));
+ [translateToStatement(node.body), visitExpression(node.condition)]));
insideUntranslatedBreakable = oldInsideUntranslatedBreakable;
return;
}
@@ -1013,7 +1013,7 @@ abstract class AsyncRewriterBase extends js.NodeVisitor {
withExpressions([node.init, node.condition, node.update],
(List<js.Expression> transformed) {
addStatement(new js.For(transformed[0], transformed[1], transformed[2],
- translateInBlock(node.body)));
+ translateToStatement(node.body)));
});
insideUntranslatedBreakable = oldInsideUntranslated;
return;
@@ -1064,13 +1064,15 @@ abstract class AsyncRewriterBase extends js.NodeVisitor {
}
// Only used for code where `!shouldTransform(node)`.
- js.Block translateInBlock(js.Statement node) {
+ js.Block translateToStatement(js.Statement node) {
sigurdm 2016/04/26 05:15:04 I think the return type should be `js.Statement` n
assert(!shouldTransform(node));
List<js.Statement> oldBuffer = currentStatementBuffer;
currentStatementBuffer = new List();
List<js.Statement> resultBuffer = currentStatementBuffer;
visitStatement(node);
currentStatementBuffer = oldBuffer;
+ if (resultBuffer.length == 1)
+ return resultBuffer.single;
sigurdm 2016/04/26 05:15:04 Either put the return on the same line as the if,
sigurdm 2016/04/26 05:15:05 For the case where `node` is an empty block (can t
return new js.Block(resultBuffer);
}
@@ -1078,8 +1080,9 @@ abstract class AsyncRewriterBase extends js.NodeVisitor {
void visitIf(js.If node) {
if (!shouldTransform(node.then) && !shouldTransform(node.otherwise)) {
withExpression(node.condition, (js.Expression condition) {
- addStatement(new js.If(condition, translateInBlock(node.then),
- translateInBlock(node.otherwise)));
+ js.Ast translatedThen = translateToStatement(node.then);
+ js.Ast translatedElse = translateToStatement(node.otherwise);
+ addStatement(new js.If(condition, translatedThen, translatedElse));
}, store: false);
return;
}
@@ -1137,7 +1140,7 @@ abstract class AsyncRewriterBase extends js.NodeVisitor {
void visitLabeledStatement(js.LabeledStatement node) {
if (!shouldTransform(node)) {
addStatement(
- new js.LabeledStatement(node.label, translateInBlock(node.body)));
+ new js.LabeledStatement(node.label, translateToStatement(node.body)));
return;
}
// `continue label` is really continuing the nested loop.
@@ -1302,9 +1305,9 @@ abstract class AsyncRewriterBase extends js.NodeVisitor {
List<js.SwitchClause> cases = node.cases.map((js.SwitchClause clause) {
if (clause is js.Case) {
return new js.Case(
- clause.expression, translateInBlock(clause.body));
+ clause.expression, translateToStatement(clause.body));
} else if (clause is js.Default) {
- return new js.Default(translateInBlock(clause.body));
+ return new js.Default(translateToStatement(clause.body));
}
}).toList();
addStatement(new js.Switch(key, cases));
@@ -1426,14 +1429,14 @@ abstract class AsyncRewriterBase extends js.NodeVisitor {
/// See the comments of [rewriteFunction] for more explanation.
void visitTry(js.Try node) {
if (!shouldTransform(node)) {
- js.Block body = translateInBlock(node.body);
+ js.Block body = translateToStatement(node.body);
sigurdm 2016/04/26 05:15:04 This would also become a `js.Statement`
js.Catch catchPart = (node.catchPart == null)
? null
: new js.Catch(node.catchPart.declaration,
- translateInBlock(node.catchPart.body));
+ translateToStatement(node.catchPart.body));
js.Block finallyPart = (node.finallyPart == null)
? null
- : translateInBlock(node.finallyPart);
+ : translateToStatement(node.finallyPart);
addStatement(new js.Try(body, catchPart, finallyPart));
return;
}
@@ -1576,7 +1579,7 @@ abstract class AsyncRewriterBase extends js.NodeVisitor {
bool oldInsideUntranslated = insideUntranslatedBreakable;
insideUntranslatedBreakable = true;
withExpression(node.condition, (js.Expression condition) {
- addStatement(new js.While(condition, translateInBlock(node.body)));
+ addStatement(new js.While(condition, translateToStatement(node.body)));
}, store: false);
insideUntranslatedBreakable = oldInsideUntranslated;
return;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698