5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-03 04:29:35 +08:00

Fix registration of exposed fields (#1727)

This commit is contained in:
Valentin Trinqué 2022-08-11 00:41:37 +02:00 committed by GitHub
parent 04094ddf19
commit cf3c65f0cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 4 deletions

View File

@ -156,7 +156,7 @@ func (b *Bindings) AddStructToGenerateTS(packageName string, structName string,
}
kind := field.Type.Kind()
if kind == reflect.Struct {
if field.PkgPath == "" {
if !field.IsExported() {
continue
}
fqname := field.Type.String()
@ -168,7 +168,7 @@ func (b *Bindings) AddStructToGenerateTS(packageName string, structName string,
b.AddStructToGenerateTS(pName, sName, s)
}
} else if kind == reflect.Ptr && field.Type.Elem().Kind() == reflect.Struct {
if field.PkgPath == "" {
if !field.IsExported() {
continue
}
fqname := field.Type.String()
@ -182,7 +182,6 @@ func (b *Bindings) AddStructToGenerateTS(packageName string, structName string,
}
}
}
}
func (b *Bindings) getAllStructNames() *slicer.StringSlicer {

View File

@ -1,10 +1,41 @@
package binding
import (
"github.com/leaanthony/slicer"
"testing"
"github.com/leaanthony/slicer"
"github.com/stretchr/testify/assert"
"github.com/wailsapp/wails/v2/internal/logger"
)
type BindForTest struct {
}
func (b *BindForTest) GetA() A {
return A{}
}
type A struct {
B B `json:"B"`
}
type B struct {
Name string `json:"name"`
}
func TestNestedStruct(t *testing.T) {
bind := &BindForTest{}
testBindings := NewBindings(logger.New(nil), []interface{}{bind}, []interface{}{})
namesStrSlicer := testBindings.getAllStructNames()
names := []string{}
namesStrSlicer.Each(func(s string) {
names = append(names, s)
})
assert.Contains(t, names, "binding.A")
assert.Contains(t, names, "binding.B")
}
func Test_goTypeToJSDocType(t *testing.T) {
tests := []struct {