@@ -179,6 +179,10 @@ class IncrementalPlan {
179179
180180 var index = 0 ;
181181
182+ // Returns the next line and updates [index].
183+ //
184+ // After this function returns, [index] points to the character after the
185+ // end of the line which was returned.
182186 String getLine () {
183187 var nextIndex = code.indexOf ('\n ' , index);
184188 if (nextIndex < 0 ) {
@@ -220,24 +224,37 @@ class IncrementalPlan {
220224 // [code] consists _only_ of one comment line.
221225 return '$code $newline $newline // @dart=2.9$newline ' ;
222226 }
223- line = getLine ();
224- lineStart = line.indexOf (_nonWhitespaceChar);
225- while (lineStart >= 0 &&
226- line.length > lineStart + 1 &&
227- line.codeUnitAt (lineStart) == $slash &&
228- line.codeUnitAt (lineStart + 1 ) == $slash) {
229- // Another comment line.
227+ var previousLineIndex = index;
228+ while (true ) {
229+ previousLineIndex = index;
230230 line = getLine ();
231- if (index == length) {
232- // [code] consists _only_ of this block comment.
233- return '$code $newline $newline // @dart=2.9$newline ' ;
234- }
235231 lineStart = line.indexOf (_nonWhitespaceChar);
232+ if (lineStart < 0 ) {
233+ // Line of whitespace; end of block comment.
234+ break ;
235+ }
236+ if (line.length <= lineStart + 1 ) {
237+ // Only one character; not a comment; end of block comment.
238+ break ;
239+ }
240+ if (line.codeUnitAt (lineStart) == $slash &&
241+ line.codeUnitAt (lineStart + 1 ) == $slash) {
242+ // Comment line.
243+ if (index == length) {
244+ // [code] consists _only_ of this block comment.
245+ return '$code $newline $newline // @dart=2.9$newline ' ;
246+ }
247+ continue ;
248+ } else {
249+ // Non-blank, non-comment line.
250+ break ;
251+ }
236252 }
237- // [index ] points to the start of [line], which is the first
253+ // [previousLineIndex ] points to the start of [line], which is the first
238254 // non-comment line following the first comment.
239- return '${code .substring (0 , index )}$newline // @dart=2.9$newline $newline '
240- '${code .substring (index )}' ;
255+ return '${code .substring (0 , previousLineIndex )}$newline '
256+ '// @dart=2.9$newline $newline '
257+ '${code .substring (previousLineIndex )}' ;
241258 } else {
242259 // [code] does not start with a block comment.
243260 return '// @dart=2.9$newline $newline $code ' ;
0 commit comments