From f1a7f1b7817d62934d64948df2466f0ea474ed10 Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Mon, 6 Mar 2023 20:54:04 +1100 Subject: [PATCH] Improved bindings generation --- v3/internal/parser/bindings.go | 92 +++- v3/internal/parser/bindings_test.go | 27 +- .../bindings.js | 66 +++ .../testdata/function_single/bindings.js | 29 + .../struct_literal_multiple/bindings.js | 50 ++ .../struct_literal_multiple_files/bindings.js | 50 ++ .../struct_literal_multiple_other/bindings.js | 66 +++ .../struct_literal_single/bindings.js | 494 ++++++++++++++++++ .../testdata/variable_single/bindings.js | 29 + .../variable_single_from_function/bindings.js | 29 + .../bindings.js | 66 +++ 11 files changed, 981 insertions(+), 17 deletions(-) create mode 100644 v3/internal/parser/testdata/function_from_imported_package/bindings.js create mode 100644 v3/internal/parser/testdata/function_single/bindings.js create mode 100644 v3/internal/parser/testdata/struct_literal_multiple/bindings.js create mode 100644 v3/internal/parser/testdata/struct_literal_multiple_files/bindings.js create mode 100644 v3/internal/parser/testdata/struct_literal_multiple_other/bindings.js create mode 100644 v3/internal/parser/testdata/struct_literal_single/bindings.js create mode 100644 v3/internal/parser/testdata/variable_single/bindings.js create mode 100644 v3/internal/parser/testdata/variable_single_from_function/bindings.js create mode 100644 v3/internal/parser/testdata/variable_single_from_other_function/bindings.js diff --git a/v3/internal/parser/bindings.go b/v3/internal/parser/bindings.go index a6c513e19..25101c1b2 100644 --- a/v3/internal/parser/bindings.go +++ b/v3/internal/parser/bindings.go @@ -1,11 +1,19 @@ package parser import ( + "sort" + "strconv" "strings" "github.com/samber/lo" ) +const header = `// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +` + const helperTemplate = `function {{structName}}(method) { return { packageName: "{{packageName}}", @@ -115,38 +123,100 @@ func getPackageName(input *Parameter) string { return result } +func normalisePackageNames(packageNames []string) map[string]string { + // We iterate over the package names and determine if any of them + // have a forward slash. If this is the case, we assume that the + // package name is the last element of the path. If this has already + // been found, then we need to add a digit to the end of the package + // name to make it unique. We return a map of the original package + // name to the new package name. + var result = make(map[string]string) + var packagesConverted = make(map[string]struct{}) + var count = 1 + for _, packageName := range packageNames { + var originalPackageName = packageName + if strings.Contains(packageName, "/") { + parts := strings.Split(packageName, "/") + packageName = parts[len(parts)-1] + } + if _, ok := packagesConverted[packageName]; ok { + // We've already seen this package name. Add a digit + // to the end of the package name to make it unique + count += 1 + packageName += strconv.Itoa(count) + + } + packagesConverted[packageName] = struct{}{} + result[originalPackageName] = packageName + } + + return result +} + func GenerateBindings(bindings map[string]map[string][]*BoundMethod) string { var result string var allModels []string - for packageName, packageBindings := range bindings { - for structName, bindings := range packageBindings { - result += GenerateHelper(packageName, structName) - for _, binding := range bindings { - thisBinding, models := GenerateBinding(structName, binding) + var normalisedPackageNames = normalisePackageNames(lo.Keys(bindings)) + // sort the bindings keys + packageNames := lo.Keys(bindings) + sort.Strings(packageNames) + for _, packageName := range packageNames { + packageBindings := bindings[packageName] + structNames := lo.Keys(packageBindings) + sort.Strings(structNames) + for _, structName := range structNames { + result += GenerateHelper(normalisedPackageNames[packageName], structName) + methods := packageBindings[structName] + sort.Slice(methods, func(i, j int) bool { + return methods[i].Name < methods[j].Name + }) + for _, method := range methods { + thisBinding, models := GenerateBinding(structName, method) result += thisBinding allModels = append(allModels, models...) } } } + result += ` window.go = window.go || {}; ` - for packageName, packageBindings := range bindings { - result += "Object.window.go." + packageName + " = {\n" - for structName, methods := range packageBindings { + // Iterate over the sorted bindings keys + packageNames = lo.Keys(bindings) + for _, packageName := range packageNames { + packageBindings := bindings[packageName] + structNames := lo.Keys(packageBindings) + sort.Strings(structNames) + result += "window.go." + normalisedPackageNames[packageName] + " = {\n" + for _, structName := range structNames { result += " " + structName + ": {\n" + methods := packageBindings[structName] + sort.Slice(methods, func(i, j int) bool { + return methods[i].Name < methods[j].Name + }) for _, method := range methods { result += " " + method.Name + ",\n" } - result += " }\n" + result += " },\n" } result += "};\n" } // add imports - imports := "import {" + strings.Join(lo.Uniq(allModels), ", ") + "} from './models';\n" - result = imports + "\n" + result + if len(allModels) > 0 { + allModels := lo.Uniq(allModels) + var models []string + for _, model := range allModels { + models = append(models, normalisedPackageNames[model]) + } + sort.Strings(models) + result += "\n" + imports := "import {" + strings.Join(models, ", ") + "} from './models';\n" + result = imports + "\n" + result + } + + result = header + result return result } diff --git a/v3/internal/parser/bindings_test.go b/v3/internal/parser/bindings_test.go index fc7100d8c..9b9054431 100644 --- a/v3/internal/parser/bindings_test.go +++ b/v3/internal/parser/bindings_test.go @@ -11,6 +11,14 @@ func TestGenerateBindings(t *testing.T) { tests := []string{ "struct_literal_single", + "struct_literal_multiple", + "struct_literal_multiple_other", + "struct_literal_multiple_files", + "function_single", + "function_from_imported_package", + "variable_single", + "variable_single_from_function", + "variable_single_from_other_function", } for _, projectDir := range tests { t.Run(projectDir, func(t *testing.T) { @@ -24,21 +32,28 @@ func TestGenerateBindings(t *testing.T) { // Generate Bindings got := GenerateBindings(project.BoundMethods) - // Write file to project directory - err = os.WriteFile(projectDir+"/bindings.got.js", []byte(got), 0644) - if err != nil { - t.Errorf("os.WriteFile() error = %v", err) - return - } + // Load bindings.js from project directory expected, err := os.ReadFile(projectDir + "/bindings.js") if err != nil { + // Write file to project directory + err = os.WriteFile(projectDir+"/bindings.got.js", []byte(got), 0644) + if err != nil { + t.Errorf("os.WriteFile() error = %v", err) + return + } t.Errorf("os.ReadFile() error = %v", err) return } // Compare if diff := cmp.Diff(string(expected), got); diff != "" { + // Write file to project directory + err = os.WriteFile(projectDir+"/bindings.got.js", []byte(got), 0644) + if err != nil { + t.Errorf("os.WriteFile() error = %v", err) + return + } t.Fatalf("GenerateService() mismatch (-want +got):\n%s", diff) } }) diff --git a/v3/internal/parser/testdata/function_from_imported_package/bindings.js b/v3/internal/parser/testdata/function_from_imported_package/bindings.js new file mode 100644 index 000000000..574988d22 --- /dev/null +++ b/v3/internal/parser/testdata/function_from_imported_package/bindings.js @@ -0,0 +1,66 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +import {main, services} from './models'; + +function OtherService(method) { + return { + packageName: "services", + serviceName: "OtherService", + methodName: method, + args: Array.prototype.slice.call(arguments, 1), + }; +} + +/** + * OtherService.Yay + * + * + * @returns {Promise} + **/ +function Yay() { + return wails.Call(OtherService("Yay")); +} +function GreetService(method) { + return { + packageName: "main", + serviceName: "GreetService", + methodName: method, + args: Array.prototype.slice.call(arguments, 1), + }; +} + +/** + * GreetService.Greet + * Greet does XYZ + * @param name {string} + * @returns {Promise} + **/ +function Greet(name) { + return wails.Call(GreetService("Greet", name)); +} + +/** + * GreetService.NewPerson + * NewPerson creates a new person + * @param name {string} + * @returns {Promise} + **/ +function NewPerson(name) { + return wails.Call(GreetService("NewPerson", name)); +} + +window.go = window.go || {}; +window.go.main = { + GreetService: { + Greet, + NewPerson, + }, +}; +window.go.services = { + OtherService: { + Yay, + }, +}; + diff --git a/v3/internal/parser/testdata/function_single/bindings.js b/v3/internal/parser/testdata/function_single/bindings.js new file mode 100644 index 000000000..0a156d149 --- /dev/null +++ b/v3/internal/parser/testdata/function_single/bindings.js @@ -0,0 +1,29 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +function GreetService(method) { + return { + packageName: "main", + serviceName: "GreetService", + methodName: method, + args: Array.prototype.slice.call(arguments, 1), + }; +} + +/** + * GreetService.Greet + * Greet someone + * @param name {string} + * @returns {Promise} + **/ +function Greet(name) { + return wails.Call(GreetService("Greet", name)); +} + +window.go = window.go || {}; +window.go.main = { + GreetService: { + Greet, + }, +}; diff --git a/v3/internal/parser/testdata/struct_literal_multiple/bindings.js b/v3/internal/parser/testdata/struct_literal_multiple/bindings.js new file mode 100644 index 000000000..277073941 --- /dev/null +++ b/v3/internal/parser/testdata/struct_literal_multiple/bindings.js @@ -0,0 +1,50 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +function GreetService(method) { + return { + packageName: "main", + serviceName: "GreetService", + methodName: method, + args: Array.prototype.slice.call(arguments, 1), + }; +} + +/** + * GreetService.Greet + * + * @param name {string} + * @returns {Promise} + **/ +function Greet(name) { + return wails.Call(GreetService("Greet", name)); +} +function OtherService(method) { + return { + packageName: "main", + serviceName: "OtherService", + methodName: method, + args: Array.prototype.slice.call(arguments, 1), + }; +} + +/** + * OtherService.Hello + * + * + * @returns {Promise} + **/ +function Hello() { + return wails.Call(OtherService("Hello")); +} + +window.go = window.go || {}; +window.go.main = { + GreetService: { + Greet, + }, + OtherService: { + Hello, + }, +}; diff --git a/v3/internal/parser/testdata/struct_literal_multiple_files/bindings.js b/v3/internal/parser/testdata/struct_literal_multiple_files/bindings.js new file mode 100644 index 000000000..277073941 --- /dev/null +++ b/v3/internal/parser/testdata/struct_literal_multiple_files/bindings.js @@ -0,0 +1,50 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +function GreetService(method) { + return { + packageName: "main", + serviceName: "GreetService", + methodName: method, + args: Array.prototype.slice.call(arguments, 1), + }; +} + +/** + * GreetService.Greet + * + * @param name {string} + * @returns {Promise} + **/ +function Greet(name) { + return wails.Call(GreetService("Greet", name)); +} +function OtherService(method) { + return { + packageName: "main", + serviceName: "OtherService", + methodName: method, + args: Array.prototype.slice.call(arguments, 1), + }; +} + +/** + * OtherService.Hello + * + * + * @returns {Promise} + **/ +function Hello() { + return wails.Call(OtherService("Hello")); +} + +window.go = window.go || {}; +window.go.main = { + GreetService: { + Greet, + }, + OtherService: { + Hello, + }, +}; diff --git a/v3/internal/parser/testdata/struct_literal_multiple_other/bindings.js b/v3/internal/parser/testdata/struct_literal_multiple_other/bindings.js new file mode 100644 index 000000000..574988d22 --- /dev/null +++ b/v3/internal/parser/testdata/struct_literal_multiple_other/bindings.js @@ -0,0 +1,66 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +import {main, services} from './models'; + +function OtherService(method) { + return { + packageName: "services", + serviceName: "OtherService", + methodName: method, + args: Array.prototype.slice.call(arguments, 1), + }; +} + +/** + * OtherService.Yay + * + * + * @returns {Promise} + **/ +function Yay() { + return wails.Call(OtherService("Yay")); +} +function GreetService(method) { + return { + packageName: "main", + serviceName: "GreetService", + methodName: method, + args: Array.prototype.slice.call(arguments, 1), + }; +} + +/** + * GreetService.Greet + * Greet does XYZ + * @param name {string} + * @returns {Promise} + **/ +function Greet(name) { + return wails.Call(GreetService("Greet", name)); +} + +/** + * GreetService.NewPerson + * NewPerson creates a new person + * @param name {string} + * @returns {Promise} + **/ +function NewPerson(name) { + return wails.Call(GreetService("NewPerson", name)); +} + +window.go = window.go || {}; +window.go.main = { + GreetService: { + Greet, + NewPerson, + }, +}; +window.go.services = { + OtherService: { + Yay, + }, +}; + diff --git a/v3/internal/parser/testdata/struct_literal_single/bindings.js b/v3/internal/parser/testdata/struct_literal_single/bindings.js new file mode 100644 index 000000000..5b3fcd587 --- /dev/null +++ b/v3/internal/parser/testdata/struct_literal_single/bindings.js @@ -0,0 +1,494 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +import {main} from './models'; + +function GreetService(method) { + return { + packageName: "main", + serviceName: "GreetService", + methodName: method, + args: Array.prototype.slice.call(arguments, 1), + }; +} + +/** + * GreetService.ArrayInt + * + * @param _in {number[]} + * @returns {Promise} + **/ +function ArrayInt(_in) { + return wails.Call(GreetService("ArrayInt", _in)); +} + +/** + * GreetService.BoolInBoolOut + * + * @param _in {boolean} + * @returns {Promise} + **/ +function BoolInBoolOut(_in) { + return wails.Call(GreetService("BoolInBoolOut", _in)); +} + +/** + * GreetService.Float32InFloat32Out + * + * @param _in {number} + * @returns {Promise} + **/ +function Float32InFloat32Out(_in) { + return wails.Call(GreetService("Float32InFloat32Out", _in)); +} + +/** + * GreetService.Float64InFloat64Out + * + * @param _in {number} + * @returns {Promise} + **/ +function Float64InFloat64Out(_in) { + return wails.Call(GreetService("Float64InFloat64Out", _in)); +} + +/** + * GreetService.Greet + * Greet someone + * @param name {string} + * @returns {Promise} + **/ +function Greet(name) { + return wails.Call(GreetService("Greet", name)); +} + +/** + * GreetService.Int16InIntOut + * + * @param _in {number} + * @returns {Promise} + **/ +function Int16InIntOut(_in) { + return wails.Call(GreetService("Int16InIntOut", _in)); +} + +/** + * GreetService.Int16PointerInAndOutput + * + * @param _in {number | null} + * @returns {Promise} + **/ +function Int16PointerInAndOutput(_in) { + return wails.Call(GreetService("Int16PointerInAndOutput", _in)); +} + +/** + * GreetService.Int32InIntOut + * + * @param _in {number} + * @returns {Promise} + **/ +function Int32InIntOut(_in) { + return wails.Call(GreetService("Int32InIntOut", _in)); +} + +/** + * GreetService.Int32PointerInAndOutput + * + * @param _in {number | null} + * @returns {Promise} + **/ +function Int32PointerInAndOutput(_in) { + return wails.Call(GreetService("Int32PointerInAndOutput", _in)); +} + +/** + * GreetService.Int64InIntOut + * + * @param _in {number} + * @returns {Promise} + **/ +function Int64InIntOut(_in) { + return wails.Call(GreetService("Int64InIntOut", _in)); +} + +/** + * GreetService.Int64PointerInAndOutput + * + * @param _in {number | null} + * @returns {Promise} + **/ +function Int64PointerInAndOutput(_in) { + return wails.Call(GreetService("Int64PointerInAndOutput", _in)); +} + +/** + * GreetService.Int8InIntOut + * + * @param _in {number} + * @returns {Promise} + **/ +function Int8InIntOut(_in) { + return wails.Call(GreetService("Int8InIntOut", _in)); +} + +/** + * GreetService.Int8PointerInAndOutput + * + * @param _in {number | null} + * @returns {Promise} + **/ +function Int8PointerInAndOutput(_in) { + return wails.Call(GreetService("Int8PointerInAndOutput", _in)); +} + +/** + * GreetService.IntInIntOut + * + * @param _in {number} + * @returns {Promise} + **/ +function IntInIntOut(_in) { + return wails.Call(GreetService("IntInIntOut", _in)); +} + +/** + * GreetService.IntPointerInAndOutput + * + * @param _in {number | null} + * @returns {Promise} + **/ +function IntPointerInAndOutput(_in) { + return wails.Call(GreetService("IntPointerInAndOutput", _in)); +} + +/** + * GreetService.IntPointerInputNamedOutputs + * + * @param _in {number | null} + * @returns {Promise} + **/ +function IntPointerInputNamedOutputs(_in) { + return wails.Call(GreetService("IntPointerInputNamedOutputs", _in)); +} + +/** + * GreetService.MapIntInt + * + * @param _in {map} + * @returns {Promise} + **/ +function MapIntInt(_in) { + return wails.Call(GreetService("MapIntInt", _in)); +} + +/** + * GreetService.MapIntPointerInt + * + * @param _in {map} + * @returns {Promise} + **/ +function MapIntPointerInt(_in) { + return wails.Call(GreetService("MapIntPointerInt", _in)); +} + +/** + * GreetService.MapIntSliceInt + * + * @param _in {map} + * @returns {Promise} + **/ +function MapIntSliceInt(_in) { + return wails.Call(GreetService("MapIntSliceInt", _in)); +} + +/** + * GreetService.MapIntSliceIntInMapIntSliceIntOut + * + * @param _in {map} + * @returns {Promise} + **/ +function MapIntSliceIntInMapIntSliceIntOut(_in) { + return wails.Call(GreetService("MapIntSliceIntInMapIntSliceIntOut", _in)); +} + +/** + * GreetService.NoInputsStringOut + * + * + * @returns {Promise} + **/ +function NoInputsStringOut() { + return wails.Call(GreetService("NoInputsStringOut")); +} + +/** + * GreetService.PointerBoolInBoolOut + * + * @param _in {boolean | null} + * @returns {Promise} + **/ +function PointerBoolInBoolOut(_in) { + return wails.Call(GreetService("PointerBoolInBoolOut", _in)); +} + +/** + * GreetService.PointerFloat32InFloat32Out + * + * @param _in {number | null} + * @returns {Promise} + **/ +function PointerFloat32InFloat32Out(_in) { + return wails.Call(GreetService("PointerFloat32InFloat32Out", _in)); +} + +/** + * GreetService.PointerFloat64InFloat64Out + * + * @param _in {number | null} + * @returns {Promise} + **/ +function PointerFloat64InFloat64Out(_in) { + return wails.Call(GreetService("PointerFloat64InFloat64Out", _in)); +} + +/** + * GreetService.PointerMapIntInt + * + * @param _in {map | null} + * @returns {Promise} + **/ +function PointerMapIntInt(_in) { + return wails.Call(GreetService("PointerMapIntInt", _in)); +} + +/** + * GreetService.PointerStringInStringOut + * + * @param _in {string | null} + * @returns {Promise} + **/ +function PointerStringInStringOut(_in) { + return wails.Call(GreetService("PointerStringInStringOut", _in)); +} + +/** + * GreetService.StringArrayInputNamedOutput + * + * @param _in {string[]} + * @returns {Promise} + **/ +function StringArrayInputNamedOutput(_in) { + return wails.Call(GreetService("StringArrayInputNamedOutput", _in)); +} + +/** + * GreetService.StringArrayInputNamedOutputs + * + * @param _in {string[]} + * @returns {Promise} + **/ +function StringArrayInputNamedOutputs(_in) { + return wails.Call(GreetService("StringArrayInputNamedOutputs", _in)); +} + +/** + * GreetService.StringArrayInputStringArrayOut + * + * @param _in {string[]} + * @returns {Promise} + **/ +function StringArrayInputStringArrayOut(_in) { + return wails.Call(GreetService("StringArrayInputStringArrayOut", _in)); +} + +/** + * GreetService.StringArrayInputStringOut + * + * @param _in {string[]} + * @returns {Promise} + **/ +function StringArrayInputStringOut(_in) { + return wails.Call(GreetService("StringArrayInputStringOut", _in)); +} + +/** + * GreetService.StructInputStructOutput + * + * @param _in {main.Person} + * @returns {Promise} + **/ +function StructInputStructOutput(_in) { + return wails.Call(GreetService("StructInputStructOutput", _in)); +} + +/** + * GreetService.StructPointerInputErrorOutput + * + * @param _in {main.Person | null} + * @returns {Promise} + **/ +function StructPointerInputErrorOutput(_in) { + return wails.Call(GreetService("StructPointerInputErrorOutput", _in)); +} + +/** + * GreetService.StructPointerInputStructPointerOutput + * + * @param _in {main.Person | null} + * @returns {Promise} + **/ +function StructPointerInputStructPointerOutput(_in) { + return wails.Call(GreetService("StructPointerInputStructPointerOutput", _in)); +} + +/** + * GreetService.UInt16InUIntOut + * + * @param _in {number} + * @returns {Promise} + **/ +function UInt16InUIntOut(_in) { + return wails.Call(GreetService("UInt16InUIntOut", _in)); +} + +/** + * GreetService.UInt16PointerInAndOutput + * + * @param _in {number | null} + * @returns {Promise} + **/ +function UInt16PointerInAndOutput(_in) { + return wails.Call(GreetService("UInt16PointerInAndOutput", _in)); +} + +/** + * GreetService.UInt32InUIntOut + * + * @param _in {number} + * @returns {Promise} + **/ +function UInt32InUIntOut(_in) { + return wails.Call(GreetService("UInt32InUIntOut", _in)); +} + +/** + * GreetService.UInt32PointerInAndOutput + * + * @param _in {number | null} + * @returns {Promise} + **/ +function UInt32PointerInAndOutput(_in) { + return wails.Call(GreetService("UInt32PointerInAndOutput", _in)); +} + +/** + * GreetService.UInt64InUIntOut + * + * @param _in {number} + * @returns {Promise} + **/ +function UInt64InUIntOut(_in) { + return wails.Call(GreetService("UInt64InUIntOut", _in)); +} + +/** + * GreetService.UInt64PointerInAndOutput + * + * @param _in {number | null} + * @returns {Promise} + **/ +function UInt64PointerInAndOutput(_in) { + return wails.Call(GreetService("UInt64PointerInAndOutput", _in)); +} + +/** + * GreetService.UInt8InUIntOut + * + * @param _in {number} + * @returns {Promise} + **/ +function UInt8InUIntOut(_in) { + return wails.Call(GreetService("UInt8InUIntOut", _in)); +} + +/** + * GreetService.UInt8PointerInAndOutput + * + * @param _in {number | null} + * @returns {Promise} + **/ +function UInt8PointerInAndOutput(_in) { + return wails.Call(GreetService("UInt8PointerInAndOutput", _in)); +} + +/** + * GreetService.UIntInUIntOut + * + * @param _in {number} + * @returns {Promise} + **/ +function UIntInUIntOut(_in) { + return wails.Call(GreetService("UIntInUIntOut", _in)); +} + +/** + * GreetService.UIntPointerInAndOutput + * + * @param _in {number | null} + * @returns {Promise} + **/ +function UIntPointerInAndOutput(_in) { + return wails.Call(GreetService("UIntPointerInAndOutput", _in)); +} + +window.go = window.go || {}; +window.go.main = { + GreetService: { + ArrayInt, + BoolInBoolOut, + Float32InFloat32Out, + Float64InFloat64Out, + Greet, + Int16InIntOut, + Int16PointerInAndOutput, + Int32InIntOut, + Int32PointerInAndOutput, + Int64InIntOut, + Int64PointerInAndOutput, + Int8InIntOut, + Int8PointerInAndOutput, + IntInIntOut, + IntPointerInAndOutput, + IntPointerInputNamedOutputs, + MapIntInt, + MapIntPointerInt, + MapIntSliceInt, + MapIntSliceIntInMapIntSliceIntOut, + NoInputsStringOut, + PointerBoolInBoolOut, + PointerFloat32InFloat32Out, + PointerFloat64InFloat64Out, + PointerMapIntInt, + PointerStringInStringOut, + StringArrayInputNamedOutput, + StringArrayInputNamedOutputs, + StringArrayInputStringArrayOut, + StringArrayInputStringOut, + StructInputStructOutput, + StructPointerInputErrorOutput, + StructPointerInputStructPointerOutput, + UInt16InUIntOut, + UInt16PointerInAndOutput, + UInt32InUIntOut, + UInt32PointerInAndOutput, + UInt64InUIntOut, + UInt64PointerInAndOutput, + UInt8InUIntOut, + UInt8PointerInAndOutput, + UIntInUIntOut, + UIntPointerInAndOutput, + }, +}; + diff --git a/v3/internal/parser/testdata/variable_single/bindings.js b/v3/internal/parser/testdata/variable_single/bindings.js new file mode 100644 index 000000000..0a156d149 --- /dev/null +++ b/v3/internal/parser/testdata/variable_single/bindings.js @@ -0,0 +1,29 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +function GreetService(method) { + return { + packageName: "main", + serviceName: "GreetService", + methodName: method, + args: Array.prototype.slice.call(arguments, 1), + }; +} + +/** + * GreetService.Greet + * Greet someone + * @param name {string} + * @returns {Promise} + **/ +function Greet(name) { + return wails.Call(GreetService("Greet", name)); +} + +window.go = window.go || {}; +window.go.main = { + GreetService: { + Greet, + }, +}; diff --git a/v3/internal/parser/testdata/variable_single_from_function/bindings.js b/v3/internal/parser/testdata/variable_single_from_function/bindings.js new file mode 100644 index 000000000..0a156d149 --- /dev/null +++ b/v3/internal/parser/testdata/variable_single_from_function/bindings.js @@ -0,0 +1,29 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +function GreetService(method) { + return { + packageName: "main", + serviceName: "GreetService", + methodName: method, + args: Array.prototype.slice.call(arguments, 1), + }; +} + +/** + * GreetService.Greet + * Greet someone + * @param name {string} + * @returns {Promise} + **/ +function Greet(name) { + return wails.Call(GreetService("Greet", name)); +} + +window.go = window.go || {}; +window.go.main = { + GreetService: { + Greet, + }, +}; diff --git a/v3/internal/parser/testdata/variable_single_from_other_function/bindings.js b/v3/internal/parser/testdata/variable_single_from_other_function/bindings.js new file mode 100644 index 000000000..574988d22 --- /dev/null +++ b/v3/internal/parser/testdata/variable_single_from_other_function/bindings.js @@ -0,0 +1,66 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +import {main, services} from './models'; + +function OtherService(method) { + return { + packageName: "services", + serviceName: "OtherService", + methodName: method, + args: Array.prototype.slice.call(arguments, 1), + }; +} + +/** + * OtherService.Yay + * + * + * @returns {Promise} + **/ +function Yay() { + return wails.Call(OtherService("Yay")); +} +function GreetService(method) { + return { + packageName: "main", + serviceName: "GreetService", + methodName: method, + args: Array.prototype.slice.call(arguments, 1), + }; +} + +/** + * GreetService.Greet + * Greet does XYZ + * @param name {string} + * @returns {Promise} + **/ +function Greet(name) { + return wails.Call(GreetService("Greet", name)); +} + +/** + * GreetService.NewPerson + * NewPerson creates a new person + * @param name {string} + * @returns {Promise} + **/ +function NewPerson(name) { + return wails.Call(GreetService("NewPerson", name)); +} + +window.go = window.go || {}; +window.go.main = { + GreetService: { + Greet, + NewPerson, + }, +}; +window.go.services = { + OtherService: { + Yay, + }, +}; +