Format yield and yield*. (#1312)
* Format yield and yield*.
* Fix yield tests and then yield itself.
Turns out the one liner yield statement doesn't parse as a yield and
instead parses it as a variable declaration (with yield being the type).
Change tests to be properly parsing yield statements and then fixed up
the behaviour for it.
diff --git a/lib/src/front_end/ast_node_visitor.dart b/lib/src/front_end/ast_node_visitor.dart
index ea56cda..6fd93ce 100644
--- a/lib/src/front_end/ast_node_visitor.dart
+++ b/lib/src/front_end/ast_node_visitor.dart
@@ -1335,7 +1335,11 @@
@override
void visitYieldStatement(YieldStatement node) {
- throw UnimplementedError();
+ token(node.yieldKeyword);
+ token(node.star);
+ space();
+ visit(node.expression);
+ token(node.semicolon);
}
/// If [node] is not `null`, then visit it.
diff --git a/test/statement/other.stmt b/test/statement/other.stmt
index 1012d30..8974abb 100644
--- a/test/statement/other.stmt
+++ b/test/statement/other.stmt
@@ -30,4 +30,20 @@
<<<
while (true) {
continue someLabel;
-}
\ No newline at end of file
+}
+>>> Yield.
+Stream<String> i(String n) async* {
+ yield i ;
+}
+<<<
+Stream<String> i(String n) async* {
+ yield i;
+}
+>>> Yield*.
+Stream<int> i(int n) async* {
+ yield * i ( n - 1 ) ;
+}
+<<<
+Stream<int> i(int n) async* {
+ yield* i(n - 1);
+}
diff --git a/test/statement/other_comment.stmt b/test/statement/other_comment.stmt
index 0bfa982..2ef8ffd 100644
--- a/test/statement/other_comment.stmt
+++ b/test/statement/other_comment.stmt
@@ -35,3 +35,19 @@
while (true) {
break; // comment
}
+>>> Yield with comment after semicolon.
+Stream<String> i(String n) async* {
+ yield i ; // comment
+}
+<<<
+Stream<String> i(String n) async* {
+ yield i; // comment
+}
+>>> Yield* with comment after semicolon.
+Stream<int> i(int n) async* {
+ yield * i( x ) ; // comment
+}
+<<<
+Stream<int> i(int n) async* {
+ yield* i(x); // comment
+}