Format throw and rethrow. (#1347)
* Format throw and rethrow.
* Space() instead.
* Added another throw test.
diff --git a/lib/src/front_end/ast_node_visitor.dart b/lib/src/front_end/ast_node_visitor.dart
index 201ba08..a645403 100644
--- a/lib/src/front_end/ast_node_visitor.dart
+++ b/lib/src/front_end/ast_node_visitor.dart
@@ -1497,7 +1497,7 @@
@override
Piece visitRethrowExpression(RethrowExpression node) {
- throw UnimplementedError();
+ return tokenPiece(node.rethrowKeyword);
}
@override
@@ -1712,7 +1712,11 @@
@override
Piece visitThrowExpression(ThrowExpression node) {
- throw UnimplementedError();
+ return buildPiece((b) {
+ b.token(node.throwKeyword);
+ b.space();
+ b.visit(node.expression);
+ });
}
@override
diff --git a/test/statement/other.stmt b/test/statement/other.stmt
index 7e44161..55d7fd2 100644
--- a/test/statement/other.stmt
+++ b/test/statement/other.stmt
@@ -55,3 +55,29 @@
foo() async {
await i(1 + 2);
}
+>>> Throw.
+throw 'error'
+;
+<<<
+throw 'error';
+>>> Throw doesn't split after the 'throw' keyword.
+throw 'Some extremely long error message.';
+<<<
+throw 'Some extremely long error message.';
+>>> Throw with long string literal.
+throw new FormatException('This is a long exception message.');
+<<<
+throw new FormatException(
+ 'This is a long exception message.',
+);
+>>> Rethrow.
+try {
+ throw 1 ;
+} catch (e) {
+ rethrow ;}
+<<<
+try {
+ throw 1;
+} catch (e) {
+ rethrow;
+}