Skip to content

Commit 9cdc3b8

Browse files
committed
Resolve comments
1 parent 6a8257d commit 9cdc3b8

File tree

1 file changed

+8
-19
lines changed

1 file changed

+8
-19
lines changed

modfile/read.go

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,6 @@ func (x *FileSyntax) Cleanup() {
225225
if ww == 0 {
226226
continue
227227
}
228-
// **Check and remove empty RParen comments**
229-
stmt.RParen.Comments = removeEmptyComments(stmt.RParen.Comments)
230228
if ww == 1 && len(stmt.RParen.Comments.Before) == 0 {
231229
// Collapse block into single line but keep the Line reference used by the
232230
// parsed File structure.
@@ -250,22 +248,6 @@ func (x *FileSyntax) Cleanup() {
250248
x.Stmt = x.Stmt[:w]
251249
}
252250

253-
// removeEmptyComments removes empty comment sections.
254-
func removeEmptyComments(c Comments) Comments {
255-
// Remove comments with empty tokens and zero position markers
256-
var newBefore []Comment
257-
for _, cm := range c.Before {
258-
if cm.Token != "" || cm.Start.Line != 0 || cm.Start.Byte != 0 {
259-
newBefore = append(newBefore, cm)
260-
}
261-
}
262-
263-
if len(newBefore) == 0 && len(c.Suffix) == 0 && len(c.After) == 0 {
264-
return Comments{}
265-
}
266-
return Comments{Before: newBefore, Suffix: c.Suffix, After: c.After}
267-
}
268-
269251
func commentsAdd(x, y []Comment) []Comment {
270252
return append(x[:len(x):len(x)], y...)
271253
}
@@ -895,7 +877,14 @@ func (in *input) parseLineBlock(start Position, token []string, lparen token) *L
895877
in.Error(fmt.Sprintf("syntax error (unterminated block started at %s:%d:%d)", in.filename, x.Start.Line, x.Start.LineRune))
896878
case ')':
897879
rparen := in.lex()
898-
x.RParen.Before = comments
880+
// Filter out comments with Start.Line == 0
881+
var filteredComments []Comment
882+
for _, c := range comments {
883+
if c.Start.Line > 0 {
884+
filteredComments = append(filteredComments, c)
885+
}
886+
}
887+
x.RParen.Before = filteredComments
899888
x.RParen.Pos = rparen.pos
900889
if !in.peek().isEOL() {
901890
in.Error("syntax error (expected newline after closing paren)")

0 commit comments

Comments
 (0)