File tree Expand file tree Collapse file tree 5 files changed +95
-2
lines changed Expand file tree Collapse file tree 5 files changed +95
-2
lines changed Original file line number Diff line number Diff line change 1
1
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2
2
// for details. All rights reserved. Use of this source code is governed by a
3
3
// BSD-style license that can be found in the LICENSE file.
4
+
4
5
library pub.solver.backtracking_solver;
5
6
6
7
import 'dart:async';
Original file line number Diff line number Diff line change @@ -107,6 +107,9 @@ class SequenceBuilder {
107
107
108
108
/// Writes any comments appearing before [token] to the sequence.
109
109
///
110
+ /// Also handles blank lines between preceding comments and elements and the
111
+ /// subsequent element.
112
+ ///
110
113
/// Comments between sequence elements get special handling where comments
111
114
/// on their own line become standalone sequence elements.
112
115
void addCommentsBefore (Token token, {int ? indent}) {
@@ -152,7 +155,13 @@ class SequenceBuilder {
152
155
if (comments.requiresNewline) _mustSplit = true ;
153
156
154
157
// Write a blank before the token if there should be one.
155
- if (comments.linesBeforeNextToken > 1 ) addBlank ();
158
+ if (comments.linesBeforeNextToken > 1 ) {
159
+ // If we just wrote a comment, then allow a blank line between it and the
160
+ // element.
161
+ if (comments.isNotEmpty) _allowBlank = true ;
162
+
163
+ addBlank ();
164
+ }
156
165
}
157
166
158
167
void _add (int indent, Piece piece) {
Original file line number Diff line number Diff line change
1
+ >>>
2
+ // Comment.
3
+
4
+ main() {}
5
+ <<<
6
+ // Comment.
7
+
8
+ main() {}
9
+ >>>
10
+ // Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
11
+ // for details. All rights reserved. Use of this source code is governed by a
12
+ // BSD-style license that can be found in the LICENSE file.
13
+
14
+ import 'package:analyzer/dart/ast/ast.dart';
15
+ <<<
16
+ // Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
17
+ // for details. All rights reserved. Use of this source code is governed by a
18
+ // BSD-style license that can be found in the LICENSE file.
19
+
20
+ import 'package:analyzer/dart/ast/ast.dart';
Original file line number Diff line number Diff line change @@ -96,4 +96,21 @@ line */
96
96
a:
97
97
b:
98
98
c;
99
+ }
100
+ >>> Preserve one blank line between a leading comment and statement.
101
+ {
102
+
103
+
104
+
105
+ // comment
106
+
107
+
108
+
109
+ a;
110
+ }
111
+ <<<
112
+ {
113
+ // comment
114
+
115
+ a;
99
116
}
Original file line number Diff line number Diff line change @@ -100,4 +100,50 @@ void b() => body;
100
100
/// Doc function.
101
101
void c() {
102
102
;
103
- }
103
+ }
104
+ >>> Preserve one blank line between a leading comment and declaration.
105
+ // comment
106
+
107
+
108
+
109
+ var a = 1;
110
+ <<<
111
+ // comment
112
+
113
+ var a = 1;
114
+ >>> Preserve one blank line between a leading comment and directive.
115
+ // comment
116
+
117
+
118
+
119
+ import 'x.dart';
120
+ <<<
121
+ // comment
122
+
123
+ import 'x.dart';
124
+ >>> Preserve one blank line between comments and declarations.
125
+ // comment
126
+ var a = 1;
127
+
128
+ // comment
129
+
130
+ var b = 2;
131
+
132
+
133
+
134
+ // comment
135
+
136
+
137
+
138
+ var c = 3;
139
+ <<<
140
+ // comment
141
+ var a = 1;
142
+
143
+ // comment
144
+
145
+ var b = 2;
146
+
147
+ // comment
148
+
149
+ var c = 3;
You can’t perform that action at this time.
0 commit comments