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

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

Issue 858573002: Implement await and async for the js-ast. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: address review comments Created 5 years, 11 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 | « pkg/compiler/lib/src/js/builder.dart ('k') | pkg/compiler/lib/src/js/printer.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/js/nodes.dart
diff --git a/pkg/compiler/lib/src/js/nodes.dart b/pkg/compiler/lib/src/js/nodes.dart
index d5c574e92a21c7e21f6e2038d1817a455f93d399..e5b57f6351593fa734602e297c1558ad28d9ecd0 100644
--- a/pkg/compiler/lib/src/js/nodes.dart
+++ b/pkg/compiler/lib/src/js/nodes.dart
@@ -60,6 +60,8 @@ abstract class NodeVisitor<T> {
T visitProperty(Property node);
T visitRegExpLiteral(RegExpLiteral node);
+ T visitAwait(Await node);
+
T visitComment(Comment node);
T visitInterpolatedExpression(InterpolatedExpression node);
@@ -165,6 +167,8 @@ class BaseVisitor<T> implements NodeVisitor<T> {
// Ignore comments by default.
T visitComment(Comment node) => null;
+
+ T visitAwait(Await node) => visitExpression(node);
}
abstract class Node {
@@ -847,8 +851,9 @@ class NamedFunction extends Expression {
class Fun extends Expression {
final List<Parameter> params;
final Block body;
+ final AsyncModifier asyncModifier;
- Fun(this.params, this.body);
+ Fun(this.params, this.body, {this.asyncModifier: const AsyncModifier.sync()});
accept(NodeVisitor visitor) => visitor.visitFun(this);
@@ -862,6 +867,16 @@ class Fun extends Expression {
int get precedenceLevel => CALL;
}
+class AsyncModifier {
+ final bool isAsync;
+ final bool isYielding;
+
+ const AsyncModifier.sync() : isAsync = false, isYielding = false;
+ const AsyncModifier.async() : isAsync = true, isYielding = false;
+ const AsyncModifier.asyncStar() : isAsync = true, isYielding = true;
+ const AsyncModifier.syncStar() : isAsync = false, isYielding = true;
+}
+
class PropertyAccess extends Expression {
final Expression receiver;
final Expression selector;
@@ -1091,6 +1106,25 @@ class RegExpLiteral extends Expression {
}
/**
+ * An asynchronous await.
+ *
+ * Not part of javascript. We desugar this expression before outputting.
+ * Should only occur in a [Fun] with `asyncModifier` async or asyncStar.
+ */
+class Await extends Expression {
+ /** The awaited expression. */
+ final Expression expression;
+
+ Await(this.expression);
+
+ int get precedenceLevel => UNARY;
+ accept(NodeVisitor visitor) => visitor.visitAwait(this);
+ void visitChildren(NodeVisitor visitor) => expression.accept(visitor);
+ Await _clone() => new Await(expression);
+
+}
+
+/**
* A comment.
*
* Extends [Statement] so we can add comments before statements in
« no previous file with comments | « pkg/compiler/lib/src/js/builder.dart ('k') | pkg/compiler/lib/src/js/printer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698