Skip to content

Commit 1ad10d2

Browse files
authored
Format if case for if statements. (#1353)
* Format if case. * Rebase and fix differences. * Move if case test and remove patterns folder for now.
1 parent b3b4321 commit 1ad10d2

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

lib/src/front_end/ast_node_visitor.dart

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,18 @@ class AstNodeVisitor extends ThrowingAstVisitor<Piece> with PieceFactory {
219219
throw UnimplementedError();
220220
}
221221

222+
@override
223+
Piece visitCaseClause(CaseClause node) {
224+
return buildPiece((b) {
225+
b.token(node.caseKeyword);
226+
if (node.guardedPattern.whenClause != null) {
227+
throw UnimplementedError();
228+
}
229+
b.space();
230+
b.visit(node.guardedPattern.pattern);
231+
});
232+
}
233+
222234
@override
223235
Piece visitCastPattern(CastPattern node) {
224236
throw UnimplementedError();
@@ -1022,11 +1034,14 @@ class AstNodeVisitor extends ThrowingAstVisitor<Piece> with PieceFactory {
10221034
void traverse(Token? precedingElse, IfStatement ifStatement) {
10231035
var condition = buildPiece((b) {
10241036
b.token(precedingElse, spaceAfter: true);
1025-
b.add(startControlFlow(
1026-
ifStatement.ifKeyword,
1027-
ifStatement.leftParenthesis,
1028-
ifStatement.expression,
1029-
ifStatement.rightParenthesis));
1037+
b.token(ifStatement.ifKeyword);
1038+
b.space();
1039+
b.token(ifStatement.leftParenthesis);
1040+
b.add(buildPiece((b) {
1041+
b.visit(ifStatement.expression);
1042+
b.visit(ifStatement.caseClause, spaceBefore: true);
1043+
}));
1044+
b.token(ifStatement.rightParenthesis);
10301045
b.space();
10311046
});
10321047

test/statement/if_case.stmt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
40 columns |
2+
>>> Simple bool pattern.
3+
if (obj case true) {;}
4+
<<<
5+
if (obj case true) {
6+
;
7+
}

0 commit comments

Comments
 (0)