Skip to content

Commit 3bf98a4

Browse files
committed
Avoid unnecessary comment removal
1 parent 51c4aaa commit 3bf98a4

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

modfile/read.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,11 +232,11 @@ func (x *FileSyntax) Cleanup() {
232232
// Collapse block into single line but keep the Line reference used by the
233233
// parsed File structure.
234234
*stmt.Line[0] = Line{
235-
Comments: removeEmptyComments(Comments{
235+
Comments: Comments{
236236
Before: commentsAdd(stmt.Before, stmt.Line[0].Before),
237237
Suffix: commentsAdd(stmt.Line[0].Suffix, stmt.Suffix),
238238
After: commentsAdd(stmt.Line[0].After, stmt.After),
239-
}),
239+
},
240240
Token: stringsAdd(stmt.Token, stmt.Line[0].Token),
241241
}
242242
x.Stmt[w] = stmt.Line[0]
@@ -889,6 +889,7 @@ func (in *input) parseLineBlock(start Position, token []string, lparen token) *L
889889
// Suffix comment, will be attached later by assignComments.
890890
in.lex()
891891
case '\n':
892+
// Blank line. Add an empty comment to preserve it.
892893
in.lex()
893894
if len(comments) == 0 && len(x.Line) > 0 || len(comments) > 0 && comments[len(comments)-1].Token != "" {
894895
comments = append(comments, Comment{})

0 commit comments

Comments
 (0)