mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-02 20:03:01 +08:00
Improved bindings generation
This commit is contained in:
parent
71aa7c9731
commit
f1a7f1b781
@ -1,11 +1,19 @@
|
|||||||
package parser
|
package parser
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"sort"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/samber/lo"
|
"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) {
|
const helperTemplate = `function {{structName}}(method) {
|
||||||
return {
|
return {
|
||||||
packageName: "{{packageName}}",
|
packageName: "{{packageName}}",
|
||||||
@ -115,38 +123,100 @@ func getPackageName(input *Parameter) string {
|
|||||||
return result
|
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 {
|
func GenerateBindings(bindings map[string]map[string][]*BoundMethod) string {
|
||||||
|
|
||||||
var result string
|
var result string
|
||||||
var allModels []string
|
var allModels []string
|
||||||
for packageName, packageBindings := range bindings {
|
var normalisedPackageNames = normalisePackageNames(lo.Keys(bindings))
|
||||||
for structName, bindings := range packageBindings {
|
// sort the bindings keys
|
||||||
result += GenerateHelper(packageName, structName)
|
packageNames := lo.Keys(bindings)
|
||||||
for _, binding := range bindings {
|
sort.Strings(packageNames)
|
||||||
thisBinding, models := GenerateBinding(structName, binding)
|
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
|
result += thisBinding
|
||||||
allModels = append(allModels, models...)
|
allModels = append(allModels, models...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result += `
|
result += `
|
||||||
window.go = window.go || {};
|
window.go = window.go || {};
|
||||||
`
|
`
|
||||||
for packageName, packageBindings := range bindings {
|
// Iterate over the sorted bindings keys
|
||||||
result += "Object.window.go." + packageName + " = {\n"
|
packageNames = lo.Keys(bindings)
|
||||||
for structName, methods := range packageBindings {
|
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"
|
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 {
|
for _, method := range methods {
|
||||||
result += " " + method.Name + ",\n"
|
result += " " + method.Name + ",\n"
|
||||||
}
|
}
|
||||||
result += " }\n"
|
result += " },\n"
|
||||||
}
|
}
|
||||||
result += "};\n"
|
result += "};\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
// add imports
|
// add imports
|
||||||
imports := "import {" + strings.Join(lo.Uniq(allModels), ", ") + "} from './models';\n"
|
if len(allModels) > 0 {
|
||||||
result = imports + "\n" + result
|
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
|
return result
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,14 @@ func TestGenerateBindings(t *testing.T) {
|
|||||||
|
|
||||||
tests := []string{
|
tests := []string{
|
||||||
"struct_literal_single",
|
"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 {
|
for _, projectDir := range tests {
|
||||||
t.Run(projectDir, func(t *testing.T) {
|
t.Run(projectDir, func(t *testing.T) {
|
||||||
@ -24,21 +32,28 @@ func TestGenerateBindings(t *testing.T) {
|
|||||||
|
|
||||||
// Generate Bindings
|
// Generate Bindings
|
||||||
got := GenerateBindings(project.BoundMethods)
|
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
|
// Load bindings.js from project directory
|
||||||
expected, err := os.ReadFile(projectDir + "/bindings.js")
|
expected, err := os.ReadFile(projectDir + "/bindings.js")
|
||||||
if err != nil {
|
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)
|
t.Errorf("os.ReadFile() error = %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compare
|
// Compare
|
||||||
if diff := cmp.Diff(string(expected), got); diff != "" {
|
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)
|
t.Fatalf("GenerateService() mismatch (-want +got):\n%s", diff)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
66
v3/internal/parser/testdata/function_from_imported_package/bindings.js
vendored
Normal file
66
v3/internal/parser/testdata/function_from_imported_package/bindings.js
vendored
Normal file
@ -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<services.Address | null>}
|
||||||
|
**/
|
||||||
|
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<string>}
|
||||||
|
**/
|
||||||
|
function Greet(name) {
|
||||||
|
return wails.Call(GreetService("Greet", name));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GreetService.NewPerson
|
||||||
|
* NewPerson creates a new person
|
||||||
|
* @param name {string}
|
||||||
|
* @returns {Promise<main.Person | null>}
|
||||||
|
**/
|
||||||
|
function NewPerson(name) {
|
||||||
|
return wails.Call(GreetService("NewPerson", name));
|
||||||
|
}
|
||||||
|
|
||||||
|
window.go = window.go || {};
|
||||||
|
window.go.main = {
|
||||||
|
GreetService: {
|
||||||
|
Greet,
|
||||||
|
NewPerson,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
window.go.services = {
|
||||||
|
OtherService: {
|
||||||
|
Yay,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
29
v3/internal/parser/testdata/function_single/bindings.js
vendored
Normal file
29
v3/internal/parser/testdata/function_single/bindings.js
vendored
Normal file
@ -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<string>}
|
||||||
|
**/
|
||||||
|
function Greet(name) {
|
||||||
|
return wails.Call(GreetService("Greet", name));
|
||||||
|
}
|
||||||
|
|
||||||
|
window.go = window.go || {};
|
||||||
|
window.go.main = {
|
||||||
|
GreetService: {
|
||||||
|
Greet,
|
||||||
|
},
|
||||||
|
};
|
50
v3/internal/parser/testdata/struct_literal_multiple/bindings.js
vendored
Normal file
50
v3/internal/parser/testdata/struct_literal_multiple/bindings.js
vendored
Normal file
@ -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<string>}
|
||||||
|
**/
|
||||||
|
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<void>}
|
||||||
|
**/
|
||||||
|
function Hello() {
|
||||||
|
return wails.Call(OtherService("Hello"));
|
||||||
|
}
|
||||||
|
|
||||||
|
window.go = window.go || {};
|
||||||
|
window.go.main = {
|
||||||
|
GreetService: {
|
||||||
|
Greet,
|
||||||
|
},
|
||||||
|
OtherService: {
|
||||||
|
Hello,
|
||||||
|
},
|
||||||
|
};
|
50
v3/internal/parser/testdata/struct_literal_multiple_files/bindings.js
vendored
Normal file
50
v3/internal/parser/testdata/struct_literal_multiple_files/bindings.js
vendored
Normal file
@ -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<string>}
|
||||||
|
**/
|
||||||
|
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<void>}
|
||||||
|
**/
|
||||||
|
function Hello() {
|
||||||
|
return wails.Call(OtherService("Hello"));
|
||||||
|
}
|
||||||
|
|
||||||
|
window.go = window.go || {};
|
||||||
|
window.go.main = {
|
||||||
|
GreetService: {
|
||||||
|
Greet,
|
||||||
|
},
|
||||||
|
OtherService: {
|
||||||
|
Hello,
|
||||||
|
},
|
||||||
|
};
|
66
v3/internal/parser/testdata/struct_literal_multiple_other/bindings.js
vendored
Normal file
66
v3/internal/parser/testdata/struct_literal_multiple_other/bindings.js
vendored
Normal file
@ -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<services.Address | null>}
|
||||||
|
**/
|
||||||
|
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<string>}
|
||||||
|
**/
|
||||||
|
function Greet(name) {
|
||||||
|
return wails.Call(GreetService("Greet", name));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GreetService.NewPerson
|
||||||
|
* NewPerson creates a new person
|
||||||
|
* @param name {string}
|
||||||
|
* @returns {Promise<main.Person | null>}
|
||||||
|
**/
|
||||||
|
function NewPerson(name) {
|
||||||
|
return wails.Call(GreetService("NewPerson", name));
|
||||||
|
}
|
||||||
|
|
||||||
|
window.go = window.go || {};
|
||||||
|
window.go.main = {
|
||||||
|
GreetService: {
|
||||||
|
Greet,
|
||||||
|
NewPerson,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
window.go.services = {
|
||||||
|
OtherService: {
|
||||||
|
Yay,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
494
v3/internal/parser/testdata/struct_literal_single/bindings.js
vendored
Normal file
494
v3/internal/parser/testdata/struct_literal_single/bindings.js
vendored
Normal file
@ -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<void>}
|
||||||
|
**/
|
||||||
|
function ArrayInt(_in) {
|
||||||
|
return wails.Call(GreetService("ArrayInt", _in));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GreetService.BoolInBoolOut
|
||||||
|
*
|
||||||
|
* @param _in {boolean}
|
||||||
|
* @returns {Promise<boolean>}
|
||||||
|
**/
|
||||||
|
function BoolInBoolOut(_in) {
|
||||||
|
return wails.Call(GreetService("BoolInBoolOut", _in));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GreetService.Float32InFloat32Out
|
||||||
|
*
|
||||||
|
* @param _in {number}
|
||||||
|
* @returns {Promise<number>}
|
||||||
|
**/
|
||||||
|
function Float32InFloat32Out(_in) {
|
||||||
|
return wails.Call(GreetService("Float32InFloat32Out", _in));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GreetService.Float64InFloat64Out
|
||||||
|
*
|
||||||
|
* @param _in {number}
|
||||||
|
* @returns {Promise<number>}
|
||||||
|
**/
|
||||||
|
function Float64InFloat64Out(_in) {
|
||||||
|
return wails.Call(GreetService("Float64InFloat64Out", _in));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GreetService.Greet
|
||||||
|
* Greet someone
|
||||||
|
* @param name {string}
|
||||||
|
* @returns {Promise<string>}
|
||||||
|
**/
|
||||||
|
function Greet(name) {
|
||||||
|
return wails.Call(GreetService("Greet", name));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GreetService.Int16InIntOut
|
||||||
|
*
|
||||||
|
* @param _in {number}
|
||||||
|
* @returns {Promise<number>}
|
||||||
|
**/
|
||||||
|
function Int16InIntOut(_in) {
|
||||||
|
return wails.Call(GreetService("Int16InIntOut", _in));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GreetService.Int16PointerInAndOutput
|
||||||
|
*
|
||||||
|
* @param _in {number | null}
|
||||||
|
* @returns {Promise<number | null>}
|
||||||
|
**/
|
||||||
|
function Int16PointerInAndOutput(_in) {
|
||||||
|
return wails.Call(GreetService("Int16PointerInAndOutput", _in));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GreetService.Int32InIntOut
|
||||||
|
*
|
||||||
|
* @param _in {number}
|
||||||
|
* @returns {Promise<number>}
|
||||||
|
**/
|
||||||
|
function Int32InIntOut(_in) {
|
||||||
|
return wails.Call(GreetService("Int32InIntOut", _in));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GreetService.Int32PointerInAndOutput
|
||||||
|
*
|
||||||
|
* @param _in {number | null}
|
||||||
|
* @returns {Promise<number | null>}
|
||||||
|
**/
|
||||||
|
function Int32PointerInAndOutput(_in) {
|
||||||
|
return wails.Call(GreetService("Int32PointerInAndOutput", _in));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GreetService.Int64InIntOut
|
||||||
|
*
|
||||||
|
* @param _in {number}
|
||||||
|
* @returns {Promise<number>}
|
||||||
|
**/
|
||||||
|
function Int64InIntOut(_in) {
|
||||||
|
return wails.Call(GreetService("Int64InIntOut", _in));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GreetService.Int64PointerInAndOutput
|
||||||
|
*
|
||||||
|
* @param _in {number | null}
|
||||||
|
* @returns {Promise<number | null>}
|
||||||
|
**/
|
||||||
|
function Int64PointerInAndOutput(_in) {
|
||||||
|
return wails.Call(GreetService("Int64PointerInAndOutput", _in));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GreetService.Int8InIntOut
|
||||||
|
*
|
||||||
|
* @param _in {number}
|
||||||
|
* @returns {Promise<number>}
|
||||||
|
**/
|
||||||
|
function Int8InIntOut(_in) {
|
||||||
|
return wails.Call(GreetService("Int8InIntOut", _in));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GreetService.Int8PointerInAndOutput
|
||||||
|
*
|
||||||
|
* @param _in {number | null}
|
||||||
|
* @returns {Promise<number | null>}
|
||||||
|
**/
|
||||||
|
function Int8PointerInAndOutput(_in) {
|
||||||
|
return wails.Call(GreetService("Int8PointerInAndOutput", _in));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GreetService.IntInIntOut
|
||||||
|
*
|
||||||
|
* @param _in {number}
|
||||||
|
* @returns {Promise<number>}
|
||||||
|
**/
|
||||||
|
function IntInIntOut(_in) {
|
||||||
|
return wails.Call(GreetService("IntInIntOut", _in));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GreetService.IntPointerInAndOutput
|
||||||
|
*
|
||||||
|
* @param _in {number | null}
|
||||||
|
* @returns {Promise<number | null>}
|
||||||
|
**/
|
||||||
|
function IntPointerInAndOutput(_in) {
|
||||||
|
return wails.Call(GreetService("IntPointerInAndOutput", _in));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GreetService.IntPointerInputNamedOutputs
|
||||||
|
*
|
||||||
|
* @param _in {number | null}
|
||||||
|
* @returns {Promise<number | null, void>}
|
||||||
|
**/
|
||||||
|
function IntPointerInputNamedOutputs(_in) {
|
||||||
|
return wails.Call(GreetService("IntPointerInputNamedOutputs", _in));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GreetService.MapIntInt
|
||||||
|
*
|
||||||
|
* @param _in {map}
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
**/
|
||||||
|
function MapIntInt(_in) {
|
||||||
|
return wails.Call(GreetService("MapIntInt", _in));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GreetService.MapIntPointerInt
|
||||||
|
*
|
||||||
|
* @param _in {map}
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
**/
|
||||||
|
function MapIntPointerInt(_in) {
|
||||||
|
return wails.Call(GreetService("MapIntPointerInt", _in));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GreetService.MapIntSliceInt
|
||||||
|
*
|
||||||
|
* @param _in {map}
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
**/
|
||||||
|
function MapIntSliceInt(_in) {
|
||||||
|
return wails.Call(GreetService("MapIntSliceInt", _in));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GreetService.MapIntSliceIntInMapIntSliceIntOut
|
||||||
|
*
|
||||||
|
* @param _in {map}
|
||||||
|
* @returns {Promise<map>}
|
||||||
|
**/
|
||||||
|
function MapIntSliceIntInMapIntSliceIntOut(_in) {
|
||||||
|
return wails.Call(GreetService("MapIntSliceIntInMapIntSliceIntOut", _in));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GreetService.NoInputsStringOut
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @returns {Promise<string>}
|
||||||
|
**/
|
||||||
|
function NoInputsStringOut() {
|
||||||
|
return wails.Call(GreetService("NoInputsStringOut"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GreetService.PointerBoolInBoolOut
|
||||||
|
*
|
||||||
|
* @param _in {boolean | null}
|
||||||
|
* @returns {Promise<boolean | null>}
|
||||||
|
**/
|
||||||
|
function PointerBoolInBoolOut(_in) {
|
||||||
|
return wails.Call(GreetService("PointerBoolInBoolOut", _in));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GreetService.PointerFloat32InFloat32Out
|
||||||
|
*
|
||||||
|
* @param _in {number | null}
|
||||||
|
* @returns {Promise<number | null>}
|
||||||
|
**/
|
||||||
|
function PointerFloat32InFloat32Out(_in) {
|
||||||
|
return wails.Call(GreetService("PointerFloat32InFloat32Out", _in));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GreetService.PointerFloat64InFloat64Out
|
||||||
|
*
|
||||||
|
* @param _in {number | null}
|
||||||
|
* @returns {Promise<number | null>}
|
||||||
|
**/
|
||||||
|
function PointerFloat64InFloat64Out(_in) {
|
||||||
|
return wails.Call(GreetService("PointerFloat64InFloat64Out", _in));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GreetService.PointerMapIntInt
|
||||||
|
*
|
||||||
|
* @param _in {map | null}
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
**/
|
||||||
|
function PointerMapIntInt(_in) {
|
||||||
|
return wails.Call(GreetService("PointerMapIntInt", _in));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GreetService.PointerStringInStringOut
|
||||||
|
*
|
||||||
|
* @param _in {string | null}
|
||||||
|
* @returns {Promise<string | null>}
|
||||||
|
**/
|
||||||
|
function PointerStringInStringOut(_in) {
|
||||||
|
return wails.Call(GreetService("PointerStringInStringOut", _in));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GreetService.StringArrayInputNamedOutput
|
||||||
|
*
|
||||||
|
* @param _in {string[]}
|
||||||
|
* @returns {Promise<string[]>}
|
||||||
|
**/
|
||||||
|
function StringArrayInputNamedOutput(_in) {
|
||||||
|
return wails.Call(GreetService("StringArrayInputNamedOutput", _in));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GreetService.StringArrayInputNamedOutputs
|
||||||
|
*
|
||||||
|
* @param _in {string[]}
|
||||||
|
* @returns {Promise<string[], void>}
|
||||||
|
**/
|
||||||
|
function StringArrayInputNamedOutputs(_in) {
|
||||||
|
return wails.Call(GreetService("StringArrayInputNamedOutputs", _in));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GreetService.StringArrayInputStringArrayOut
|
||||||
|
*
|
||||||
|
* @param _in {string[]}
|
||||||
|
* @returns {Promise<string[]>}
|
||||||
|
**/
|
||||||
|
function StringArrayInputStringArrayOut(_in) {
|
||||||
|
return wails.Call(GreetService("StringArrayInputStringArrayOut", _in));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GreetService.StringArrayInputStringOut
|
||||||
|
*
|
||||||
|
* @param _in {string[]}
|
||||||
|
* @returns {Promise<string>}
|
||||||
|
**/
|
||||||
|
function StringArrayInputStringOut(_in) {
|
||||||
|
return wails.Call(GreetService("StringArrayInputStringOut", _in));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GreetService.StructInputStructOutput
|
||||||
|
*
|
||||||
|
* @param _in {main.Person}
|
||||||
|
* @returns {Promise<main.Person>}
|
||||||
|
**/
|
||||||
|
function StructInputStructOutput(_in) {
|
||||||
|
return wails.Call(GreetService("StructInputStructOutput", _in));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GreetService.StructPointerInputErrorOutput
|
||||||
|
*
|
||||||
|
* @param _in {main.Person | null}
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
**/
|
||||||
|
function StructPointerInputErrorOutput(_in) {
|
||||||
|
return wails.Call(GreetService("StructPointerInputErrorOutput", _in));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GreetService.StructPointerInputStructPointerOutput
|
||||||
|
*
|
||||||
|
* @param _in {main.Person | null}
|
||||||
|
* @returns {Promise<main.Person | null>}
|
||||||
|
**/
|
||||||
|
function StructPointerInputStructPointerOutput(_in) {
|
||||||
|
return wails.Call(GreetService("StructPointerInputStructPointerOutput", _in));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GreetService.UInt16InUIntOut
|
||||||
|
*
|
||||||
|
* @param _in {number}
|
||||||
|
* @returns {Promise<number>}
|
||||||
|
**/
|
||||||
|
function UInt16InUIntOut(_in) {
|
||||||
|
return wails.Call(GreetService("UInt16InUIntOut", _in));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GreetService.UInt16PointerInAndOutput
|
||||||
|
*
|
||||||
|
* @param _in {number | null}
|
||||||
|
* @returns {Promise<number | null>}
|
||||||
|
**/
|
||||||
|
function UInt16PointerInAndOutput(_in) {
|
||||||
|
return wails.Call(GreetService("UInt16PointerInAndOutput", _in));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GreetService.UInt32InUIntOut
|
||||||
|
*
|
||||||
|
* @param _in {number}
|
||||||
|
* @returns {Promise<number>}
|
||||||
|
**/
|
||||||
|
function UInt32InUIntOut(_in) {
|
||||||
|
return wails.Call(GreetService("UInt32InUIntOut", _in));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GreetService.UInt32PointerInAndOutput
|
||||||
|
*
|
||||||
|
* @param _in {number | null}
|
||||||
|
* @returns {Promise<number | null>}
|
||||||
|
**/
|
||||||
|
function UInt32PointerInAndOutput(_in) {
|
||||||
|
return wails.Call(GreetService("UInt32PointerInAndOutput", _in));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GreetService.UInt64InUIntOut
|
||||||
|
*
|
||||||
|
* @param _in {number}
|
||||||
|
* @returns {Promise<number>}
|
||||||
|
**/
|
||||||
|
function UInt64InUIntOut(_in) {
|
||||||
|
return wails.Call(GreetService("UInt64InUIntOut", _in));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GreetService.UInt64PointerInAndOutput
|
||||||
|
*
|
||||||
|
* @param _in {number | null}
|
||||||
|
* @returns {Promise<number | null>}
|
||||||
|
**/
|
||||||
|
function UInt64PointerInAndOutput(_in) {
|
||||||
|
return wails.Call(GreetService("UInt64PointerInAndOutput", _in));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GreetService.UInt8InUIntOut
|
||||||
|
*
|
||||||
|
* @param _in {number}
|
||||||
|
* @returns {Promise<number>}
|
||||||
|
**/
|
||||||
|
function UInt8InUIntOut(_in) {
|
||||||
|
return wails.Call(GreetService("UInt8InUIntOut", _in));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GreetService.UInt8PointerInAndOutput
|
||||||
|
*
|
||||||
|
* @param _in {number | null}
|
||||||
|
* @returns {Promise<number | null>}
|
||||||
|
**/
|
||||||
|
function UInt8PointerInAndOutput(_in) {
|
||||||
|
return wails.Call(GreetService("UInt8PointerInAndOutput", _in));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GreetService.UIntInUIntOut
|
||||||
|
*
|
||||||
|
* @param _in {number}
|
||||||
|
* @returns {Promise<number>}
|
||||||
|
**/
|
||||||
|
function UIntInUIntOut(_in) {
|
||||||
|
return wails.Call(GreetService("UIntInUIntOut", _in));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GreetService.UIntPointerInAndOutput
|
||||||
|
*
|
||||||
|
* @param _in {number | null}
|
||||||
|
* @returns {Promise<number | null>}
|
||||||
|
**/
|
||||||
|
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,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
29
v3/internal/parser/testdata/variable_single/bindings.js
vendored
Normal file
29
v3/internal/parser/testdata/variable_single/bindings.js
vendored
Normal file
@ -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<string>}
|
||||||
|
**/
|
||||||
|
function Greet(name) {
|
||||||
|
return wails.Call(GreetService("Greet", name));
|
||||||
|
}
|
||||||
|
|
||||||
|
window.go = window.go || {};
|
||||||
|
window.go.main = {
|
||||||
|
GreetService: {
|
||||||
|
Greet,
|
||||||
|
},
|
||||||
|
};
|
29
v3/internal/parser/testdata/variable_single_from_function/bindings.js
vendored
Normal file
29
v3/internal/parser/testdata/variable_single_from_function/bindings.js
vendored
Normal file
@ -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<string>}
|
||||||
|
**/
|
||||||
|
function Greet(name) {
|
||||||
|
return wails.Call(GreetService("Greet", name));
|
||||||
|
}
|
||||||
|
|
||||||
|
window.go = window.go || {};
|
||||||
|
window.go.main = {
|
||||||
|
GreetService: {
|
||||||
|
Greet,
|
||||||
|
},
|
||||||
|
};
|
66
v3/internal/parser/testdata/variable_single_from_other_function/bindings.js
vendored
Normal file
66
v3/internal/parser/testdata/variable_single_from_other_function/bindings.js
vendored
Normal file
@ -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<services.Address | null>}
|
||||||
|
**/
|
||||||
|
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<string>}
|
||||||
|
**/
|
||||||
|
function Greet(name) {
|
||||||
|
return wails.Call(GreetService("Greet", name));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GreetService.NewPerson
|
||||||
|
* NewPerson creates a new person
|
||||||
|
* @param name {string}
|
||||||
|
* @returns {Promise<main.Person | null>}
|
||||||
|
**/
|
||||||
|
function NewPerson(name) {
|
||||||
|
return wails.Call(GreetService("NewPerson", name));
|
||||||
|
}
|
||||||
|
|
||||||
|
window.go = window.go || {};
|
||||||
|
window.go.main = {
|
||||||
|
GreetService: {
|
||||||
|
Greet,
|
||||||
|
NewPerson,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
window.go.services = {
|
||||||
|
OtherService: {
|
||||||
|
Yay,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user