MCPcopy
hub / github.com/gopherjs/gopherjs / translateSelection

Method translateSelection

compiler/utils.go:194–226  ·  view source on GitHub ↗
(sel typesutil.Selection, pos token.Pos)

Source from the content-addressed store, hash-verified

192}
193
194func (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
228var nilObj = types.Universe.Lookup("nil")
229

Callers 2

translateAssignMethod · 0.95
translateExprMethod · 0.95

Calls 10

fieldTypeMethod · 0.95
IsJsObjectFunction · 0.92
getJsTagFunction · 0.85
fieldNameFunction · 0.85
TagMethod · 0.80
RecvMethod · 0.65
IndexMethod · 0.65
ElemMethod · 0.45
NameMethod · 0.45
FieldMethod · 0.45

Tested by

no test coverage detected