| 192 | } |
| 193 | |
| 194 | func (fc *funcContext) translateSelection(sel typesutil.Selection, pos token.Pos) ([]string, string) { |
| 195 | var fields []string |
| 196 | t := sel.Recv() |
| 197 | for _, index := range sel.Index() { |
| 198 | if ptr, isPtr := t.Underlying().(*types.Pointer); isPtr { |
| 199 | t = ptr.Elem() |
| 200 | } |
| 201 | s := t.Underlying().(*types.Struct) |
| 202 | if jsTag := getJsTag(s.Tag(index)); jsTag != "" { |
| 203 | jsFieldName := s.Field(index).Name() |
| 204 | for { |
| 205 | fields = append(fields, fieldName(s, 0)) |
| 206 | ft := fc.fieldType(s, 0) |
| 207 | if typesutil.IsJsObject(ft) { |
| 208 | return fields, jsTag |
| 209 | } |
| 210 | ft = ft.Underlying() |
| 211 | if ptr, ok := ft.(*types.Pointer); ok { |
| 212 | ft = ptr.Elem().Underlying() |
| 213 | } |
| 214 | var ok bool |
| 215 | s, ok = ft.(*types.Struct) |
| 216 | if !ok || s.NumFields() == 0 { |
| 217 | fc.pkgCtx.errList = append(fc.pkgCtx.errList, types.Error{Fset: fc.pkgCtx.fileSet, Pos: pos, Msg: fmt.Sprintf("could not find field with type *js.Object for 'js' tag of field '%s'", jsFieldName), Soft: true}) |
| 218 | return nil, "" |
| 219 | } |
| 220 | } |
| 221 | } |
| 222 | fields = append(fields, fieldName(s, index)) |
| 223 | t = fc.fieldType(s, index) |
| 224 | } |
| 225 | return fields, "" |
| 226 | } |
| 227 | |
| 228 | var nilObj = types.Universe.Lookup("nil") |
| 229 | |