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
2 changes: 1 addition & 1 deletion rewrite-go/pkg/parser/go_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -1758,7 +1758,7 @@ func (ctx *parseContext) mapCallExpr(expr *ast.CallExpr) tree.Expression {

switch f := fun.(type) {
case *tree.FieldAccess:
selRP := tree.RightPadded[tree.Expression]{Element: f.Target}
selRP := tree.RightPadded[tree.Expression]{Element: f.Target, After: f.Name.Before}
sel = &selRP
name = f.Name.Element
case *tree.Identifier:
Expand Down
1 change: 1 addition & 0 deletions rewrite-go/pkg/printer/go_printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ func (p *GoPrinter) VisitMethodInvocation(mi *tree.MethodInvocation, param any)
if mi.Select != nil {
p.Visit(mi.Select.Element, out)
if mi.Name.Name != "" {
p.visitSpace(mi.Select.After, out)
out.Append(".")
}
}
Expand Down
13 changes: 13 additions & 0 deletions rewrite-go/test/comment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,19 @@ func TestParseCommentInsideEmptyDelimiters(t *testing.T) {
`))
}

func TestParseBlockCommentBeforeSelector(t *testing.T) {
NewRecipeSpec().RewriteRun(t,
Golang(`
package main

import "unsafe"

func f(x int) {
unsafe /* a comment */ .Alignof(x)
}
`))
}

func TestParseMultilineBlockComment(t *testing.T) {
NewRecipeSpec().RewriteRun(t,
Golang(`
Expand Down
Loading