Skip to content

Commit f5153b2

Browse files
authored
Format throw and rethrow. (#1347)
* Format throw and rethrow. * Space() instead. * Added another throw test.
1 parent 885f1ec commit f5153b2

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

lib/src/front_end/ast_node_visitor.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1497,7 +1497,7 @@ class AstNodeVisitor extends ThrowingAstVisitor<Piece> with PieceFactory {
14971497

14981498
@override
14991499
Piece visitRethrowExpression(RethrowExpression node) {
1500-
throw UnimplementedError();
1500+
return tokenPiece(node.rethrowKeyword);
15011501
}
15021502

15031503
@override
@@ -1712,7 +1712,11 @@ class AstNodeVisitor extends ThrowingAstVisitor<Piece> with PieceFactory {
17121712

17131713
@override
17141714
Piece visitThrowExpression(ThrowExpression node) {
1715-
throw UnimplementedError();
1715+
return buildPiece((b) {
1716+
b.token(node.throwKeyword);
1717+
b.space();
1718+
b.visit(node.expression);
1719+
});
17161720
}
17171721

17181722
@override

test/statement/other.stmt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,29 @@ foo() async {
5555
foo() async {
5656
await i(1 + 2);
5757
}
58+
>>> Throw.
59+
throw 'error'
60+
;
61+
<<<
62+
throw 'error';
63+
>>> Throw doesn't split after the 'throw' keyword.
64+
throw 'Some extremely long error message.';
65+
<<<
66+
throw 'Some extremely long error message.';
67+
>>> Throw with long string literal.
68+
throw new FormatException('This is a long exception message.');
69+
<<<
70+
throw new FormatException(
71+
'This is a long exception message.',
72+
);
73+
>>> Rethrow.
74+
try {
75+
throw 1 ;
76+
} catch (e) {
77+
rethrow ;}
78+
<<<
79+
try {
80+
throw 1;
81+
} catch (e) {
82+
rethrow;
83+
}

0 commit comments

Comments
 (0)