Skip to content

Commit

Permalink
Merge pull request #7 from lujiajing1126/obj_resolve
Browse files Browse the repository at this point in the history
Use LastIndex to split ident name
  • Loading branch information
tenntenn authored May 1, 2024
2 parents 209025f + 35c65dc commit 2e8025e
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions template.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,13 @@ func (td *TempalteData) name(v reflect.Value) string {
}

func (td *TempalteData) objectOf(s string) Object {
ss := strings.Split(s, ".")
dotPos := strings.LastIndex(s, ".")

switch len(ss) {
case 1:
if dotPos == -1 {
obj := types.Universe.Lookup(s)
return NewObject(obj)
case 2:
pkg, name := ss[0], ss[1]
} else {
pkg, name := s[:dotPos], s[dotPos+1:]
obj := analysisutil.LookupFromImports(td.Pkg.Imports(), pkg, name)
if obj != nil {
return NewObject(obj)
Expand All @@ -126,7 +125,6 @@ func (td *TempalteData) objectOf(s string) Object {
}
return NewObject(td.Pkg.Scope().Lookup(name))
}
return nil
}

func (td *TempalteData) typeOf(s string) *Type {
Expand Down

0 comments on commit 2e8025e

Please sign in to comment.