Skip to content

Commit

Permalink
Clean up visitor and also handle long names with no types.
Browse files Browse the repository at this point in the history
  • Loading branch information
kallentu committed Jan 17, 2024
1 parent 9b209cf commit 67e7eae
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
13 changes: 1 addition & 12 deletions lib/src/front_end/ast_node_visitor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -452,25 +452,14 @@ class AstNodeVisitor extends ThrowingAstVisitor<Piece> with PieceFactory {

@override
Piece visitDeclaredVariablePattern(DeclaredVariablePattern node) {
// We don't need any splitting behavior if we don't have a type.
if (node.keyword != null && node.type == null) {
return buildPiece((b) {
b.modifier(node.keyword);
b.visit(node.type, spaceAfter: true);
b.token(node.name);
});
}

// Build a [VariablePiece] that can split between the type and the variable
// name.
var header = buildPiece((b) {
b.modifier(node.keyword);
b.visit(node.type);
});
return VariablePiece(
header,
[tokenPiece(node.name)],
hasType: true,
hasType: node.type != null,
);
}

Expand Down
11 changes: 11 additions & 0 deletions test/pattern/declared_variable_comment.stmt
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,14 @@ if (obj
x) {
;
}
>>> Line comment after type, before long name.
if (obj
case final // c
thisIsReallyQuiteAVeryLongVariableName) {
;
}
<<<
if (obj case final // c
thisIsReallyQuiteAVeryLongVariableName) {
;
}

0 comments on commit 67e7eae

Please sign in to comment.