Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/src/ast_extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,19 @@ extension AstNodeExtensions on AstNode {
/// (if there is any), or the beginning of the code.
Token get firstNonCommentToken {
return switch (this) {
// If the node is annotated, skip past the doc comments, but not the
// metadata.
AnnotatedNode(metadata: [var annotation, ...]) => annotation.beginToken,
AnnotatedNode(firstTokenAfterCommentAndMetadata: var token) => token,

// DefaultFormalParameter is not an AnnotatedNode, but its first child
// (parameter) *is* an AnnotatedNode, so we can't just use beginToken.
DefaultFormalParameter(:var parameter) => parameter.firstNonCommentToken,

// A pattern variable statement isn't itself an AnnotatedNode, but the
// [PatternVariableDeclaration] that it wraps is.
PatternVariableDeclarationStatement(:var declaration) =>
declaration.firstNonCommentToken,
_ => beginToken
};
}
Expand Down
10 changes: 10 additions & 0 deletions test/tall/regression/1500/1586.unit
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
>>>
main() {
/// Doc comment.
final (a, b) = c;
}
<<<
main() {
/// Doc comment.
final (a, b) = c;
}