ast: fix double-fix for refs["with-a"].dash as package

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
This commit is contained in:
Stephan Renatus
2026-02-02 19:51:36 +01:00
committed by Stephan Renatus
parent e426fd7c76
commit c90bfeb91a
2 changed files with 12 additions and 9 deletions
-9
View File
@@ -68,15 +68,6 @@ func (pkg *Package) AppendText(buf []byte) ([]byte, error) {
path := pkg.Path[1:] // omit "data"
if s, ok := path[0].Value.(String); ok {
buf = append(buf, s...) // first term should never be quoted
if len(path) == 1 {
return buf, nil
}
buf = append(buf, '.')
path = path[1:]
}
return path.AppendText(buf)
}
+12
View File
@@ -51,6 +51,18 @@ r = true`,
},
want: `package example.foo`,
},
{
name: "package with special chars",
node: &ast.Package{
Path: ast.Ref{
ast.DefaultRootDocument,
ast.StringTerm("pkg"),
ast.StringTerm("with-a"),
ast.StringTerm("dash"),
},
},
want: `package pkg["with-a"].dash`,
},
{
name: "import",
node: &ast.Import{