Skip to content

Commit b348e49

Browse files
committed
bundle: do not rewrite type name as key in composite literal
It must be a struct field, which should not be rewritten. The exception is embedded fields. For that we would need to dig deeper into the type information.
1 parent 67fb960 commit b348e49

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

cmd/bundle/main.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ func main() {
107107
}
108108

109109
isTop := make(map[interface{}]bool)
110+
isType := make(map[string]bool)
110111
isTopName := make(map[string]bool)
111112
for _, f := range pkg.Files {
112113
for _, d := range f.Decls {
@@ -122,6 +123,7 @@ func main() {
122123
}
123124
case *ast.TypeSpec:
124125
isTop[spec] = true
126+
isType[spec.Name.Name] = true
125127
isTopName[spec.Name.Name] = true
126128
rename(spec.Name)
127129
}
@@ -140,6 +142,12 @@ func main() {
140142

141143
for _, f := range pkg.Files {
142144
walk(f, func(n interface{}) {
145+
kv, ok := n.(*ast.KeyValueExpr)
146+
if ok {
147+
if id, ok := kv.Key.(*ast.Ident); ok && renamed[id] && isType[id.Name[len(*prefix):]] {
148+
id.Name = id.Name[len(*prefix):]
149+
}
150+
}
143151
id, ok := n.(*ast.Ident)
144152
if ok && (id.Obj != nil && isTop[id.Obj.Decl] || id.Obj == nil && isTopName[id.Name]) {
145153
rename(id)

0 commit comments

Comments
 (0)