Skip to content

Commit e860fda

Browse files
authored
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.
1 parent a72fbfc commit e860fda

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

lib/src/front_end/ast_node_visitor.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1335,7 +1335,11 @@ class AstNodeVisitor extends ThrowingAstVisitor<void>
13351335

13361336
@override
13371337
void visitYieldStatement(YieldStatement node) {
1338-
throw UnimplementedError();
1338+
token(node.yieldKeyword);
1339+
token(node.star);
1340+
space();
1341+
visit(node.expression);
1342+
token(node.semicolon);
13391343
}
13401344

13411345
/// If [node] is not `null`, then visit it.

test/statement/other.stmt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,20 @@ while (true) {
3030
<<<
3131
while (true) {
3232
continue someLabel;
33-
}
33+
}
34+
>>> Yield.
35+
Stream<String> i(String n) async* {
36+
yield i ;
37+
}
38+
<<<
39+
Stream<String> i(String n) async* {
40+
yield i;
41+
}
42+
>>> Yield*.
43+
Stream<int> i(int n) async* {
44+
yield * i ( n - 1 ) ;
45+
}
46+
<<<
47+
Stream<int> i(int n) async* {
48+
yield* i(n - 1);
49+
}

test/statement/other_comment.stmt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,19 @@ while (true) {
3535
while (true) {
3636
break; // comment
3737
}
38+
>>> Yield with comment after semicolon.
39+
Stream<String> i(String n) async* {
40+
yield i ; // comment
41+
}
42+
<<<
43+
Stream<String> i(String n) async* {
44+
yield i; // comment
45+
}
46+
>>> Yield* with comment after semicolon.
47+
Stream<int> i(int n) async* {
48+
yield * i( x ) ; // comment
49+
}
50+
<<<
51+
Stream<int> i(int n) async* {
52+
yield* i(x); // comment
53+
}

0 commit comments

Comments
 (0)