diff --git a/v3/internal/parser/parser.go b/v3/internal/parser/parser.go index b1ec6d15..bb10ef26 100644 --- a/v3/internal/parser/parser.go +++ b/v3/internal/parser/parser.go @@ -395,7 +395,7 @@ func (p *Project) parseBoundStructMethods(name string, pkg *ParsedPackage) error var ident *ast.Ident var ok bool - switch v := funcDecl.Recv.List[0].Type.(type) { + switch funcDecl.Recv.List[0].Type.(type) { case *ast.StarExpr: recv := funcDecl.Recv.List[0].Type.(*ast.StarExpr) ident, ok = recv.X.(*ast.Ident) diff --git a/v3/internal/parser/parser_test.go b/v3/internal/parser/parser_test.go index c6832191..8722836d 100644 --- a/v3/internal/parser/parser_test.go +++ b/v3/internal/parser/parser_test.go @@ -974,6 +974,965 @@ func TestParseDirectory(t *testing.T) { }, wantErr: false, }, + { + name: "should find single bound service (non-pointer receiver)", + dir: "testdata/struct_literal_non_pointer_single", + wantBoundMethods: map[string]map[string][]*BoundMethod{ + "main": { + "GreetService": { + { + Name: "Greet", + DocComment: "Greet someone\n", + Inputs: []*Parameter{ + { + Name: "name", + Type: &ParameterType{ + Name: "string", + }, + }, + }, + Outputs: []*Parameter{ + { + Name: "", + Type: &ParameterType{ + Name: "string", + }, + }, + }, + ID: 1411160069, + }, + { + Name: "NoInputsStringOut", + DocComment: "", + Inputs: nil, + Outputs: []*Parameter{ + { + Name: "", + Type: &ParameterType{ + Name: "string", + }, + }, + }, + ID: 1075577233, + }, + { + Name: "StringArrayInputStringOut", + Inputs: []*Parameter{ + { + Name: "in", + Type: &ParameterType{ + Name: "string", + IsSlice: true, + }, + }, + }, + Outputs: []*Parameter{ + { + Type: &ParameterType{ + Name: "string", + }, + }, + }, + ID: 1091960237, + }, + { + Name: "StringArrayInputStringArrayOut", + Inputs: []*Parameter{ + { + Name: "in", + Type: &ParameterType{ + Name: "string", + IsSlice: true, + }, + }, + }, + Outputs: []*Parameter{ + { + Type: &ParameterType{ + Name: "string", + IsSlice: true, + }, + }, + }, + ID: 383995060, + }, + { + Name: "StringArrayInputNamedOutput", + Inputs: []*Parameter{ + { + Name: "in", + Type: &ParameterType{ + Name: "string", + IsSlice: true, + }, + }, + }, + Outputs: []*Parameter{ + { + Name: "output", + Type: &ParameterType{ + Name: "string", + IsSlice: true, + }, + }, + }, + ID: 3678582682, + }, + { + Name: "StringArrayInputNamedOutputs", + Inputs: []*Parameter{ + { + Name: "in", + Type: &ParameterType{ + Name: "string", + IsSlice: true, + }, + }, + }, + Outputs: []*Parameter{ + { + Name: "output", + Type: &ParameterType{ + Name: "string", + IsSlice: true, + }, + }, + { + Name: "err", + Type: &ParameterType{ + Name: "error", + }, + }, + }, + ID: 319259595, + }, + { + Name: "IntPointerInputNamedOutputs", + Inputs: []*Parameter{ + { + Name: "in", + Type: &ParameterType{ + Name: "int", + IsPointer: true, + }, + }, + }, + Outputs: []*Parameter{ + { + Name: "output", + Type: &ParameterType{ + Name: "int", + IsPointer: true, + }, + }, + { + Name: "err", + Type: &ParameterType{ + Name: "error", + }}, + }, + ID: 2718999663, + }, + { + Name: "UIntPointerInAndOutput", + Inputs: []*Parameter{ + { + Name: "in", + Type: &ParameterType{ + Name: "uint", + IsPointer: true, + }, + }, + }, + Outputs: []*Parameter{ + { + Type: &ParameterType{ + Name: "uint", + IsPointer: true, + }, + }, + }, + ID: 1367187362, + }, + { + Name: "UInt8PointerInAndOutput", + Inputs: []*Parameter{ + { + Name: "in", + Type: &ParameterType{ + Name: "uint8", + IsPointer: true, + }, + }, + }, + Outputs: []*Parameter{ + { + Type: &ParameterType{ + Name: "uint8", + IsPointer: true, + }, + }, + }, + ID: 518250834, + }, + { + Name: "UInt16PointerInAndOutput", + Inputs: []*Parameter{ + { + Name: "in", + Type: &ParameterType{ + Name: "uint16", + IsPointer: true, + }, + }, + }, + Outputs: []*Parameter{ + { + Type: &ParameterType{ + Name: "uint16", + IsPointer: true, + }, + }, + }, + ID: 1236957573, + }, + { + Name: "UInt32PointerInAndOutput", + Inputs: []*Parameter{ + { + Name: "in", + Type: &ParameterType{ + Name: "uint32", + IsPointer: true, + }, + }, + }, + Outputs: []*Parameter{ + { + Type: &ParameterType{ + Name: "uint32", + IsPointer: true, + }, + }, + }, + ID: 1739300671, + }, + { + Name: "UInt64PointerInAndOutput", + Inputs: []*Parameter{ + { + Name: "in", + Type: &ParameterType{ + Name: "uint64", + IsPointer: true, + }, + }, + }, + Outputs: []*Parameter{ + { + Type: &ParameterType{ + Name: "uint64", + IsPointer: true, + }, + }, + }, + ID: 1403757716, + }, + { + Name: "IntPointerInAndOutput", + Inputs: []*Parameter{ + { + Name: "in", + Type: &ParameterType{ + Name: "int", + IsPointer: true, + }, + }, + }, + Outputs: []*Parameter{ + { + Type: &ParameterType{ + Name: "int", + IsPointer: true, + }, + }, + }, + ID: 1066151743, + }, + { + Name: "Int8PointerInAndOutput", + Inputs: []*Parameter{ + { + Name: "in", + Type: &ParameterType{ + Name: "int8", + IsPointer: true, + }, + }, + }, + Outputs: []*Parameter{ + { + Type: &ParameterType{ + Name: "int8", + IsPointer: true, + }, + }, + }, + ID: 2189402897, + }, + { + Name: "Int16PointerInAndOutput", + Inputs: []*Parameter{ + { + Name: "in", + Type: &ParameterType{ + Name: "int16", + IsPointer: true, + }, + }, + }, + Outputs: []*Parameter{ + { + Type: &ParameterType{ + Name: "int16", + IsPointer: true, + }, + }, + }, + ID: 1754277916, + }, + { + Name: "Int32PointerInAndOutput", + Inputs: []*Parameter{ + { + Name: "in", + Type: &ParameterType{ + Name: "int32", + IsPointer: true, + }, + }, + }, + Outputs: []*Parameter{ + { + Type: &ParameterType{ + Name: "int32", + IsPointer: true, + }, + }, + }, + ID: 4251088558, + }, + { + Name: "Int64PointerInAndOutput", + Inputs: []*Parameter{ + { + Name: "in", + Type: &ParameterType{ + Name: "int64", + IsPointer: true, + }, + }, + }, + Outputs: []*Parameter{ + { + Type: &ParameterType{ + Name: "int64", + IsPointer: true, + }, + }, + }, + ID: 2205561041, + }, + { + Name: "IntInIntOut", + Inputs: []*Parameter{ + { + Name: "in", + Type: &ParameterType{ + Name: "int", + }, + }, + }, + Outputs: []*Parameter{ + { + Type: &ParameterType{ + Name: "int", + }, + }, + }, + ID: 642881729, + }, + { + Name: "Int8InIntOut", + Inputs: []*Parameter{ + { + Name: "in", + Type: &ParameterType{ + Name: "int8", + }, + }, + }, + Outputs: []*Parameter{ + { + Type: &ParameterType{ + Name: "int8", + }, + }, + }, + ID: 572240879, + }, + { + Name: "Int16InIntOut", + Inputs: []*Parameter{ + { + Name: "in", + Type: &ParameterType{ + Name: "int16", + }, + }, + }, + Outputs: []*Parameter{ + { + Type: &ParameterType{ + Name: "int16", + }, + }, + }, + ID: 3306292566, + }, + { + Name: "Int32InIntOut", + Inputs: []*Parameter{ + { + Name: "in", + Type: &ParameterType{ + Name: "int32", + }, + }, + }, + Outputs: []*Parameter{ + { + Type: &ParameterType{ + Name: "int32", + }, + }, + }, + ID: 1909469092, + }, + { + Name: "Int64InIntOut", + Inputs: []*Parameter{ + { + Name: "in", + Type: &ParameterType{ + Name: "int64", + }, + }, + }, + Outputs: []*Parameter{ + { + Type: &ParameterType{ + Name: "int64", + }, + }, + }, + ID: 1343888303, + }, + { + Name: "UIntInUIntOut", + Inputs: []*Parameter{ + { + Name: "in", + Type: &ParameterType{ + Name: "uint", + }, + }, + }, + Outputs: []*Parameter{ + { + Type: &ParameterType{ + Name: "uint", + }, + }, + }, + ID: 2836661285, + }, + { + Name: "UInt8InUIntOut", + Inputs: []*Parameter{ + { + Name: "in", + Type: &ParameterType{ + Name: "uint8", + }, + }, + }, + Outputs: []*Parameter{ + { + Type: &ParameterType{ + Name: "uint8", + }, + }, + }, + ID: 2988345717, + }, + { + Name: "UInt16InUIntOut", + Inputs: []*Parameter{ + { + Name: "in", + Type: &ParameterType{ + Name: "uint16", + }, + }, + }, + Outputs: []*Parameter{ + { + Type: &ParameterType{ + Name: "uint16", + }, + }, + }, + ID: 3401034892, + }, + { + Name: "UInt32InUIntOut", + Inputs: []*Parameter{ + { + Name: "in", + Type: &ParameterType{ + Name: "uint32", + }, + }, + }, + Outputs: []*Parameter{ + { + Type: &ParameterType{ + Name: "uint32", + }, + }, + }, + ID: 1160383782, + }, + { + Name: "UInt64InUIntOut", + Inputs: []*Parameter{ + { + Name: "in", + Type: &ParameterType{ + Name: "uint64", + }, + }, + }, + Outputs: []*Parameter{ + { + Type: &ParameterType{ + Name: "uint64", + }, + }, + }, + ID: 793803239, + }, + { + Name: "Float32InFloat32Out", + Inputs: []*Parameter{ + { + Name: "in", + Type: &ParameterType{ + Name: "float32", + }, + }, + }, + Outputs: []*Parameter{ + { + Type: &ParameterType{ + Name: "float32", + }, + }, + }, + ID: 3132595881, + }, + { + Name: "Float64InFloat64Out", + Inputs: []*Parameter{ + { + Name: "in", + Type: &ParameterType{ + Name: "float64", + }, + }, + }, + Outputs: []*Parameter{ + { + Type: &ParameterType{ + Name: "float64", + }, + }, + }, + ID: 2182412247, + }, + { + Name: "PointerFloat32InFloat32Out", + Inputs: []*Parameter{ + { + Name: "in", + Type: &ParameterType{ + Name: "float32", + IsPointer: true, + }, + }, + }, + Outputs: []*Parameter{ + { + Type: &ParameterType{ + Name: "float32", + IsPointer: true, + }, + }, + }, + ID: 224675106, + }, + { + Name: "PointerFloat64InFloat64Out", + Inputs: []*Parameter{ + { + Name: "in", + Type: &ParameterType{ + Name: "float64", + IsPointer: true, + }, + }, + }, + Outputs: []*Parameter{ + { + Type: &ParameterType{ + Name: "float64", + IsPointer: true, + }, + }, + }, + ID: 2124953624, + }, + { + Name: "BoolInBoolOut", + Inputs: []*Parameter{ + { + Name: "in", + Type: &ParameterType{ + Name: "bool", + }, + }, + }, + Outputs: []*Parameter{ + { + Type: &ParameterType{ + Name: "bool", + }, + }, + }, + ID: 2424639793, + }, + { + Name: "PointerBoolInBoolOut", + Inputs: []*Parameter{ + { + Name: "in", + Type: &ParameterType{ + Name: "bool", + IsPointer: true, + }, + }, + }, + Outputs: []*Parameter{ + { + Type: &ParameterType{ + Name: "bool", + IsPointer: true, + }, + }, + }, + ID: 3589606958, + }, + { + Name: "PointerStringInStringOut", + Inputs: []*Parameter{ + { + Name: "in", + Type: &ParameterType{ + Name: "string", + IsPointer: true, + }, + }, + }, + Outputs: []*Parameter{ + { + Type: &ParameterType{ + Name: "string", + IsPointer: true, + }, + }, + }, + ID: 229603958, + }, + { + Name: "StructPointerInputErrorOutput", + Inputs: []*Parameter{ + { + Name: "in", + Type: &ParameterType{ + Name: "Person", + IsPointer: true, + IsStruct: true, + Package: "main", + }, + }, + }, + Outputs: []*Parameter{ + { + Type: &ParameterType{ + Name: "error", + }, + }, + }, + ID: 2447692557, + }, + { + Name: "StructInputStructOutput", + Inputs: []*Parameter{ + { + Name: "in", + Type: &ParameterType{ + Name: "Person", + IsStruct: true, + Package: "main", + }, + }, + }, + Outputs: []*Parameter{ + { + Type: &ParameterType{ + Name: "Person", + IsStruct: true, + Package: "main", + }, + }, + }, + ID: 3835643147, + }, + { + Name: "StructPointerInputStructPointerOutput", + Inputs: []*Parameter{ + { + Name: "in", + Type: &ParameterType{ + Name: "Person", + IsPointer: true, + IsStruct: true, + Package: "main", + }, + }, + }, + Outputs: []*Parameter{ + { + Type: &ParameterType{ + Name: "Person", + IsPointer: true, + IsStruct: true, + Package: "main", + }, + }, + }, + ID: 2943477349, + }, + { + Name: "MapIntInt", + Inputs: []*Parameter{ + { + Name: "in", + Type: &ParameterType{ + Name: "map", + MapKey: &ParameterType{ + Name: "int", + }, + MapValue: &ParameterType{ + Name: "int", + }, + }, + }, + }, + ID: 2386486356, + }, + { + Name: "PointerMapIntInt", + Inputs: []*Parameter{ + { + Name: "in", + Type: &ParameterType{ + Name: "map", + IsPointer: true, + MapKey: &ParameterType{ + Name: "int", + }, + MapValue: &ParameterType{ + Name: "int", + }, + }, + }, + }, + ID: 3516977899, + }, + { + Name: "MapIntPointerInt", + Inputs: []*Parameter{ + { + Name: "in", + Type: &ParameterType{ + Name: "map", + MapKey: &ParameterType{ + Name: "int", + IsPointer: true, + }, + MapValue: &ParameterType{ + Name: "int", + }, + }, + }, + }, + ID: 550413585, + }, + { + Name: "MapIntSliceInt", + Inputs: []*Parameter{ + { + Name: "in", + Type: &ParameterType{ + Name: "map", + MapKey: &ParameterType{ + Name: "int", + }, + MapValue: &ParameterType{ + Name: "int", + IsSlice: true, + }, + }, + }, + }, + ID: 2900172572, + }, + { + Name: "MapIntSliceIntInMapIntSliceIntOut", + Inputs: []*Parameter{ + { + Name: "in", + Type: &ParameterType{ + Name: "map", + MapKey: &ParameterType{ + Name: "int", + }, + MapValue: &ParameterType{ + Name: "int", + IsSlice: true, + }, + }, + }, + }, + Outputs: []*Parameter{ + { + Name: "out", + Type: &ParameterType{ + Name: "map", + MapKey: &ParameterType{ + Name: "int", + }, + MapValue: &ParameterType{ + Name: "int", + IsSlice: true, + }, + }, + }, + }, + ID: 881980169, + }, + { + Name: "ArrayInt", + Inputs: []*Parameter{ + { + Name: "in", + Type: &ParameterType{ + Name: "int", + IsSlice: true, + }, + }, + }, + ID: 3862002418, + }, + }, + }, + }, + wantModels: map[string]map[string]*StructDef{ + "main": { + "Person": { + Name: "Person", + Fields: []*Field{ + { + Name: "Name", + Type: &ParameterType{ + Name: "string", + }, + }, + { + Name: "Parent", + Type: &ParameterType{ + Name: "Person", + IsStruct: true, + IsPointer: true, + Package: "main", + }, + }, + { + Name: "Details", + Type: &ParameterType{ + Name: "anon1", + IsStruct: true, + Package: "main", + }, + }, + }, + }, + "anon1": { + Name: "anon1", + Fields: []*Field{ + { + Name: "Age", + Type: &ParameterType{ + Name: "int", + }, + }, + { + Name: "Address", + Type: &ParameterType{ + Name: "anon2", + IsStruct: true, + Package: "main", + }, + }, + }, + }, + "anon2": { + Name: "anon2", + Fields: []*Field{ + { + Name: "Street", + Type: &ParameterType{ + Name: "string", + }, + }, + }, + }, + }, + }, + wantErr: false, + }, { name: "should find multiple bound services", dir: "testdata/struct_literal_multiple", diff --git a/v3/internal/parser/testdata/struct_literal_non_pointer_single/bindings_main.js b/v3/internal/parser/testdata/struct_literal_non_pointer_single/bindings_main.js new file mode 100644 index 00000000..893b066b --- /dev/null +++ b/v3/internal/parser/testdata/struct_literal_non_pointer_single/bindings_main.js @@ -0,0 +1,356 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +import {main} from './models'; + +window.go = window.go || {}; +window.go.main = { + GreetService: { + + /** + * GreetService.ArrayInt + * + * @param _in {number[]} + * @returns {Promise} + **/ + ArrayInt: function(_in) { wails.CallByID(3862002418, ...Array.prototype.slice.call(arguments, 0)); }, + + /** + * GreetService.BoolInBoolOut + * + * @param _in {boolean} + * @returns {Promise} + **/ + BoolInBoolOut: function(_in) { wails.CallByID(2424639793, ...Array.prototype.slice.call(arguments, 0)); }, + + /** + * GreetService.Float32InFloat32Out + * + * @param _in {number} + * @returns {Promise} + **/ + Float32InFloat32Out: function(_in) { wails.CallByID(3132595881, ...Array.prototype.slice.call(arguments, 0)); }, + + /** + * GreetService.Float64InFloat64Out + * + * @param _in {number} + * @returns {Promise} + **/ + Float64InFloat64Out: function(_in) { wails.CallByID(2182412247, ...Array.prototype.slice.call(arguments, 0)); }, + + /** + * GreetService.Greet + * Greet someone + * @param name {string} + * @returns {Promise} + **/ + Greet: function(name) { wails.CallByID(1411160069, ...Array.prototype.slice.call(arguments, 0)); }, + + /** + * GreetService.Int16InIntOut + * + * @param _in {number} + * @returns {Promise} + **/ + Int16InIntOut: function(_in) { wails.CallByID(3306292566, ...Array.prototype.slice.call(arguments, 0)); }, + + /** + * GreetService.Int16PointerInAndOutput + * + * @param _in {number | null} + * @returns {Promise} + **/ + Int16PointerInAndOutput: function(_in) { wails.CallByID(1754277916, ...Array.prototype.slice.call(arguments, 0)); }, + + /** + * GreetService.Int32InIntOut + * + * @param _in {number} + * @returns {Promise} + **/ + Int32InIntOut: function(_in) { wails.CallByID(1909469092, ...Array.prototype.slice.call(arguments, 0)); }, + + /** + * GreetService.Int32PointerInAndOutput + * + * @param _in {number | null} + * @returns {Promise} + **/ + Int32PointerInAndOutput: function(_in) { wails.CallByID(4251088558, ...Array.prototype.slice.call(arguments, 0)); }, + + /** + * GreetService.Int64InIntOut + * + * @param _in {number} + * @returns {Promise} + **/ + Int64InIntOut: function(_in) { wails.CallByID(1343888303, ...Array.prototype.slice.call(arguments, 0)); }, + + /** + * GreetService.Int64PointerInAndOutput + * + * @param _in {number | null} + * @returns {Promise} + **/ + Int64PointerInAndOutput: function(_in) { wails.CallByID(2205561041, ...Array.prototype.slice.call(arguments, 0)); }, + + /** + * GreetService.Int8InIntOut + * + * @param _in {number} + * @returns {Promise} + **/ + Int8InIntOut: function(_in) { wails.CallByID(572240879, ...Array.prototype.slice.call(arguments, 0)); }, + + /** + * GreetService.Int8PointerInAndOutput + * + * @param _in {number | null} + * @returns {Promise} + **/ + Int8PointerInAndOutput: function(_in) { wails.CallByID(2189402897, ...Array.prototype.slice.call(arguments, 0)); }, + + /** + * GreetService.IntInIntOut + * + * @param _in {number} + * @returns {Promise} + **/ + IntInIntOut: function(_in) { wails.CallByID(642881729, ...Array.prototype.slice.call(arguments, 0)); }, + + /** + * GreetService.IntPointerInAndOutput + * + * @param _in {number | null} + * @returns {Promise} + **/ + IntPointerInAndOutput: function(_in) { wails.CallByID(1066151743, ...Array.prototype.slice.call(arguments, 0)); }, + + /** + * GreetService.IntPointerInputNamedOutputs + * + * @param _in {number | null} + * @returns {Promise} + **/ + IntPointerInputNamedOutputs: function(_in) { wails.CallByID(2718999663, ...Array.prototype.slice.call(arguments, 0)); }, + + /** + * GreetService.MapIntInt + * + * @param _in {map} + * @returns {Promise} + **/ + MapIntInt: function(_in) { wails.CallByID(2386486356, ...Array.prototype.slice.call(arguments, 0)); }, + + /** + * GreetService.MapIntPointerInt + * + * @param _in {map} + * @returns {Promise} + **/ + MapIntPointerInt: function(_in) { wails.CallByID(550413585, ...Array.prototype.slice.call(arguments, 0)); }, + + /** + * GreetService.MapIntSliceInt + * + * @param _in {map} + * @returns {Promise} + **/ + MapIntSliceInt: function(_in) { wails.CallByID(2900172572, ...Array.prototype.slice.call(arguments, 0)); }, + + /** + * GreetService.MapIntSliceIntInMapIntSliceIntOut + * + * @param _in {map} + * @returns {Promise} + **/ + MapIntSliceIntInMapIntSliceIntOut: function(_in) { wails.CallByID(881980169, ...Array.prototype.slice.call(arguments, 0)); }, + + /** + * GreetService.NoInputsStringOut + * + * + * @returns {Promise} + **/ + NoInputsStringOut: function() { wails.CallByID(1075577233, ...Array.prototype.slice.call(arguments, 0)); }, + + /** + * GreetService.PointerBoolInBoolOut + * + * @param _in {boolean | null} + * @returns {Promise} + **/ + PointerBoolInBoolOut: function(_in) { wails.CallByID(3589606958, ...Array.prototype.slice.call(arguments, 0)); }, + + /** + * GreetService.PointerFloat32InFloat32Out + * + * @param _in {number | null} + * @returns {Promise} + **/ + PointerFloat32InFloat32Out: function(_in) { wails.CallByID(224675106, ...Array.prototype.slice.call(arguments, 0)); }, + + /** + * GreetService.PointerFloat64InFloat64Out + * + * @param _in {number | null} + * @returns {Promise} + **/ + PointerFloat64InFloat64Out: function(_in) { wails.CallByID(2124953624, ...Array.prototype.slice.call(arguments, 0)); }, + + /** + * GreetService.PointerMapIntInt + * + * @param _in {map | null} + * @returns {Promise} + **/ + PointerMapIntInt: function(_in) { wails.CallByID(3516977899, ...Array.prototype.slice.call(arguments, 0)); }, + + /** + * GreetService.PointerStringInStringOut + * + * @param _in {string | null} + * @returns {Promise} + **/ + PointerStringInStringOut: function(_in) { wails.CallByID(229603958, ...Array.prototype.slice.call(arguments, 0)); }, + + /** + * GreetService.StringArrayInputNamedOutput + * + * @param _in {string[]} + * @returns {Promise} + **/ + StringArrayInputNamedOutput: function(_in) { wails.CallByID(3678582682, ...Array.prototype.slice.call(arguments, 0)); }, + + /** + * GreetService.StringArrayInputNamedOutputs + * + * @param _in {string[]} + * @returns {Promise} + **/ + StringArrayInputNamedOutputs: function(_in) { wails.CallByID(319259595, ...Array.prototype.slice.call(arguments, 0)); }, + + /** + * GreetService.StringArrayInputStringArrayOut + * + * @param _in {string[]} + * @returns {Promise} + **/ + StringArrayInputStringArrayOut: function(_in) { wails.CallByID(383995060, ...Array.prototype.slice.call(arguments, 0)); }, + + /** + * GreetService.StringArrayInputStringOut + * + * @param _in {string[]} + * @returns {Promise} + **/ + StringArrayInputStringOut: function(_in) { wails.CallByID(1091960237, ...Array.prototype.slice.call(arguments, 0)); }, + + /** + * GreetService.StructInputStructOutput + * + * @param _in {main.Person} + * @returns {Promise} + **/ + StructInputStructOutput: function(_in) { wails.CallByID(3835643147, ...Array.prototype.slice.call(arguments, 0)); }, + + /** + * GreetService.StructPointerInputErrorOutput + * + * @param _in {main.Person | null} + * @returns {Promise} + **/ + StructPointerInputErrorOutput: function(_in) { wails.CallByID(2447692557, ...Array.prototype.slice.call(arguments, 0)); }, + + /** + * GreetService.StructPointerInputStructPointerOutput + * + * @param _in {main.Person | null} + * @returns {Promise} + **/ + StructPointerInputStructPointerOutput: function(_in) { wails.CallByID(2943477349, ...Array.prototype.slice.call(arguments, 0)); }, + + /** + * GreetService.UInt16InUIntOut + * + * @param _in {number} + * @returns {Promise} + **/ + UInt16InUIntOut: function(_in) { wails.CallByID(3401034892, ...Array.prototype.slice.call(arguments, 0)); }, + + /** + * GreetService.UInt16PointerInAndOutput + * + * @param _in {number | null} + * @returns {Promise} + **/ + UInt16PointerInAndOutput: function(_in) { wails.CallByID(1236957573, ...Array.prototype.slice.call(arguments, 0)); }, + + /** + * GreetService.UInt32InUIntOut + * + * @param _in {number} + * @returns {Promise} + **/ + UInt32InUIntOut: function(_in) { wails.CallByID(1160383782, ...Array.prototype.slice.call(arguments, 0)); }, + + /** + * GreetService.UInt32PointerInAndOutput + * + * @param _in {number | null} + * @returns {Promise} + **/ + UInt32PointerInAndOutput: function(_in) { wails.CallByID(1739300671, ...Array.prototype.slice.call(arguments, 0)); }, + + /** + * GreetService.UInt64InUIntOut + * + * @param _in {number} + * @returns {Promise} + **/ + UInt64InUIntOut: function(_in) { wails.CallByID(793803239, ...Array.prototype.slice.call(arguments, 0)); }, + + /** + * GreetService.UInt64PointerInAndOutput + * + * @param _in {number | null} + * @returns {Promise} + **/ + UInt64PointerInAndOutput: function(_in) { wails.CallByID(1403757716, ...Array.prototype.slice.call(arguments, 0)); }, + + /** + * GreetService.UInt8InUIntOut + * + * @param _in {number} + * @returns {Promise} + **/ + UInt8InUIntOut: function(_in) { wails.CallByID(2988345717, ...Array.prototype.slice.call(arguments, 0)); }, + + /** + * GreetService.UInt8PointerInAndOutput + * + * @param _in {number | null} + * @returns {Promise} + **/ + UInt8PointerInAndOutput: function(_in) { wails.CallByID(518250834, ...Array.prototype.slice.call(arguments, 0)); }, + + /** + * GreetService.UIntInUIntOut + * + * @param _in {number} + * @returns {Promise} + **/ + UIntInUIntOut: function(_in) { wails.CallByID(2836661285, ...Array.prototype.slice.call(arguments, 0)); }, + + /** + * GreetService.UIntPointerInAndOutput + * + * @param _in {number | null} + * @returns {Promise} + **/ + UIntPointerInAndOutput: function(_in) { wails.CallByID(1367187362, ...Array.prototype.slice.call(arguments, 0)); }, + }, +}; + diff --git a/v3/internal/parser/testdata/struct_literal_non_pointer_single/main.go b/v3/internal/parser/testdata/struct_literal_non_pointer_single/main.go new file mode 100644 index 00000000..e417a7b6 --- /dev/null +++ b/v3/internal/parser/testdata/struct_literal_non_pointer_single/main.go @@ -0,0 +1,205 @@ +package main + +import ( + _ "embed" + "log" + "strings" + + "github.com/wailsapp/wails/v3/pkg/application" +) + +type Person struct { + Name string + Parent *Person + Details struct { + Age int + Address struct { + Street string + } + } +} + +// GreetService is great +type GreetService struct { + SomeVariable int + lowerCase string +} + +// Greet someone +func (GreetService) Greet(name string) string { + return "Hello " + name +} + +func (GreetService) NoInputsStringOut() string { + return "Hello" +} + +func (GreetService) StringArrayInputStringOut(in []string) string { + return strings.Join(in, ",") +} + +func (GreetService) StringArrayInputStringArrayOut(in []string) []string { + return in +} + +func (GreetService) StringArrayInputNamedOutput(in []string) (output []string) { + return in +} + +func (GreetService) StringArrayInputNamedOutputs(in []string) (output []string, err error) { + return in, nil +} + +func (GreetService) IntPointerInputNamedOutputs(in *int) (output *int, err error) { + return in, nil +} + +func (GreetService) UIntPointerInAndOutput(in *uint) *uint { + return in +} + +func (GreetService) UInt8PointerInAndOutput(in *uint8) *uint8 { + return in +} + +func (GreetService) UInt16PointerInAndOutput(in *uint16) *uint16 { + return in +} + +func (GreetService) UInt32PointerInAndOutput(in *uint32) *uint32 { + return in +} + +func (GreetService) UInt64PointerInAndOutput(in *uint64) *uint64 { + return in +} + +func (GreetService) IntPointerInAndOutput(in *int) *int { + return in +} + +func (GreetService) Int8PointerInAndOutput(in *int8) *int8 { + return in +} + +func (GreetService) Int16PointerInAndOutput(in *int16) *int16 { + return in +} + +func (GreetService) Int32PointerInAndOutput(in *int32) *int32 { + return in +} + +func (GreetService) Int64PointerInAndOutput(in *int64) *int64 { + return in +} + +func (GreetService) IntInIntOut(in int) int { + return in +} + +func (GreetService) Int8InIntOut(in int8) int8 { + return in +} +func (GreetService) Int16InIntOut(in int16) int16 { + return in +} +func (GreetService) Int32InIntOut(in int32) int32 { + return in +} +func (GreetService) Int64InIntOut(in int64) int64 { + return in +} + +func (GreetService) UIntInUIntOut(in uint) uint { + return in +} + +func (GreetService) UInt8InUIntOut(in uint8) uint8 { + return in +} +func (GreetService) UInt16InUIntOut(in uint16) uint16 { + return in +} +func (GreetService) UInt32InUIntOut(in uint32) uint32 { + return in +} +func (GreetService) UInt64InUIntOut(in uint64) uint64 { + return in +} + +func (GreetService) Float32InFloat32Out(in float32) float32 { + return in +} + +func (GreetService) Float64InFloat64Out(in float64) float64 { + return in +} + +func (GreetService) PointerFloat32InFloat32Out(in *float32) *float32 { + return in +} + +func (GreetService) PointerFloat64InFloat64Out(in *float64) *float64 { + return in +} + +func (GreetService) BoolInBoolOut(in bool) bool { + return in +} + +func (GreetService) PointerBoolInBoolOut(in *bool) *bool { + return in +} + +func (GreetService) PointerStringInStringOut(in *string) *string { + return in +} + +func (GreetService) StructPointerInputErrorOutput(in *Person) error { + return nil +} + +func (GreetService) StructInputStructOutput(in Person) Person { + return in +} + +func (GreetService) StructPointerInputStructPointerOutput(in *Person) *Person { + return in +} + +func (GreetService) MapIntInt(in map[int]int) { +} + +func (GreetService) PointerMapIntInt(in *map[int]int) { +} + +func (GreetService) MapIntPointerInt(in map[*int]int) { +} + +func (GreetService) MapIntSliceInt(in map[int][]int) { +} + +func (GreetService) MapIntSliceIntInMapIntSliceIntOut(in map[int][]int) (out map[int][]int) { + return nil +} + +func (GreetService) ArrayInt(in [4]int) { +} + +func main() { + app := application.New(application.Options{ + Bind: []interface{}{ + &GreetService{}, + }, + }) + + app.NewWebviewWindow() + + err := app.Run() + + if err != nil { + log.Fatal(err) + } + +} diff --git a/v3/internal/parser/testdata/struct_literal_non_pointer_single/models.ts b/v3/internal/parser/testdata/struct_literal_non_pointer_single/models.ts new file mode 100644 index 00000000..91bab56a --- /dev/null +++ b/v3/internal/parser/testdata/struct_literal_non_pointer_single/models.ts @@ -0,0 +1,64 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +export namespace main { + + export class Person { + name: string; + parent: Person; + details: anon1; + + static createFrom(source: any = {}) { + return new Person(source); + } + + constructor(source: any = {}) { + if ('string' === typeof source) { + source = JSON.parse(source); + } + + this.name = source['name']; + this.parent = Person.createFrom(source['parent']); + this.details = anon1.createFrom(source['details']); + + } + } + + export class anon1 { + age: number; + address: anon2; + + static createFrom(source: any = {}) { + return new anon1(source); + } + + constructor(source: any = {}) { + if ('string' === typeof source) { + source = JSON.parse(source); + } + + this.age = source['age']; + this.address = anon2.createFrom(source['address']); + + } + } + + export class anon2 { + street: string; + + static createFrom(source: any = {}) { + return new anon2(source); + } + + constructor(source: any = {}) { + if ('string' === typeof source) { + source = JSON.parse(source); + } + + this.street = source['street']; + + } + } + +}