From 2bb25b12ffc5e794b28019aaa0d0f68771bbb0c3 Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Fri, 22 Dec 2023 20:01:42 +1100 Subject: [PATCH] Update bindings generator to generate bindings in packages and files. Remove unused JavaScript files Update tests. Update v3 docs --- mkdocs-website/docs/en/roadmap.md | 43 +- .../shared/alpha3-bindings-callbyname.csv | 10 +- mkdocs-website/shared/alpha3-models.csv | 6 +- v3/go.mod | 1 + v3/internal/parser/bindings.go | 142 +++++-- v3/internal/parser/bindings_test.go | 367 ++++++++++++---- v3/internal/parser/models.go | 30 +- v3/internal/parser/models_test.go | 309 +++++++++----- v3/internal/parser/parser.go | 157 +++++-- v3/internal/parser/parser_enum_test.go | 168 ++------ v3/internal/parser/parser_function_test.go | 60 ++- .../parser_struct_literal_multiple_test.go | 35 +- ..._struct_literal_non_pointer_single_test.go | 30 ++ .../parser_struct_literal_single_test.go | 30 ++ .../parser/parser_variable_single_test.go | 38 +- .../parser/templates/interfaces.ts.tmpl | 42 +- v3/internal/parser/templates/model.js.tmpl | 41 +- v3/internal/parser/templates/model.ts.tmpl | 63 +-- .../testdata/enum-interface/bindings_main.js | 29 -- .../enum-interface/bindings_main.name.js | 29 -- .../parser/testdata/enum-interface/models.ts | 21 - .../parser/testdata/enum/bindings_main.js | 29 -- .../testdata/enum/bindings_main.name.js | 29 -- .../frontend/bindings/main/GreetService.js | 29 ++ .../bindings/main/GreetService.name.js | 29 ++ .../bindings/main/models.interfaces.ts | 19 + .../{ => frontend/bindings/main}/models.js | 19 +- .../enum/frontend/bindings/main/models.ts | 30 ++ v3/internal/parser/testdata/enum/main.go | 1 + v3/internal/parser/testdata/enum/models.ts | 33 -- .../bindings_main.js | 20 - .../bindings_main.name.js | 20 - .../frontend/bindings/main/GreetService.js | 18 + .../bindings/main/GreetService.name.js | 18 + .../bindings/services/models.interfaces.ts | 12 + .../bindings/services}/models.js | 6 +- .../frontend/bindings/services/models.ts | 12 + .../enum_from_imported_package/models.ts | 16 - .../bindings_main.js | 27 -- .../bindings_services.got.js | 19 - .../bindings_services.js | 19 - .../boundmethods.got.json | 1 + .../frontend/bindings/main/GreetService.js | 27 ++ .../bindings/main/GreetService.name.js | 27 ++ .../bindings/main/models.interfaces.ts | 11 + .../frontend/bindings/main/models.js | 34 ++ .../frontend/bindings/main/models.ts | 22 + .../bindings/services/OtherService.js | 16 + .../bindings/services/OtherService.name.js | 16 + .../bindings/services/models.interfaces.ts} | 7 +- .../frontend/bindings/services/models.js | 31 ++ .../frontend/bindings/services/models.ts | 22 + .../function_from_imported_package/main.go | 3 +- .../function_from_imported_package/models.js | 63 --- .../function_from_imported_package/models.ts | 48 --- .../frontend/bindings/main/GreetService.js | 27 ++ .../bindings/main/GreetService.name.js | 27 ++ .../frontend/bindings/main/models.ts | 17 + .../bindings/services/other/OtherService.js | 16 + .../services/other/OtherService.name.js | 16 + .../bindings/services/other}/models.ts | 6 +- .../main.go | 21 +- .../services/other/other.go | 26 ++ .../testdata/function_single/bindings_main.js | 15 - .../frontend/bindings/main/GreetService.js | 14 + .../bindings/main/GreetService.name.js | 14 + .../struct_literal_multiple/bindings_main.js | 26 -- .../frontend/bindings/main/GreetService.js | 13 + .../bindings/main/GreetService.name.js | 13 + .../frontend/bindings/main/OtherService.js | 12 + .../bindings/main/OtherService.name.js | 12 + .../bindings_main.js | 26 -- .../frontend/bindings/main/GreetService.js | 13 + .../bindings/main/GreetService.name.js | 13 + .../frontend/bindings/main/OtherService.js | 12 + .../bindings/main/OtherService.name.js | 12 + .../bindings_main.js | 27 -- .../bindings_services.js | 19 - .../frontend/bindings/main/GreetService.js | 27 ++ .../bindings/main/GreetService.name.js | 27 ++ .../bindings/main/models.interfaces.ts | 10 + .../frontend/bindings/main/models.js | 33 ++ .../frontend/bindings/main/models.ts | 21 + .../bindings/services/OtherService.js | 16 + .../bindings/services/OtherService.name.js | 16 + .../bindings/services/models.interfaces.ts} | 7 +- .../frontend/bindings/services/models.js | 31 ++ .../frontend/bindings/services/models.ts | 22 + .../struct_literal_multiple_other/models.js | 63 --- .../struct_literal_multiple_other/models.ts | 48 --- .../bindings_main.js | 356 ---------------- .../frontend/bindings/main/GreetService.js | 394 ++++++++++++++++++ .../bindings/main/GreetService.name.js | 394 ++++++++++++++++++ .../bindings/main/models.interfaces.ts | 19 + .../{ => frontend/bindings/main}/models.js | 35 +- .../frontend/bindings/main/models.ts | 52 +++ .../models.ts | 59 --- .../struct_literal_single/bindings_main.js | 355 ---------------- .../frontend/bindings/main/GreetService.js | 394 ++++++++++++++++++ .../bindings/main/GreetService.name.js | 394 ++++++++++++++++++ .../bindings/main/models.interfaces.ts | 19 + .../frontend/bindings/main/models.js | 79 ++++ .../frontend/bindings/main/models.ts | 52 +++ .../testdata/struct_literal_single/models.ts | 59 --- .../testdata/variable_single/bindings_main.js | 15 - .../frontend/bindings/main/GreetService.js | 14 + .../bindings/main/GreetService.name.js | 14 + .../bindings_main.js | 15 - .../frontend/bindings/main/GreetService.js | 14 + .../bindings/main/GreetService.name.js | 14 + .../variable_single_from_function/models.ts | 5 - .../bindings_main.js | 27 -- .../bindings_services.js | 19 - .../frontend/bindings/main/GreetService.js | 27 ++ .../bindings/main/GreetService.name.js | 27 ++ .../bindings/main/models.interfaces.ts | 12 + .../frontend/bindings/main/models.js | 35 ++ .../frontend/bindings/main/models.ts | 23 + .../bindings/services/OtherService.js | 16 + .../bindings/services/OtherService.name.js | 16 + .../bindings/services/models.interfaces.ts} | 7 +- .../frontend/bindings/services/models.js | 31 ++ .../frontend/bindings/services/models.ts | 22 + .../main.go | 2 + .../models.ts | 48 --- 125 files changed, 4008 insertions(+), 2158 deletions(-) delete mode 100644 v3/internal/parser/testdata/enum-interface/bindings_main.js delete mode 100644 v3/internal/parser/testdata/enum-interface/bindings_main.name.js delete mode 100644 v3/internal/parser/testdata/enum-interface/models.ts delete mode 100644 v3/internal/parser/testdata/enum/bindings_main.js delete mode 100644 v3/internal/parser/testdata/enum/bindings_main.name.js create mode 100644 v3/internal/parser/testdata/enum/frontend/bindings/main/GreetService.js create mode 100644 v3/internal/parser/testdata/enum/frontend/bindings/main/GreetService.name.js create mode 100644 v3/internal/parser/testdata/enum/frontend/bindings/main/models.interfaces.ts rename v3/internal/parser/testdata/enum/{ => frontend/bindings/main}/models.js (73%) create mode 100644 v3/internal/parser/testdata/enum/frontend/bindings/main/models.ts delete mode 100644 v3/internal/parser/testdata/enum/models.ts delete mode 100644 v3/internal/parser/testdata/enum_from_imported_package/bindings_main.js delete mode 100644 v3/internal/parser/testdata/enum_from_imported_package/bindings_main.name.js create mode 100644 v3/internal/parser/testdata/enum_from_imported_package/frontend/bindings/main/GreetService.js create mode 100644 v3/internal/parser/testdata/enum_from_imported_package/frontend/bindings/main/GreetService.name.js create mode 100644 v3/internal/parser/testdata/enum_from_imported_package/frontend/bindings/services/models.interfaces.ts rename v3/internal/parser/testdata/enum_from_imported_package/{ => frontend/bindings/services}/models.js (66%) create mode 100644 v3/internal/parser/testdata/enum_from_imported_package/frontend/bindings/services/models.ts delete mode 100644 v3/internal/parser/testdata/enum_from_imported_package/models.ts delete mode 100644 v3/internal/parser/testdata/function_from_imported_package/bindings_main.js delete mode 100644 v3/internal/parser/testdata/function_from_imported_package/bindings_services.got.js delete mode 100644 v3/internal/parser/testdata/function_from_imported_package/bindings_services.js create mode 100644 v3/internal/parser/testdata/function_from_imported_package/boundmethods.got.json create mode 100644 v3/internal/parser/testdata/function_from_imported_package/frontend/bindings/main/GreetService.js create mode 100644 v3/internal/parser/testdata/function_from_imported_package/frontend/bindings/main/GreetService.name.js create mode 100644 v3/internal/parser/testdata/function_from_imported_package/frontend/bindings/main/models.interfaces.ts create mode 100644 v3/internal/parser/testdata/function_from_imported_package/frontend/bindings/main/models.js create mode 100644 v3/internal/parser/testdata/function_from_imported_package/frontend/bindings/main/models.ts create mode 100644 v3/internal/parser/testdata/function_from_imported_package/frontend/bindings/services/OtherService.js create mode 100644 v3/internal/parser/testdata/function_from_imported_package/frontend/bindings/services/OtherService.name.js rename v3/internal/parser/testdata/{struct_literal_multiple_files/models.ts => function_from_imported_package/frontend/bindings/services/models.interfaces.ts} (58%) create mode 100644 v3/internal/parser/testdata/function_from_imported_package/frontend/bindings/services/models.js create mode 100644 v3/internal/parser/testdata/function_from_imported_package/frontend/bindings/services/models.ts delete mode 100644 v3/internal/parser/testdata/function_from_imported_package/models.js delete mode 100644 v3/internal/parser/testdata/function_from_imported_package/models.ts create mode 100644 v3/internal/parser/testdata/function_from_nested_imported_package/frontend/bindings/main/GreetService.js create mode 100644 v3/internal/parser/testdata/function_from_nested_imported_package/frontend/bindings/main/GreetService.name.js create mode 100644 v3/internal/parser/testdata/function_from_nested_imported_package/frontend/bindings/main/models.ts create mode 100644 v3/internal/parser/testdata/function_from_nested_imported_package/frontend/bindings/services/other/OtherService.js create mode 100644 v3/internal/parser/testdata/function_from_nested_imported_package/frontend/bindings/services/other/OtherService.name.js rename v3/internal/parser/testdata/{function_single => function_from_nested_imported_package/frontend/bindings/services/other}/models.ts (58%) rename v3/internal/parser/testdata/{enum-interface => function_from_nested_imported_package}/main.go (65%) create mode 100644 v3/internal/parser/testdata/function_from_nested_imported_package/services/other/other.go delete mode 100644 v3/internal/parser/testdata/function_single/bindings_main.js create mode 100644 v3/internal/parser/testdata/function_single/frontend/bindings/main/GreetService.js create mode 100644 v3/internal/parser/testdata/function_single/frontend/bindings/main/GreetService.name.js delete mode 100644 v3/internal/parser/testdata/struct_literal_multiple/bindings_main.js create mode 100644 v3/internal/parser/testdata/struct_literal_multiple/frontend/bindings/main/GreetService.js create mode 100644 v3/internal/parser/testdata/struct_literal_multiple/frontend/bindings/main/GreetService.name.js create mode 100644 v3/internal/parser/testdata/struct_literal_multiple/frontend/bindings/main/OtherService.js create mode 100644 v3/internal/parser/testdata/struct_literal_multiple/frontend/bindings/main/OtherService.name.js delete mode 100644 v3/internal/parser/testdata/struct_literal_multiple_files/bindings_main.js create mode 100644 v3/internal/parser/testdata/struct_literal_multiple_files/frontend/bindings/main/GreetService.js create mode 100644 v3/internal/parser/testdata/struct_literal_multiple_files/frontend/bindings/main/GreetService.name.js create mode 100644 v3/internal/parser/testdata/struct_literal_multiple_files/frontend/bindings/main/OtherService.js create mode 100644 v3/internal/parser/testdata/struct_literal_multiple_files/frontend/bindings/main/OtherService.name.js delete mode 100644 v3/internal/parser/testdata/struct_literal_multiple_other/bindings_main.js delete mode 100644 v3/internal/parser/testdata/struct_literal_multiple_other/bindings_services.js create mode 100644 v3/internal/parser/testdata/struct_literal_multiple_other/frontend/bindings/main/GreetService.js create mode 100644 v3/internal/parser/testdata/struct_literal_multiple_other/frontend/bindings/main/GreetService.name.js create mode 100644 v3/internal/parser/testdata/struct_literal_multiple_other/frontend/bindings/main/models.interfaces.ts create mode 100644 v3/internal/parser/testdata/struct_literal_multiple_other/frontend/bindings/main/models.js create mode 100644 v3/internal/parser/testdata/struct_literal_multiple_other/frontend/bindings/main/models.ts create mode 100644 v3/internal/parser/testdata/struct_literal_multiple_other/frontend/bindings/services/OtherService.js create mode 100644 v3/internal/parser/testdata/struct_literal_multiple_other/frontend/bindings/services/OtherService.name.js rename v3/internal/parser/testdata/{variable_single/models.ts => struct_literal_multiple_other/frontend/bindings/services/models.interfaces.ts} (58%) create mode 100644 v3/internal/parser/testdata/struct_literal_multiple_other/frontend/bindings/services/models.js create mode 100644 v3/internal/parser/testdata/struct_literal_multiple_other/frontend/bindings/services/models.ts delete mode 100644 v3/internal/parser/testdata/struct_literal_multiple_other/models.js delete mode 100644 v3/internal/parser/testdata/struct_literal_multiple_other/models.ts delete mode 100644 v3/internal/parser/testdata/struct_literal_non_pointer_single/bindings_main.js create mode 100644 v3/internal/parser/testdata/struct_literal_non_pointer_single/frontend/bindings/main/GreetService.js create mode 100644 v3/internal/parser/testdata/struct_literal_non_pointer_single/frontend/bindings/main/GreetService.name.js create mode 100644 v3/internal/parser/testdata/struct_literal_non_pointer_single/frontend/bindings/main/models.interfaces.ts rename v3/internal/parser/testdata/struct_literal_non_pointer_single/{ => frontend/bindings/main}/models.js (74%) create mode 100644 v3/internal/parser/testdata/struct_literal_non_pointer_single/frontend/bindings/main/models.ts delete mode 100644 v3/internal/parser/testdata/struct_literal_non_pointer_single/models.ts delete mode 100644 v3/internal/parser/testdata/struct_literal_single/bindings_main.js create mode 100644 v3/internal/parser/testdata/struct_literal_single/frontend/bindings/main/GreetService.js create mode 100644 v3/internal/parser/testdata/struct_literal_single/frontend/bindings/main/GreetService.name.js create mode 100644 v3/internal/parser/testdata/struct_literal_single/frontend/bindings/main/models.interfaces.ts create mode 100644 v3/internal/parser/testdata/struct_literal_single/frontend/bindings/main/models.js create mode 100644 v3/internal/parser/testdata/struct_literal_single/frontend/bindings/main/models.ts delete mode 100644 v3/internal/parser/testdata/struct_literal_single/models.ts delete mode 100644 v3/internal/parser/testdata/variable_single/bindings_main.js create mode 100644 v3/internal/parser/testdata/variable_single/frontend/bindings/main/GreetService.js create mode 100644 v3/internal/parser/testdata/variable_single/frontend/bindings/main/GreetService.name.js delete mode 100644 v3/internal/parser/testdata/variable_single_from_function/bindings_main.js create mode 100644 v3/internal/parser/testdata/variable_single_from_function/frontend/bindings/main/GreetService.js create mode 100644 v3/internal/parser/testdata/variable_single_from_function/frontend/bindings/main/GreetService.name.js delete mode 100644 v3/internal/parser/testdata/variable_single_from_function/models.ts delete mode 100644 v3/internal/parser/testdata/variable_single_from_other_function/bindings_main.js delete mode 100644 v3/internal/parser/testdata/variable_single_from_other_function/bindings_services.js create mode 100644 v3/internal/parser/testdata/variable_single_from_other_function/frontend/bindings/main/GreetService.js create mode 100644 v3/internal/parser/testdata/variable_single_from_other_function/frontend/bindings/main/GreetService.name.js create mode 100644 v3/internal/parser/testdata/variable_single_from_other_function/frontend/bindings/main/models.interfaces.ts create mode 100644 v3/internal/parser/testdata/variable_single_from_other_function/frontend/bindings/main/models.js create mode 100644 v3/internal/parser/testdata/variable_single_from_other_function/frontend/bindings/main/models.ts create mode 100644 v3/internal/parser/testdata/variable_single_from_other_function/frontend/bindings/services/OtherService.js create mode 100644 v3/internal/parser/testdata/variable_single_from_other_function/frontend/bindings/services/OtherService.name.js rename v3/internal/parser/testdata/{struct_literal_multiple/models.ts => variable_single_from_other_function/frontend/bindings/services/models.interfaces.ts} (58%) create mode 100644 v3/internal/parser/testdata/variable_single_from_other_function/frontend/bindings/services/models.js create mode 100644 v3/internal/parser/testdata/variable_single_from_other_function/frontend/bindings/services/models.ts delete mode 100644 v3/internal/parser/testdata/variable_single_from_other_function/models.ts diff --git a/mkdocs-website/docs/en/roadmap.md b/mkdocs-website/docs/en/roadmap.md index 0a7910225..f2aa6ab73 100644 --- a/mkdocs-website/docs/en/roadmap.md +++ b/mkdocs-website/docs/en/roadmap.md @@ -17,21 +17,16 @@ We also want to get all examples working on Linux. #### How Can I Help? -If you are interested in helping out, please review the table below and look for -untested scenarios. The parser code and tests are located in `v3/internal/parser`. -All tests can be run using `go test ./...` from the `v3` directory. +You can generate bindings using the `wails3 generate bindings` command. This will generate bindings for all exported struct methods bound to your project. +You can then use these bindings in your frontend code. You can see an example of this in the `examples/bindings` directory. +Run `wails3 generate bindings -help` to view options that govern how bindings are generated. + +Review the table below and look for untested scenarios. The parser code and tests are located in `v3/internal/parser`. All tests can be run using `go test ./...` from the `v3` directory. Basically, try to break it and let us know if you find any issues! :smile: #### Status Bindings for struct (CallByID): -- [x] Same package -- [x] Different package -- [ ] Different package with same name -- [x] Containing another struct from same package -- [x] Containing another struct from different package -- [x] Containing an anonymous struct - - :material-check-bold: - Working - :material-minus: - Partially working @@ -40,12 +35,6 @@ Bindings for struct (CallByID): {{ read_csv("alpha3-bindings-callbyid.csv") }} Bindings for struct (CallByName): -- [ ] Same package -- [ ] Different package -- [ ] Different package with same name -- [ ] Containing another struct from same package -- [ ] Containing another struct from different package -- [ ] Containing an anonymous struct - :material-check-bold: - Working - :material-minus: - Partially working @@ -54,32 +43,18 @@ Bindings for struct (CallByName): {{ read_csv("alpha3-bindings-callbyname.csv") }} Models: -- [x] Class model for struct in same package -- [x] Class model for struct in different package -- [ ] Interface model for struct in same package -- [ ] Interface model for struct in different package -- [x] Enum in same package -- [x] Enum in different package -- [x] Interface using enum in same package -- [ ] Interface using enum in different package - -Examples: -- [ ] All examples working on Linux - - :material-check-bold: - Working - :material-minus: - Partially working - :material-close: - Not working -**Bindings**: - -{{ read_csv("alpha3-bindings-callbyid.csv") }} - -**Models**: - {{ read_csv("alpha3-models.csv") }} +Examples: + +- [ ] All examples working on Linux + ### Alpha 2 diff --git a/mkdocs-website/shared/alpha3-bindings-callbyname.csv b/mkdocs-website/shared/alpha3-bindings-callbyname.csv index a051952b9..6fc4a95f7 100644 --- a/mkdocs-website/shared/alpha3-bindings-callbyname.csv +++ b/mkdocs-website/shared/alpha3-bindings-callbyname.csv @@ -1,7 +1,7 @@ Scenario,Windows,Mac,Linux,WSL -Same package," "," "," "," " -Different package," "," "," "," " +Same package,:material-check-bold:," "," "," " +Different package,:material-check-bold:," "," "," " Different package with same name," "," "," "," " -Containing another struct from same package," "," "," "," " -Containing another struct from different package," "," "," "," " -Containing an anonymous struct," "," "," "," " +Containing another struct from same package,:material-check-bold:," "," "," " +Containing another struct from different package,:material-check-bold:," "," "," " +Containing an anonymous struct,:material-check-bold:," "," "," " diff --git a/mkdocs-website/shared/alpha3-models.csv b/mkdocs-website/shared/alpha3-models.csv index 4dfbd4780..1c311c5ae 100644 --- a/mkdocs-website/shared/alpha3-models.csv +++ b/mkdocs-website/shared/alpha3-models.csv @@ -1,10 +1,10 @@ Scenario,Windows,Mac,Linux,WSL Class model for struct in same package,:material-check-bold:," "," "," " Class model for struct in different package,:material-check-bold:," "," "," " -Interface model for struct in same package," "," "," "," " -Interface model for struct in different package," "," "," "," " +Interface model for struct in same package,:material-check-bold:," "," "," " +Interface model for struct in different package,:material-check-bold:," "," "," " Enum in same package,:material-check-bold:," "," "," " Enum in different package,:material-check-bold:," "," "," " Interface using enum in same package,:material-check-bold:," "," "," " -Interface using enum in different package," "," "," "," " +Interface using enum in different package,:material-check-bold:," "," "," " diff --git a/v3/go.mod b/v3/go.mod index 3a6d6718f..365d8ccb7 100644 --- a/v3/go.mod +++ b/v3/go.mod @@ -7,6 +7,7 @@ toolchain go1.21.4 require ( github.com/atterpac/refresh v0.2.4 github.com/bep/debounce v1.2.1 + github.com/davecgh/go-spew v1.1.1 github.com/ebitengine/purego v0.4.0-alpha.4 github.com/go-git/go-git/v5 v5.3.0 github.com/go-ole/go-ole v1.2.6 diff --git a/v3/internal/parser/bindings.go b/v3/internal/parser/bindings.go index 656e2e113..0efa8a10b 100644 --- a/v3/internal/parser/bindings.go +++ b/v3/internal/parser/bindings.go @@ -16,23 +16,26 @@ const header = `// @ts-check ` const bindingTemplate = ` - /** - * {{structName}}.{{methodName}} - *Comments -* @param names {string} - * @returns {Promise} - **/ +/**Comments + * @function {{methodName}}* @param names {string} + * @returns {Promise} + **/ ` -const callByID = ` {{methodName}}: function({{inputs}}) { return wails.CallByID({{ID}}, ...Array.prototype.slice.call(arguments, 0)); }, +const callByID = `export function {{methodName}}({{inputs}}) { + return wails.CallByID({{ID}}, ...Array.prototype.slice.call(arguments, 0)); +} ` -const callByName = ` {{methodName}}: function({{inputs}}) { return wails.CallByName("{{Name}}", ...Array.prototype.slice.call(arguments, 0)); }, + +const callByName = `export function {{methodName}}({{inputs}}) { + return wails.CallByName("{{Name}}", ...Array.prototype.slice.call(arguments, 0)); +} ` const enumTemplate = ` - export enum {{.EnumName}} { - {{.EnumValues}} - } + export enum {{.EnumName}} { + {{.EnumValues}} + } ` var reservedWords = []string{ @@ -112,8 +115,13 @@ func sanitiseJSVarName(name string) string { return name } -func GenerateBinding(structName string, method *BoundMethod, useIDs bool) (string, []string, []string) { - var namespacedStructs []string +type ExternalStruct struct { + Package string + Name string +} + +func GenerateBinding(thisStructName string, method *BoundMethod, useIDs bool) (string, []string, map[packagePath]map[string]*ExternalStruct) { + var externalStructs = make(map[packagePath]map[string]*ExternalStruct) var models []string template := bindingTemplate if useIDs { @@ -121,7 +129,7 @@ func GenerateBinding(structName string, method *BoundMethod, useIDs bool) (strin } else { template += callByName } - result := strings.ReplaceAll(template, "{{structName}}", structName) + result := strings.ReplaceAll(template, "{{structName}}", thisStructName) result = strings.ReplaceAll(result, "{{methodName}}", method.Name) result = strings.ReplaceAll(result, "{{ID}}", fmt.Sprintf("%v", method.ID)) @@ -129,10 +137,10 @@ func GenerateBinding(structName string, method *BoundMethod, useIDs bool) (strin parts := strings.Split(method.Package, "/") packageName := parts[len(parts)-1] - result = strings.ReplaceAll(result, "{{Name}}", fmt.Sprintf("%v.%v.%v", packageName, structName, method.Name)) + result = strings.ReplaceAll(result, "{{Name}}", fmt.Sprintf("%v.%v.%v", packageName, thisStructName, method.Name)) comments := strings.TrimSpace(method.DocComment) if comments != "" { - comments = " " + comments + comments = "\n * " + comments } result = strings.ReplaceAll(result, "Comments", comments) var params string @@ -143,16 +151,22 @@ func GenerateBinding(structName string, method *BoundMethod, useIDs bool) (strin models = append(models, pkgName) } if input.Type.IsStruct || input.Type.IsEnum { - nsStruct := input.NamespacedStructType() - namespacedStructs = append(namespacedStructs, nsStruct) + if _, ok := externalStructs[input.Type.Package]; !ok { + externalStructs[input.Type.Package] = make(map[string]*ExternalStruct) + } + externalStructs[input.Type.Package][input.Type.Name] = &ExternalStruct{ + Package: input.Type.Package, + Name: input.Type.Name, + } } - params += " * @param " + inputName + " {" + input.JSType() + "}\n" + inputType := input.JSType(packageName) + params += "\n * @param " + inputName + " {" + inputType + "}" } params = strings.TrimSuffix(params, "\n") - if len(params) == 0 { - params = " *" - } + //if len(params) > 0 { + // params = "\n" + params + //} result = strings.ReplaceAll(result, "* @param names {string}", params) var inputs string for _, input := range method.Inputs { @@ -181,13 +195,19 @@ func GenerateBinding(structName string, method *BoundMethod, useIDs bool) (strin if pkgName != "" { models = append(models, pkgName) } - jsType := output.JSType() + jsType := output.JSType(packageName) if jsType == "error" { jsType = "void" } if output.Type.IsStruct { - namespacedStructs = append(namespacedStructs, output.NamespacedStructType()) - jsType = output.NamespacedStructVariable() + if _, ok := externalStructs[output.Type.Package]; !ok { + externalStructs[output.Type.Package] = make(map[string]*ExternalStruct) + } + externalStructs[output.Type.Package][output.Type.Name] = &ExternalStruct{ + Package: output.Type.Package, + Name: output.Type.Name, + } + jsType = output.NamespacedStructVariable(output.Type.Package) } returns += jsType + ", " } @@ -196,7 +216,7 @@ func GenerateBinding(structName string, method *BoundMethod, useIDs bool) (strin } result = strings.ReplaceAll(result, " * @returns {Promise}", returns) - return result, lo.Uniq(models), lo.Uniq(namespacedStructs) + return result, lo.Uniq(models), externalStructs } func getPackageName(input *Parameter) string { @@ -240,47 +260,81 @@ func normalisePackageNames(packageNames []string) map[string]string { return result } -func GenerateBindings(bindings map[string]map[string][]*BoundMethod, useIDs bool) map[string]string { +func (p *Project) GenerateBindings(bindings map[string]map[string][]*BoundMethod, useIDs bool) map[string]map[string]string { - var result = make(map[string]string) + var result = make(map[string]map[string]string) - var normalisedPackageNames = normalisePackageNames(lo.Keys(bindings)) // sort the bindings keys packageNames := lo.Keys(bindings) sort.Strings(packageNames) for _, packageName := range packageNames { var allModels []string - var allNamespacedStructs []string packageBindings := bindings[packageName] structNames := lo.Keys(packageBindings) + relativePackageDir := p.RelativePackageDir(packageName) + _ = relativePackageDir sort.Strings(structNames) for _, structName := range structNames { - result[normalisedPackageNames[packageName]] += "export const " + structName + " = {\n" + if _, ok := result[relativePackageDir]; !ok { + result[relativePackageDir] = make(map[string]string) + } methods := packageBindings[structName] sort.Slice(methods, func(i, j int) bool { return methods[i].Name < methods[j].Name }) + var allNamespacedStructs map[packagePath]map[string]*ExternalStruct + var namespacedStructs map[packagePath]map[string]*ExternalStruct + var thisBinding string + var models []string for _, method := range methods { - thisBinding, models, namespacedStructs := GenerateBinding(structName, method, useIDs) - allNamespacedStructs = append(allNamespacedStructs, namespacedStructs...) + thisBinding, models, namespacedStructs = GenerateBinding(structName, method, useIDs) + // Merge the namespaced structs + allNamespacedStructs = mergeNamespacedStructs(allNamespacedStructs, namespacedStructs) allModels = append(allModels, models...) - result[normalisedPackageNames[packageName]] += thisBinding + result[relativePackageDir][structName] += thisBinding } - result[normalisedPackageNames[packageName]] += "};\n\n" - } - if len(allNamespacedStructs) > 0 { - typedefs := "/**\n" - for _, namespacedStruct := range lo.Uniq(allNamespacedStructs) { - typedefs += " * @typedef {import('./models')." + namespacedStruct + "} " + strings.ReplaceAll(namespacedStruct, ".", "") + "\n" + if len(allNamespacedStructs) > 0 { + thisPkg := p.packageCache[packageName] + typedefs := "/**\n" + for externalPackageName, namespacedStruct := range allNamespacedStructs { + pkgInfo := p.packageCache[externalPackageName] + relativePackageDir := p.RelativeBindingsDir(thisPkg, pkgInfo) + namePrefix := "" + if pkgInfo.Name != "" && pkgInfo.Path != thisPkg.Path { + namePrefix = pkgInfo.Name + } + + // Get keys from namespacedStruct and iterate over them in sorted order + namespacedStructNames := lo.Keys(namespacedStruct) + sort.Strings(namespacedStructNames) + for _, thisStructName := range namespacedStructNames { + structInfo := namespacedStruct[thisStructName] + typedefs += " * @typedef {import('" + relativePackageDir + "/models')." + thisStructName + "} " + namePrefix + structInfo.Name + "\n" + } + } + typedefs += " */\n" + result[relativePackageDir][structName] = typedefs + result[relativePackageDir][structName] } - typedefs += " */\n\n" - result[normalisedPackageNames[packageName]] = typedefs + result[normalisedPackageNames[packageName]] + result[relativePackageDir][structName] = header + result[relativePackageDir][structName] } - - result[normalisedPackageNames[packageName]] = header + result[normalisedPackageNames[packageName]] } return result } + +func mergeNamespacedStructs(structs map[packagePath]map[string]*ExternalStruct, structs2 map[packagePath]map[string]*ExternalStruct) map[packagePath]map[string]*ExternalStruct { + if structs == nil { + structs = make(map[packagePath]map[string]*ExternalStruct) + } + for pkg, pkgStructs := range structs2 { + if _, ok := structs[pkg]; !ok { + structs[pkg] = make(map[string]*ExternalStruct) + } + for name, structInfo := range pkgStructs { + structs[pkg][name] = structInfo + } + } + return structs +} diff --git a/v3/internal/parser/bindings_test.go b/v3/internal/parser/bindings_test.go index 89858adec..58977cb8b 100644 --- a/v3/internal/parser/bindings_test.go +++ b/v3/internal/parser/bindings_test.go @@ -2,11 +2,11 @@ package parser import ( "embed" + "github.com/google/go-cmp/cmp" "io/fs" "os" + "path/filepath" "testing" - - "github.com/google/go-cmp/cmp" ) //go:embed testdata @@ -25,135 +25,342 @@ func TestGenerateBindings(t *testing.T) { tests := []struct { dir string - want map[string]string + want map[string]map[string]string useIDs bool }{ { - "testdata/enum", - map[string]string{ - "main": getFile("testdata/enum/bindings_main.js"), + dir: "testdata/enum", + want: map[string]map[string]string{ + "main": { + "GreetService": getFile("testdata/enum/frontend/bindings/main/GreetService.js"), + }, }, - true, + useIDs: true, }, { - "testdata/enum", - map[string]string{ - "main": getFile("testdata/enum/bindings_main.name.js"), + dir: "testdata/enum", + want: map[string]map[string]string{ + "main": { + "GreetService": getFile("testdata/enum/frontend/bindings/main/GreetService.name.js"), + }, }, - false, - }, - // TODO: Fix this test to pull in enum - { - "testdata/enum_from_imported_package", - map[string]string{ - "main": getFile("testdata/enum_from_imported_package/bindings_main.js"), - }, - true, }, { - "testdata/function_single", - map[string]string{ - "main": getFile("testdata/function_single/bindings_main.js"), + dir: "testdata/enum_from_imported_package", + want: map[string]map[string]string{ + "main": { + "GreetService": getFile("testdata/enum_from_imported_package/frontend/bindings/main/GreetService.name.js"), + }, }, - true, }, { - "testdata/function_from_imported_package", - map[string]string{ - "main": getFile("testdata/function_from_imported_package/bindings_main.js"), - "services": getFile("testdata/function_from_imported_package/bindings_services.js"), + dir: "testdata/enum_from_imported_package", + want: map[string]map[string]string{ + "main": { + "GreetService": getFile("testdata/enum_from_imported_package/frontend/bindings/main/GreetService.js"), + }, }, - true, + useIDs: true, }, { - "testdata/variable_single", - map[string]string{ - "main": getFile("testdata/variable_single/bindings_main.js"), + dir: "testdata/function_single", + want: map[string]map[string]string{ + "main": { + "GreetService": getFile("testdata/function_single/frontend/bindings/main/GreetService.js"), + }, }, - true, + useIDs: true, }, { - "testdata/variable_single_from_function", - map[string]string{ - "main": getFile("testdata/variable_single_from_function/bindings_main.js"), + dir: "testdata/function_single", + want: map[string]map[string]string{ + "main": { + "GreetService": getFile("testdata/function_single/frontend/bindings/main/GreetService.name.js"), + }, }, - true, + useIDs: false, }, { - "testdata/variable_single_from_other_function", - map[string]string{ - "main": getFile("testdata/variable_single_from_other_function/bindings_main.js"), - "services": getFile("testdata/variable_single_from_other_function/bindings_services.js"), + dir: "testdata/function_from_imported_package", + want: map[string]map[string]string{ + "main": { + "GreetService": getFile("testdata/function_from_imported_package/frontend/bindings/main/GreetService.name.js"), + }, + "services": { + "OtherService": getFile("testdata/function_from_imported_package/frontend/bindings/services/OtherService.name.js"), + }, }, - true, + useIDs: false, }, { - "testdata/struct_literal_single", - map[string]string{ - "main": getFile("testdata/struct_literal_single/bindings_main.js"), + dir: "testdata/function_from_imported_package", + want: map[string]map[string]string{ + "main": { + "GreetService": getFile("testdata/function_from_imported_package/frontend/bindings/main/GreetService.js"), + }, + "services": { + "OtherService": getFile("testdata/function_from_imported_package/frontend/bindings/services/OtherService.js"), + }, }, - true, + useIDs: true, }, { - "testdata/struct_literal_multiple", - map[string]string{ - "main": getFile("testdata/struct_literal_multiple/bindings_main.js"), + dir: "testdata/function_from_nested_imported_package", + want: map[string]map[string]string{ + "main": { + "GreetService": getFile("testdata/function_from_nested_imported_package/frontend/bindings/main/GreetService.name.js"), + }, + "services/other": { + "OtherService": getFile("testdata/function_from_nested_imported_package/frontend/bindings/services/other/OtherService.name.js"), + }, }, - true, + useIDs: false, }, { - "testdata/struct_literal_multiple_other", - map[string]string{ - "main": getFile("testdata/struct_literal_multiple_other/bindings_main.js"), - "services": getFile("testdata/struct_literal_multiple_other/bindings_services.js"), + dir: "testdata/function_from_nested_imported_package", + want: map[string]map[string]string{ + "main": { + "GreetService": getFile("testdata/function_from_nested_imported_package/frontend/bindings/main/GreetService.js"), + }, + "services/other": { + "OtherService": getFile("testdata/function_from_nested_imported_package/frontend/bindings/services/other/OtherService.js"), + }, }, - true, + useIDs: true, }, { - "testdata/struct_literal_multiple_files", - map[string]string{ - "main": getFile("testdata/struct_literal_multiple_files/bindings_main.js"), + dir: "testdata/struct_literal_multiple", + want: map[string]map[string]string{ + "main": { + "GreetService": getFile("testdata/struct_literal_multiple/frontend/bindings/main/GreetService.js"), + "OtherService": getFile("testdata/struct_literal_multiple/frontend/bindings/main/OtherService.js"), + }, }, - true, + useIDs: true, + }, + { + dir: "testdata/struct_literal_multiple", + want: map[string]map[string]string{ + "main": { + "GreetService": getFile("testdata/struct_literal_multiple/frontend/bindings/main/GreetService.name.js"), + "OtherService": getFile("testdata/struct_literal_multiple/frontend/bindings/main/OtherService.name.js"), + }, + }, + useIDs: false, + }, + { + dir: "testdata/function_from_imported_package", + want: map[string]map[string]string{ + "main": { + "GreetService": getFile("testdata/function_from_imported_package/frontend/bindings/main/GreetService.js"), + }, + "services": { + "OtherService": getFile("testdata/function_from_imported_package/frontend/bindings/services/OtherService.js"), + }, + }, + useIDs: true, + }, + { + dir: "testdata/function_from_imported_package", + want: map[string]map[string]string{ + "main": { + "GreetService": getFile("testdata/function_from_imported_package/frontend/bindings/main/GreetService.name.js"), + }, + "services": { + "OtherService": getFile("testdata/function_from_imported_package/frontend/bindings/services/OtherService.name.js"), + }, + }, + useIDs: false, + }, + { + dir: "testdata/variable_single", + want: map[string]map[string]string{ + "main": { + "GreetService": getFile("testdata/variable_single/frontend/bindings/main/GreetService.name.js"), + }, + }, + useIDs: false, + }, + { + dir: "testdata/variable_single", + want: map[string]map[string]string{ + "main": { + "GreetService": getFile("testdata/variable_single/frontend/bindings/main/GreetService.js"), + }, + }, + useIDs: true, + }, + { + dir: "testdata/variable_single_from_function", + want: map[string]map[string]string{ + "main": { + "GreetService": getFile("testdata/variable_single_from_function/frontend/bindings/main/GreetService.name.js"), + }, + }, + useIDs: false, + }, + { + dir: "testdata/variable_single_from_function", + want: map[string]map[string]string{ + "main": { + "GreetService": getFile("testdata/variable_single_from_function/frontend/bindings/main/GreetService.js"), + }, + }, + useIDs: true, + }, + { + dir: "testdata/variable_single_from_other_function", + want: map[string]map[string]string{ + "main": { + "GreetService": getFile("testdata/variable_single_from_other_function/frontend/bindings/main/GreetService.name.js"), + }, + "services": { + "OtherService": getFile("testdata/variable_single_from_other_function/frontend/bindings/services/OtherService.name.js"), + }, + }, + useIDs: false, + }, + { + dir: "testdata/variable_single_from_other_function", + want: map[string]map[string]string{ + "main": { + "GreetService": getFile("testdata/variable_single_from_other_function/frontend/bindings/main/GreetService.js"), + }, + "services": { + "OtherService": getFile("testdata/variable_single_from_other_function/frontend/bindings/services/OtherService.js"), + }, + }, + useIDs: true, + }, + { + dir: "testdata/struct_literal_single", + want: map[string]map[string]string{ + "main": { + "GreetService": getFile("testdata/struct_literal_single/frontend/bindings/main/GreetService.name.js"), + }, + }, + useIDs: false, + }, + { + dir: "testdata/struct_literal_single", + want: map[string]map[string]string{ + "main": { + "GreetService": getFile("testdata/struct_literal_single/frontend/bindings/main/GreetService.js"), + }, + }, + useIDs: true, + }, + { + dir: "testdata/struct_literal_multiple_other", + want: map[string]map[string]string{ + "main": { + "GreetService": getFile("testdata/struct_literal_multiple_other/frontend/bindings/main/GreetService.name.js"), + }, + "services": { + "OtherService": getFile("testdata/struct_literal_multiple_other/frontend/bindings/services/OtherService.name.js"), + }, + }, + useIDs: false, + }, + { + dir: "testdata/struct_literal_multiple_other", + want: map[string]map[string]string{ + "main": { + "GreetService": getFile("testdata/struct_literal_multiple_other/frontend/bindings/main/GreetService.js"), + }, + "services": { + "OtherService": getFile("testdata/struct_literal_multiple_other/frontend/bindings/services/OtherService.js"), + }, + }, + useIDs: true, + }, + { + dir: "testdata/struct_literal_non_pointer_single", + want: map[string]map[string]string{ + "main": { + "GreetService": getFile("testdata/struct_literal_non_pointer_single/frontend/bindings/main/GreetService.name.js"), + }, + }, + useIDs: false, + }, + { + dir: "testdata/struct_literal_non_pointer_single", + want: map[string]map[string]string{ + "main": { + "GreetService": getFile("testdata/struct_literal_non_pointer_single/frontend/bindings/main/GreetService.js"), + }, + }, + useIDs: true, + }, + { + dir: "testdata/struct_literal_multiple_files", + want: map[string]map[string]string{ + "main": { + "GreetService": getFile("testdata/struct_literal_multiple_files/frontend/bindings/main/GreetService.name.js"), + "OtherService": getFile("testdata/struct_literal_multiple_files/frontend/bindings/main/OtherService.name.js"), + }, + }, + useIDs: false, + }, + { + dir: "testdata/struct_literal_multiple_files", + want: map[string]map[string]string{ + "main": { + "GreetService": getFile("testdata/struct_literal_multiple_files/frontend/bindings/main/GreetService.js"), + "OtherService": getFile("testdata/struct_literal_multiple_files/frontend/bindings/main/OtherService.js"), + }, + }, + useIDs: true, }, } for _, tt := range tests { t.Run(tt.dir, func(t *testing.T) { // Run parser on directory - project, err := ParseProject(tt.dir) + absDir, err := filepath.Abs(tt.dir) + if err != nil { + t.Errorf("filepath.Abs() error = %v", err) + return + } + project, err := ParseProject(absDir) if err != nil { t.Errorf("ParseProject() error = %v", err) return } + project.outputDirectory = "frontend/bindings" + // Generate Bindings - got := GenerateBindings(project.BoundMethods, tt.useIDs) + got := project.GenerateBindings(project.BoundMethods, tt.useIDs) - for name, binding := range got { - // check if the binding is in the expected bindings - expected, ok := tt.want[name] - if !ok { - err = os.WriteFile(tt.dir+"/bindings_"+name+".got.js", []byte(binding), 0644) - if err != nil { - t.Errorf("os.WriteFile() error = %v", err) + for dirName, structDetails := range got { + // iterate the struct names in structDetails + for name, binding := range structDetails { + expected, ok := tt.want[dirName][name] + if !ok { + outFile := filepath.Join(tt.dir, project.outputDirectory, dirName, name+".got.js") + err = os.WriteFile(outFile, []byte(binding), 0644) + if err != nil { + t.Errorf("os.WriteFile() error = %v", err) + return + } + t.Errorf("GenerateBindings() unexpected binding = %v", name) return } - t.Errorf("GenerateBindings() unexpected binding = %v", name) - return - } - // compare the binding + // compare the binding - // convert all line endings to \n - binding = convertLineEndings(binding) - expected = convertLineEndings(expected) + // convert all line endings to \n + binding = convertLineEndings(binding) + expected = convertLineEndings(expected) - if diff := cmp.Diff(expected, binding); diff != "" { - err = os.WriteFile(tt.dir+"/bindings_"+name+".got.js", []byte(binding), 0644) - if err != nil { - t.Errorf("os.WriteFile() error = %v", err) - return + if diff := cmp.Diff(expected, binding); diff != "" { + outFile := filepath.Join(tt.dir, project.outputDirectory, dirName, name+".got.js") + err = os.WriteFile(outFile, []byte(binding), 0644) + if err != nil { + t.Errorf("os.WriteFile() error = %v", err) + return + } + t.Fatalf("GenerateBindings() mismatch (-want +got):\n%s", diff) } - t.Fatalf("GenerateBindings() mismatch (-want +got):\n%s", diff) } } }) diff --git a/v3/internal/parser/models.go b/v3/internal/parser/models.go index e0e3cf419..491f4acb9 100644 --- a/v3/internal/parser/models.go +++ b/v3/internal/parser/models.go @@ -17,9 +17,10 @@ type ModelDefinitions struct { Package string Models map[string]*StructDef Enums map[string]*TypeDef + Imports []*ImportDef } -func GenerateModel(wr io.Writer, def *ModelDefinitions, options *flags.GenerateBindingsOptions) error { +func (p *Project) GenerateModel(wr io.Writer, def *ModelDefinitions, options *flags.GenerateBindingsOptions) error { templateName := "model.js.tmpl" if options.TS { templateName = "model.ts.tmpl" @@ -57,13 +58,15 @@ func pkgAlias(fullPkg string) string { return pkgParts[len(pkgParts)-1] } -func GenerateModels(models map[packagePath]map[structName]*StructDef, enums map[packagePath]map[string]*TypeDef, options *flags.GenerateBindingsOptions) (string, error) { - if models == nil && enums == nil { - return "", nil - } +type Model struct { + Package string +} - var buffer bytes.Buffer - buffer.WriteString(modelsHeader) +func (p *Project) GenerateModels(models map[packagePath]map[structName]*StructDef, enums map[packagePath]map[string]*TypeDef, options *flags.GenerateBindingsOptions) (map[packagePath]string, error) { + if models == nil && enums == nil { + return nil, nil + } + var result = make(map[packagePath]string) // sort pkgs by alias (e.g. services) instead of full pkg name (e.g. github.com/wailsapp/wails/somedir/services) // and then sort resulting list by the alias @@ -80,14 +83,21 @@ func GenerateModels(models map[packagePath]map[structName]*StructDef, enums map[ }) for _, pkg := range keys { - err := GenerateModel(&buffer, &ModelDefinitions{ + var buffer bytes.Buffer + buffer.WriteString(modelsHeader) + err := p.GenerateModel(&buffer, &ModelDefinitions{ + Imports: p.calculateImports(pkg, models[pkg]), Package: pkgAlias(pkg), Models: models[pkg], Enums: enums[pkg], }, options) if err != nil { - return "", err + return nil, err } + + // Get the relative package path + relativePackageDir := p.RelativePackageDir(pkg) + result[relativePackageDir] = buffer.String() } - return buffer.String(), nil + return result, nil } diff --git a/v3/internal/parser/models_test.go b/v3/internal/parser/models_test.go index 0e70b57f4..bae289474 100644 --- a/v3/internal/parser/models_test.go +++ b/v3/internal/parser/models_test.go @@ -14,109 +14,199 @@ func TestGenerateModels(t *testing.T) { tests := []struct { name string dir string - want string + want map[string]string useInterface bool useTypescript bool }{ + // enum { - name: "function single", - dir: "testdata/function_single", - useTypescript: true, - }, - { - name: "function from imported package", - dir: "testdata/function_from_imported_package", - want: getFile("testdata/function_from_imported_package/models.ts"), - useTypescript: true, - }, - { - name: "function from imported package (Javascript)", - dir: "testdata/function_from_imported_package", - want: getFile("testdata/function_from_imported_package/models.js"), - }, - { - name: "variable single", - dir: "testdata/variable_single", - useTypescript: true, - }, - { - name: "variable single from function", - dir: "testdata/variable_single_from_function", - useTypescript: true, - }, - { - name: "variable single from other function", - dir: "testdata/variable_single_from_other_function", - want: getFile("testdata/variable_single_from_other_function/models.ts"), - useTypescript: true, - }, - { - name: "struct literal single", - dir: "testdata/struct_literal_single", - want: getFile("testdata/struct_literal_single/models.ts"), - useTypescript: true, - }, - { - name: "struct literal multiple", - dir: "testdata/struct_literal_multiple", - useTypescript: true, - }, - { - name: "struct literal multiple other", - dir: "testdata/struct_literal_multiple_other", - want: getFile("testdata/struct_literal_multiple_other/models.ts"), - useTypescript: true, - }, - { - name: "struct literal multiple other (Javascript)", - dir: "testdata/struct_literal_multiple_other", - want: getFile("testdata/struct_literal_multiple_other/models.js"), - }, - { - name: "struct literal non pointer single (Javascript)", - dir: "testdata/struct_literal_non_pointer_single", - want: getFile("testdata/struct_literal_non_pointer_single/models.ts"), - useTypescript: true, - }, - { - name: "struct literal non pointer single (Javascript)", - dir: "testdata/struct_literal_non_pointer_single", - want: getFile("testdata/struct_literal_non_pointer_single/models.js"), - }, - { - name: "struct literal multiple files", - dir: "testdata/struct_literal_multiple_files", - useTypescript: true, - }, - { - name: "enum", - dir: "testdata/enum", - want: getFile("testdata/enum/models.ts"), - useTypescript: true, - }, - { - name: "enum (Javascript)", + name: "enum - Typescript", dir: "testdata/enum", - want: getFile("testdata/enum/models.js"), - }, - { - name: "enum from imported package", - dir: "testdata/enum_from_imported_package", - want: getFile("testdata/enum_from_imported_package/models.ts"), + want: map[string]string{ + "main": getFile("testdata/enum/frontend/bindings/main/models.ts"), + }, useTypescript: true, }, { - name: "enum from imported package", - dir: "testdata/enum_from_imported_package", - want: getFile("testdata/enum_from_imported_package/models.js"), + name: "enum - Javascript", + dir: "testdata/enum", + want: map[string]string{ + "main": getFile("testdata/enum/frontend/bindings/main/models.js"), + }, useTypescript: false, }, { - name: "enum interface", - dir: "testdata/enum-interface", - want: getFile("testdata/enum-interface/models.ts"), - useInterface: true, + name: "enum - Typescript interfaces", + dir: "testdata/enum", + want: map[string]string{ + "main": getFile("testdata/enum/frontend/bindings/main/models.interfaces.ts"), + }, useTypescript: true, + useInterface: true, + }, + // function from imported package + { + name: "function from imported package - Typescript", + dir: "testdata/function_from_imported_package", + want: map[string]string{ + "main": getFile("testdata/function_from_imported_package/frontend/bindings/main/models.ts"), + "services": getFile("testdata/function_from_imported_package/frontend/bindings/services/models.ts"), + }, + useTypescript: true, + }, + { + name: "function from imported package - Typescript interfaces", + dir: "testdata/function_from_imported_package", + want: map[string]string{ + "main": getFile("testdata/function_from_imported_package/frontend/bindings/main/models.interfaces.ts"), + "services": getFile("testdata/function_from_imported_package/frontend/bindings/services/models.interfaces.ts"), + }, + useTypescript: true, + useInterface: true, + }, + { + name: "function from imported package - Javascript", + dir: "testdata/function_from_imported_package", + want: map[string]string{ + "main": getFile("testdata/function_from_imported_package/frontend/bindings/main/models.js"), + "services": getFile("testdata/function_from_imported_package/frontend/bindings/services/models.js"), + }, + useTypescript: false, + }, + // variable single from other function + { + name: "variable single from other function - Typescript", + dir: "testdata/variable_single_from_other_function", + want: map[string]string{ + "main": getFile("testdata/variable_single_from_other_function/frontend/bindings/main/models.ts"), + "services": getFile("testdata/variable_single_from_other_function/frontend/bindings/services/models.ts"), + }, + useTypescript: true, + }, + { + name: "variable single from other function - Typescript interfaces", + dir: "testdata/variable_single_from_other_function", + want: map[string]string{ + "main": getFile("testdata/variable_single_from_other_function/frontend/bindings/main/models.interfaces.ts"), + "services": getFile("testdata/variable_single_from_other_function/frontend/bindings/services/models.interfaces.ts"), + }, + useTypescript: true, + useInterface: true, + }, + { + name: "variable single from other function - Javascript", + dir: "testdata/variable_single_from_other_function", + want: map[string]string{ + "main": getFile("testdata/variable_single_from_other_function/frontend/bindings/main/models.js"), + "services": getFile("testdata/variable_single_from_other_function/frontend/bindings/services/models.js"), + }, + useTypescript: false, + }, + // struct literal single + { + name: "struct literal single - Typescript", + dir: "testdata/struct_literal_single", + want: map[string]string{ + "main": getFile("testdata/struct_literal_single/frontend/bindings/main/models.ts"), + }, + useTypescript: true, + }, + { + name: "struct literal single - Typescript interfaces", + dir: "testdata/struct_literal_single", + want: map[string]string{ + "main": getFile("testdata/struct_literal_single/frontend/bindings/main/models.interfaces.ts"), + }, + useTypescript: true, + useInterface: true, + }, + { + name: "struct literal single - Javascript", + dir: "testdata/struct_literal_single", + want: map[string]string{ + "main": getFile("testdata/struct_literal_single/frontend/bindings/main/models.js"), + }, + useTypescript: false, + }, + // struct literal multiple other + { + name: "struct literal multiple other - Typescript", + dir: "testdata/struct_literal_multiple_other", + want: map[string]string{ + "main": getFile("testdata/struct_literal_multiple_other/frontend/bindings/main/models.ts"), + "services": getFile("testdata/struct_literal_multiple_other/frontend/bindings/services/models.ts"), + }, + useTypescript: true, + }, + { + name: "struct literal multiple other - Typescript interfaces", + dir: "testdata/struct_literal_multiple_other", + want: map[string]string{ + "main": getFile("testdata/struct_literal_multiple_other/frontend/bindings/main/models.interfaces.ts"), + "services": getFile("testdata/struct_literal_multiple_other/frontend/bindings/services/models.interfaces.ts"), + }, + useTypescript: true, + useInterface: true, + }, + { + name: "struct literal multiple other - Javascript", + dir: "testdata/struct_literal_multiple_other", + want: map[string]string{ + "main": getFile("testdata/struct_literal_multiple_other/frontend/bindings/main/models.js"), + "services": getFile("testdata/struct_literal_multiple_other/frontend/bindings/services/models.js"), + }, + useTypescript: false, + }, + // struct literal non pointer single + { + name: "struct literal non pointer single - Typescript", + dir: "testdata/struct_literal_non_pointer_single", + want: map[string]string{ + "main": getFile("testdata/struct_literal_non_pointer_single/frontend/bindings/main/models.ts"), + }, + useTypescript: true, + }, + { + name: "struct literal non pointer single - Typescript interfaces", + dir: "testdata/struct_literal_non_pointer_single", + want: map[string]string{ + "main": getFile("testdata/struct_literal_non_pointer_single/frontend/bindings/main/models.interfaces.ts"), + }, + useTypescript: true, + useInterface: true, + }, + { + name: "struct literal non pointer single - Javascript", + dir: "testdata/struct_literal_non_pointer_single", + want: map[string]string{ + "main": getFile("testdata/struct_literal_non_pointer_single/frontend/bindings/main/models.js"), + }, + useTypescript: false, + }, + // enum from imported package + { + name: "enum from imported package - Typescript", + dir: "testdata/enum_from_imported_package", + want: map[string]string{ + "services": getFile("testdata/enum_from_imported_package/frontend/bindings/services/models.ts"), + }, + useTypescript: true, + }, + { + name: "enum from imported package - Typescript interfaces", + dir: "testdata/enum_from_imported_package", + want: map[string]string{ + "services": getFile("testdata/enum_from_imported_package/frontend/bindings/services/models.interfaces.ts"), + }, + useTypescript: true, + }, + { + name: "enum from imported package - Javascript", + dir: "testdata/enum_from_imported_package", + want: map[string]string{ + "services": getFile("testdata/enum_from_imported_package/frontend/bindings/services/models.js"), + }, + useTypescript: false, }, } for _, tt := range tests { @@ -127,28 +217,39 @@ func TestGenerateModels(t *testing.T) { t.Fatalf("ParseProject() error = %v", err) } + project.outputDirectory = "frontend/bindings" + // Generate Models - got, err := GenerateModels(project.Models, project.Types, &flags.GenerateBindingsOptions{ + allModels, err := project.GenerateModels(project.Models, project.Types, &flags.GenerateBindingsOptions{ UseInterfaces: tt.useInterface, TS: tt.useTypescript, }) if err != nil { t.Fatalf("GenerateModels() error = %v", err) } - // convert all line endings to \n - got = convertLineEndings(got) - want := convertLineEndings(tt.want) - if diff := cmp.Diff(want, got); diff != "" { - gotFilename := "models.got.js" - if tt.useTypescript { - gotFilename = "models.got.ts" + for pkgDir, got := range allModels { + // convert all line endings to \n + got = convertLineEndings(got) + want, ok := tt.want[pkgDir] + if !ok { + t.Fatalf("GenerateModels() missing package: %s", pkgDir) } - err = os.WriteFile(filepath.Join(tt.dir, gotFilename), []byte(got), 0644) - if err != nil { - t.Errorf("os.WriteFile() error = %v", err) - return + want = convertLineEndings(want) + if diff := cmp.Diff(want, got); diff != "" { + gotFilename := "models.got.js" + if tt.useTypescript { + gotFilename = "models.got.ts" + } + // Get relative package path + //relativeBindingsDir := project.RelativeBindingsDir(project.packageCache[pkgDir]) + + err = os.WriteFile(filepath.Join(tt.dir, project.outputDirectory, pkgDir, gotFilename), []byte(got), 0644) + if err != nil { + t.Errorf("os.WriteFile() error = %v", err) + return + } + t.Fatalf("GenerateModels() mismatch (-want +got):\n%s", diff) } - t.Fatalf("GenerateModels() mismatch (-want +got):\n%s", diff) } }) } diff --git a/v3/internal/parser/parser.go b/v3/internal/parser/parser.go index 044a24d75..59e354bfa 100644 --- a/v3/internal/parser/parser.go +++ b/v3/internal/parser/parser.go @@ -23,9 +23,9 @@ type packagePath = string type structName = string type StructDef struct { - Name string - DocComment string - Fields []*Field + Name string + DocComments []string + Fields []*Field } func (s *StructDef) DefaultValueList() string { @@ -66,24 +66,24 @@ type Parameter struct { Type *ParameterType } -func (p *Parameter) NamespacedStructType() string { +func (p *Parameter) NamespacedStructType(pkgName string) string { var typeName string - if p.Type.Package != "" { + if p.Type.Package != "" && p.Type.Package != pkgName { parts := strings.Split(p.Type.Package, "/") typeName = parts[len(parts)-1] + "." } return typeName + p.Type.Name } -func (p *Parameter) NamespacedStructVariable() string { +func (p *Parameter) NamespacedStructVariable(pkgName string) string { var typeName string - if p.Type.Package != "" { + if p.Type.Package != "" && p.Type.Package != pkgName { parts := strings.Split(p.Type.Package, "/") typeName = parts[len(parts)-1] } return typeName + p.Type.Name } -func (p *Parameter) JSType() string { +func (p *Parameter) JSType(pkgName string) string { // Convert type to javascript equivalent type var typeName string switch p.Type.Name { @@ -99,7 +99,7 @@ func (p *Parameter) JSType() string { // if the type is a struct, we need to add the package name if p.Type.IsStruct || p.Type.IsEnum { - typeName = p.NamespacedStructType() + typeName = p.NamespacedStructType(pkgName) typeName = strings.ReplaceAll(typeName, ".", "") } @@ -118,6 +118,7 @@ func (p *Parameter) JSType() string { type BoundMethod struct { Package string + PackageDir string Name string DocComment string Inputs []*Parameter @@ -131,8 +132,9 @@ func (m BoundMethod) IDAsString() string { } type Field struct { - Name string - Type *ParameterType + Name string + Type *ParameterType + Project *Project } func (f *Field) JSName() string { @@ -195,17 +197,24 @@ func (f *Field) JSDocType(pkg string) string { jsType = f.Type.Name } + // If we are the same package, just return the type + externalPkgInfo := f.Project.packageCache[f.Type.Package] + if externalPkgInfo.Name == pkg { + return jsType + } + var result string isExternalStruct := f.Type.Package != "" && f.Type.Package != pkg && f.Type.IsStruct - if f.Type.Package == "" || f.Type.Package == pkg || !isExternalStruct { + if f.Type.Package == "" || !isExternalStruct { if f.Type.IsStruct || f.Type.IsEnum { - result = fmt.Sprintf("%s.%s", pkg, jsType) + // get the relative package directory + result = fmt.Sprintf("%s%s", externalPkgInfo.Name, f.Type.Name) } else { result = jsType } } else { - parts := strings.Split(f.Type.Package, "/") - result += fmt.Sprintf("%s.%s", parts[len(parts)-1], jsType) + // get the relative package directory + result = fmt.Sprintf("%s%s", externalPkgInfo.Name, f.Type.Name) } if !ast.IsExported(f.Name) { @@ -230,9 +239,9 @@ func (f *Field) DefaultValue() string { } type ConstDef struct { - Name string - DocComment string - Value string + Name string + DocComments []string + Value string } type TypeDef struct { @@ -258,6 +267,7 @@ type ParsedPackage struct { type Project struct { packageCache map[string]*ParsedPackage + outputDirectory string Path string BoundMethods map[packagePath]map[structName][]*BoundMethod Models map[packagePath]map[structName]*StructDef @@ -320,13 +330,21 @@ func GenerateBindingsAndModels(options *flags.GenerateBindingsOptions) error { return err } p.Stats.NumMethods = len(p.BoundMethods) - generatedMethods := GenerateBindings(p.BoundMethods, options.UseIDs) - for pkg, text := range generatedMethods { - // Write the file - err = os.WriteFile(filepath.Join(options.OutputDirectory, pkg+".js"), []byte(text), 0644) - if err != nil { + p.outputDirectory = options.OutputDirectory + generatedMethods := p.GenerateBindings(p.BoundMethods, options.UseIDs) + for pkg, structs := range generatedMethods { + // Write the directory + err = os.MkdirAll(filepath.Join(options.OutputDirectory, pkg), 0755) + if err != nil && !os.IsExist(err) { return err } + // Write the files + for structName, text := range structs { + err = os.WriteFile(filepath.Join(options.OutputDirectory, pkg, structName+".js"), []byte(text), 0644) + if err != nil { + return err + } + } } p.Stats.NumModels = len(p.Models) @@ -334,11 +352,17 @@ func GenerateBindingsAndModels(options *flags.GenerateBindingsOptions) error { // Generate Models if len(p.Models) > 0 { - generatedModels, err := GenerateModels(p.Models, p.Types, options) + generatedModels, err := p.GenerateModels(p.Models, p.Types, options) if err != nil { return err } - err = os.WriteFile(filepath.Join(options.OutputDirectory, options.ModelsFilename), []byte(generatedModels), 0644) + for pkg, text := range generatedModels { + // Get directory for package + pkgInfo := p.packageCache[pkg] + relativePackageDir := p.RelativeBindingsDir(pkgInfo, pkgInfo) + // Write the directory + err = os.WriteFile(filepath.Join(options.OutputDirectory, relativePackageDir, options.ModelsFilename), []byte(text), 0644) + } if err != nil { return err } @@ -602,6 +626,7 @@ func (p *Project) parseBoundStructMethods(name string, pkg *ParsedPackage) error method := &BoundMethod{ Package: pkg.Path, + PackageDir: pkg.Dir, ID: id, Name: funcDecl.Name.Name, DocComment: strings.TrimSpace(funcDecl.Doc.Text()), @@ -689,7 +714,8 @@ func (p *Project) parseParameterType(field *ast.Field, pkg *ParsedPackage) *Para result.Name = p.anonymousStructID() // Create a new struct definition result := &StructDef{ - Name: result.Name, + Name: result.Name, + DocComments: CommentGroupToText(field.Doc), } pkg.StructCache[result.Name] = result // Parse the fields @@ -750,8 +776,8 @@ func (p *Project) getStructDef(name string, pkg *ParsedPackage) bool { if structType, ok := typeSpec.Type.(*ast.StructType); ok { if typeSpec.Name.Name == name { result := &StructDef{ - Name: name, - //TODO DocComment: CommentGroupToText(typeDecl.Doc), + Name: name, + DocComments: CommentGroupToText(typeDecl.Doc), } pkg.StructCache[name] = result result.Fields = p.parseStructFields(structType, pkg) @@ -774,12 +800,14 @@ func (p *Project) parseStructFields(structType *ast.StructType, pkg *ParsedPacka if len(field.Names) > 0 { for _, name := range field.Names { theseFields = append(theseFields, &Field{ - Name: name.Name, + Project: p, + Name: name.Name, }) } } else { theseFields = append(theseFields, &Field{ - Name: "", + Project: p, + Name: "", }) } // loop over fields @@ -1079,7 +1107,7 @@ func (p *Project) parseConstDeclaration(decl *ast.GenDecl, pkg *ParsedPackage) { } if valueSpec.Doc != nil { - constDecl.DocComment = strings.TrimSpace(valueSpec.Doc.Text()) + constDecl.DocComments = CommentGroupToText(valueSpec.Doc) } typeDecl.Consts = append(typeDecl.Consts, constDecl) } @@ -1087,7 +1115,22 @@ func (p *Project) parseConstDeclaration(decl *ast.GenDecl, pkg *ParsedPackage) { } func (p *Project) RelativePackageDir(path string) string { - return strings.TrimPrefix(path, p.Path) + + // Get the package details + pkgInfo, ok := p.packageCache[path] + if !ok { + panic("package not found: " + path) + } + + result := filepath.ToSlash(strings.TrimPrefix(pkgInfo.Dir, p.Path)) + if result == "" { + return "main" + } + // Remove the leading slash + if result[0] == '/' || result[0] == '\\' { + result = result[1:] + } + return result } func (p *Project) parseTypes(pkgs map[string]*ParsedPackage) { @@ -1126,6 +1169,56 @@ func (p *Project) parseTypes(pkgs map[string]*ParsedPackage) { } } +func (p *Project) RelativeBindingsDir(dir *ParsedPackage, dir2 *ParsedPackage) string { + + if dir.Dir == dir2.Dir { + return "." + } + + // Calculate the relative path from the bindings directory to the package directory + absoluteSourceDir := dir.Dir + if absoluteSourceDir == p.Path { + absoluteSourceDir = filepath.Join(p.Path, p.outputDirectory, "main") + } else { + absoluteSourceDir = dir.Dir + } + targetRelativeDir := strings.TrimPrefix(dir2.Dir, p.Path) + targetBindingsDir := filepath.Join(p.Path, p.outputDirectory, targetRelativeDir) + // Calculate the relative path from the source directory to the target directory + relativePath, err := filepath.Rel(absoluteSourceDir, targetBindingsDir) + if err != nil { + panic(err) + } + return filepath.ToSlash(relativePath) +} + +type ImportDef struct { + Name string + Path string + VarName string + PackageName string +} + +func (p *Project) calculateImports(pkg string, m map[structName]*StructDef) []*ImportDef { + var result []*ImportDef + for _, structDef := range m { + for _, field := range structDef.Fields { + if field.Type.Package != pkg { + // Find the relative path from the source directory to the target directory + fieldPkgInfo := p.packageCache[field.Type.Package] + relativePath := p.RelativeBindingsDir(p.packageCache[pkg], fieldPkgInfo) + result = append(result, &ImportDef{ + PackageName: fieldPkgInfo.Name, + Name: field.Name, + Path: relativePath, + VarName: fieldPkgInfo.Name + field.Name, + }) + } + } + } + return result +} + func getTypeString(expr ast.Expr) string { switch t := expr.(type) { case *ast.Ident: diff --git a/v3/internal/parser/parser_enum_test.go b/v3/internal/parser/parser_enum_test.go index 10787cdb8..bf5b3513b 100644 --- a/v3/internal/parser/parser_enum_test.go +++ b/v3/internal/parser/parser_enum_test.go @@ -87,13 +87,14 @@ func TestParseEnum(t *testing.T) { wantTypes: map[string]map[string]*TypeDef{ "main": { "Title": { - Name: "Title", - Type: "string", + Name: "Title", + DocComments: []string{"// Title is a title"}, + Type: "string", Consts: []*ConstDef{ { - Name: "Mister", - DocComment: "Mister is a title", - Value: `"Mr"`, + Name: "Mister", + DocComments: []string{"// Mister is a title"}, + Value: `"Mr"`, }, { Name: "Miss", @@ -119,131 +120,8 @@ func TestParseEnum(t *testing.T) { wantModels: map[string]map[string]*StructDef{ "main": { "Person": { - Name: "Person", - Fields: []*Field{ - { - Name: "Title", - Type: &ParameterType{ - Package: "main", - Name: "Title", - IsEnum: true, - }, - }, - { - Name: "Name", - Type: &ParameterType{ - Package: "main", - Name: "string", - }, - }, - }, - }, - }, - }, - }, - { - name: "should find a bound service with an enum interface", - dir: "testdata/enum-interface", - wantErr: false, - wantBoundMethods: map[string]map[string][]*BoundMethod{ - "main": { - "GreetService": { - { - Package: "main", - Name: "Greet", - DocComment: "Greet does XYZ", - Inputs: []*Parameter{ - { - Name: "name", - Type: &ParameterType{ - Package: "main", - Name: "string", - }, - }, - { - Name: "title", - Type: &ParameterType{ - Package: "main", - Name: "Title", - IsEnum: true, - }, - }, - }, - Outputs: []*Parameter{ - { - Name: "", - Type: &ParameterType{ - Package: "main", - Name: "string", - }, - }, - }, - ID: 1411160069, - }, - { - Package: "main", - Name: "NewPerson", - DocComment: "NewPerson creates a new person", - Inputs: []*Parameter{ - { - Name: "name", - Type: &ParameterType{ - Package: "main", - Name: "string", - }, - }, - }, - Outputs: []*Parameter{ - { - Type: &ParameterType{ - Package: "main", - Name: "Person", - IsStruct: true, - IsPointer: true, - }, - }, - }, - ID: 1661412647, - }, - }, - }, - }, - wantTypes: map[string]map[string]*TypeDef{ - "main": { - "Title": { - Name: "Title", - Type: "string", - Consts: []*ConstDef{ - { - Name: "Mister", - DocComment: "Mister is a title", - Value: `"Mr"`, - }, - { - Name: "Miss", - Value: `"Miss"`, - }, - { - Name: "Ms", - Value: `"Ms"`, - }, - { - Name: "Mrs", - Value: `"Mrs"`, - }, - { - Name: "Dr", - Value: `"Dr"`, - }, - }, - ShouldGenerate: true, - }, - }, - }, - wantModels: map[string]map[string]*StructDef{ - "main": { - "Person": { - Name: "Person", + Name: "Person", + DocComments: []string{"// Person represents a person"}, Fields: []*Field{ { Name: "Title", @@ -273,6 +151,36 @@ func TestParseEnum(t *testing.T) { t.Errorf("ParseDirectory() error = %v, wantErr %v", err, tt.wantErr) return } + + // Patch the PackageDir in the wantBoundMethods + for _, packageData := range got.BoundMethods { + for _, boundMethods := range packageData { + for _, boundMethod := range boundMethods { + boundMethod.PackageDir = "" + } + } + } + + // Loop over the things we want + for packageName, packageData := range tt.wantBoundMethods { + for structName, wantBoundMethods := range packageData { + gotBoundMethods := got.BoundMethods[packageName][structName] + if diff := cmp.Diff(wantBoundMethods, gotBoundMethods); diff != "" { + t.Errorf("ParseDirectory() failed:\n" + diff) + } + } + } + + // Loop over the models + for _, packageData := range got.Models { + for _, wantModel := range packageData { + // Loop over the Fields + for _, field := range wantModel.Fields { + field.Project = nil + } + } + } + if diff := cmp.Diff(tt.wantBoundMethods, got.BoundMethods); diff != "" { t.Errorf("ParseDirectory() failed:\n" + diff) } diff --git a/v3/internal/parser/parser_function_test.go b/v3/internal/parser/parser_function_test.go index af1428551..bb979ef96 100644 --- a/v3/internal/parser/parser_function_test.go +++ b/v3/internal/parser/parser_function_test.go @@ -111,22 +111,23 @@ func TestParseFunction(t *testing.T) { }, }, }, - "github.com/wailsapp/wails/v3/internal/parser/testdata/variable_single_from_other_function/services": { + "github.com/wailsapp/wails/v3/internal/parser/testdata/function_from_imported_package/services": { "OtherService": { { - Package: "github.com/wailsapp/wails/v3/internal/parser/testdata/variable_single_from_other_function/services", - Name: "Yay", + Package: "github.com/wailsapp/wails/v3/internal/parser/testdata/function_from_imported_package/services", + Name: "Yay", + DocComment: "Yay does this and that", Outputs: []*Parameter{ { Type: &ParameterType{ Name: "Address", IsStruct: true, IsPointer: true, - Package: "github.com/wailsapp/wails/v3/internal/parser/testdata/variable_single_from_other_function/services", + Package: "github.com/wailsapp/wails/v3/internal/parser/testdata/function_from_imported_package/services", }, }, }, - ID: 302702907, + ID: 1592414782, }, }, }, @@ -134,7 +135,8 @@ func TestParseFunction(t *testing.T) { wantModels: map[string]map[string]*StructDef{ "main": { "Person": { - Name: "Person", + Name: "Person", + DocComments: []string{"// Person is a person"}, Fields: []*Field{ { Name: "Name", @@ -149,34 +151,34 @@ func TestParseFunction(t *testing.T) { Name: "Address", IsStruct: true, IsPointer: true, - Package: "github.com/wailsapp/wails/v3/internal/parser/testdata/variable_single_from_other_function/services", + Package: "github.com/wailsapp/wails/v3/internal/parser/testdata/function_from_imported_package/services", }, }, }, }, }, - "github.com/wailsapp/wails/v3/internal/parser/testdata/variable_single_from_other_function/services": { + "github.com/wailsapp/wails/v3/internal/parser/testdata/function_from_imported_package/services": { "Address": { Name: "Address", Fields: []*Field{ { Name: "Street", Type: &ParameterType{ - Package: "github.com/wailsapp/wails/v3/internal/parser/testdata/variable_single_from_other_function/services", + Package: "github.com/wailsapp/wails/v3/internal/parser/testdata/function_from_imported_package/services", Name: "string", }, }, { Name: "State", Type: &ParameterType{ - Package: "github.com/wailsapp/wails/v3/internal/parser/testdata/variable_single_from_other_function/services", + Package: "github.com/wailsapp/wails/v3/internal/parser/testdata/function_from_imported_package/services", Name: "string", }, }, { Name: "Country", Type: &ParameterType{ - Package: "github.com/wailsapp/wails/v3/internal/parser/testdata/variable_single_from_other_function/services", + Package: "github.com/wailsapp/wails/v3/internal/parser/testdata/function_from_imported_package/services", Name: "string", }, }, @@ -193,8 +195,40 @@ func TestParseFunction(t *testing.T) { t.Errorf("ParseDirectory() error = %v, wantErr %v", err, tt.wantErr) return } - if diff := cmp.Diff(tt.wantBoundMethods, got.BoundMethods); diff != "" { - t.Errorf("ParseDirectory() failed:\n" + diff) + + // Patch the PackageDir in the wantBoundMethods + for _, packageData := range got.BoundMethods { + for _, boundMethods := range packageData { + for _, boundMethod := range boundMethods { + boundMethod.PackageDir = "" + } + } + } + + // Loop over the things we want + for packageName, packageData := range tt.wantBoundMethods { + for structName, wantBoundMethods := range packageData { + gotBoundMethods := got.BoundMethods[packageName][structName] + if diff := cmp.Diff(wantBoundMethods, gotBoundMethods); diff != "" { + t.Errorf("ParseDirectory() failed:\n" + diff) + } + } + } + + // Loop over the models + for _, packageData := range got.Models { + for _, wantModel := range packageData { + // Loop over the Fields + for _, field := range wantModel.Fields { + field.Project = nil + } + } + } + + if !reflect.DeepEqual(tt.wantBoundMethods, got.BoundMethods) { + t.Errorf("ParseDirectory() failed:\n" + cmp.Diff(tt.wantBoundMethods, got.BoundMethods)) + //spew.Dump(tt.wantBoundMethods) + //spew.Dump(got.BoundMethods) } if !reflect.DeepEqual(tt.wantModels, got.Models) { t.Errorf("ParseDirectory() failed:\n" + cmp.Diff(tt.wantModels, got.Models)) diff --git a/v3/internal/parser/parser_struct_literal_multiple_test.go b/v3/internal/parser/parser_struct_literal_multiple_test.go index 5a35710d0..c15080f4a 100644 --- a/v3/internal/parser/parser_struct_literal_multiple_test.go +++ b/v3/internal/parser/parser_struct_literal_multiple_test.go @@ -163,8 +163,9 @@ func TestParseStructLiteralMultiple(t *testing.T) { "github.com/wailsapp/wails/v3/internal/parser/testdata/struct_literal_multiple_other/services": { "OtherService": { { - Package: "github.com/wailsapp/wails/v3/internal/parser/testdata/struct_literal_multiple_other/services", - Name: "Yay", + Package: "github.com/wailsapp/wails/v3/internal/parser/testdata/struct_literal_multiple_other/services", + Name: "Yay", + DocComment: "Yay does this and that", Outputs: []*Parameter{ { Type: &ParameterType{ @@ -242,6 +243,36 @@ func TestParseStructLiteralMultiple(t *testing.T) { t.Errorf("ParseDirectory() error = %v, wantErr %v", err, tt.wantErr) return } + + // Patch the PackageDir in the wantBoundMethods + for _, packageData := range got.BoundMethods { + for _, boundMethods := range packageData { + for _, boundMethod := range boundMethods { + boundMethod.PackageDir = "" + } + } + } + + // Loop over the things we want + for packageName, packageData := range tt.wantBoundMethods { + for structName, wantBoundMethods := range packageData { + gotBoundMethods := got.BoundMethods[packageName][structName] + if diff := cmp.Diff(wantBoundMethods, gotBoundMethods); diff != "" { + t.Errorf("ParseDirectory() failed:\n" + diff) + } + } + } + + // Loop over the models + for _, packageData := range got.Models { + for _, wantModel := range packageData { + // Loop over the Fields + for _, field := range wantModel.Fields { + field.Project = nil + } + } + } + if diff := cmp.Diff(tt.wantBoundMethods, got.BoundMethods); diff != "" { t.Errorf("ParseDirectory() failed:\n" + diff) } diff --git a/v3/internal/parser/parser_struct_literal_non_pointer_single_test.go b/v3/internal/parser/parser_struct_literal_non_pointer_single_test.go index 11c2ef280..694c4e516 100644 --- a/v3/internal/parser/parser_struct_literal_non_pointer_single_test.go +++ b/v3/internal/parser/parser_struct_literal_non_pointer_single_test.go @@ -1119,6 +1119,36 @@ func TestParseStructLiteralNonPointerSingle(t *testing.T) { t.Errorf("ParseDirectory() error = %v, wantErr %v", err, tt.wantErr) return } + + // Patch the PackageDir in the wantBoundMethods + for _, packageData := range got.BoundMethods { + for _, boundMethods := range packageData { + for _, boundMethod := range boundMethods { + boundMethod.PackageDir = "" + } + } + } + + // Loop over the things we want + for packageName, packageData := range tt.wantBoundMethods { + for structName, wantBoundMethods := range packageData { + gotBoundMethods := got.BoundMethods[packageName][structName] + if diff := cmp.Diff(wantBoundMethods, gotBoundMethods); diff != "" { + t.Errorf("ParseDirectory() failed:\n" + diff) + } + } + } + + // Loop over the models + for _, packageData := range got.Models { + for _, wantModel := range packageData { + // Loop over the Fields + for _, field := range wantModel.Fields { + field.Project = nil + } + } + } + if diff := cmp.Diff(tt.wantBoundMethods, got.BoundMethods); diff != "" { t.Errorf("ParseDirectory() failed:\n" + diff) } diff --git a/v3/internal/parser/parser_struct_literal_single_test.go b/v3/internal/parser/parser_struct_literal_single_test.go index 924eee66c..6f46e638a 100644 --- a/v3/internal/parser/parser_struct_literal_single_test.go +++ b/v3/internal/parser/parser_struct_literal_single_test.go @@ -1120,6 +1120,36 @@ func TestParseStructLiteralSingle(t *testing.T) { t.Errorf("ParseDirectory() error = %v, wantErr %v", err, tt.wantErr) return } + + // Patch the PackageDir in the wantBoundMethods + for _, packageData := range got.BoundMethods { + for _, boundMethods := range packageData { + for _, boundMethod := range boundMethods { + boundMethod.PackageDir = "" + } + } + } + + // Loop over the things we want + for packageName, packageData := range tt.wantBoundMethods { + for structName, wantBoundMethods := range packageData { + gotBoundMethods := got.BoundMethods[packageName][structName] + if diff := cmp.Diff(wantBoundMethods, gotBoundMethods); diff != "" { + t.Errorf("ParseDirectory() failed:\n" + diff) + } + } + } + + // Loop over the models + for _, packageData := range got.Models { + for _, wantModel := range packageData { + // Loop over the Fields + for _, field := range wantModel.Fields { + field.Project = nil + } + } + } + if diff := cmp.Diff(tt.wantBoundMethods, got.BoundMethods); diff != "" { t.Errorf("ParseDirectory() failed:\n" + diff) } diff --git a/v3/internal/parser/parser_variable_single_test.go b/v3/internal/parser/parser_variable_single_test.go index 8b5408d23..4a8794e25 100644 --- a/v3/internal/parser/parser_variable_single_test.go +++ b/v3/internal/parser/parser_variable_single_test.go @@ -149,8 +149,9 @@ func TestParseVariableSingle(t *testing.T) { "github.com/wailsapp/wails/v3/internal/parser/testdata/variable_single_from_other_function/services": { "OtherService": { { - Package: "github.com/wailsapp/wails/v3/internal/parser/testdata/variable_single_from_other_function/services", - Name: "Yay", + Package: "github.com/wailsapp/wails/v3/internal/parser/testdata/variable_single_from_other_function/services", + Name: "Yay", + DocComment: "Yay does this and that", Outputs: []*Parameter{ { Type: &ParameterType{ @@ -169,7 +170,8 @@ func TestParseVariableSingle(t *testing.T) { wantModels: map[string]map[string]*StructDef{ "main": { "Person": { - Name: "Person", + Name: "Person", + DocComments: []string{"// Person is a person!", "// They have a name and an address"}, Fields: []*Field{ { Name: "Name", @@ -228,6 +230,36 @@ func TestParseVariableSingle(t *testing.T) { t.Errorf("ParseDirectory() error = %v, wantErr %v", err, tt.wantErr) return } + + // Patch the PackageDir in the wantBoundMethods + for _, packageData := range got.BoundMethods { + for _, boundMethods := range packageData { + for _, boundMethod := range boundMethods { + boundMethod.PackageDir = "" + } + } + } + + // Loop over the things we want + for packageName, packageData := range tt.wantBoundMethods { + for structName, wantBoundMethods := range packageData { + gotBoundMethods := got.BoundMethods[packageName][structName] + if diff := cmp.Diff(wantBoundMethods, gotBoundMethods); diff != "" { + t.Errorf("ParseDirectory() failed:\n" + diff) + } + } + } + + // Loop over the models + for _, packageData := range got.Models { + for _, wantModel := range packageData { + // Loop over the Fields + for _, field := range wantModel.Fields { + field.Project = nil + } + } + } + if diff := cmp.Diff(tt.wantBoundMethods, got.BoundMethods); diff != "" { t.Errorf("ParseDirectory() failed:\n" + diff) } diff --git a/v3/internal/parser/templates/interfaces.ts.tmpl b/v3/internal/parser/templates/interfaces.ts.tmpl index 18d529320..9c433666d 100644 --- a/v3/internal/parser/templates/interfaces.ts.tmpl +++ b/v3/internal/parser/templates/interfaces.ts.tmpl @@ -1,20 +1,26 @@ -{{$pkg := .Package}} -export namespace {{.Package}} { - {{range $enumindex, $enumdef := .Enums}} - {{- range $commentindex, $commentdef := .DocComments}} - {{$commentdef -}} +{{- $pkg := .Package}}{{- range .Imports}} +import * as {{.PackageName}} from "{{.Path}}/models";{{- end}} +{{- range $enumindex, $enumdef := .Enums}} +{{- range $commentindex, $commentdef := $enumdef.DocComments}} +{{$commentdef -}} +{{- end}} +export enum {{$enumdef.Name}} { + {{- range $constindex, $constdef := .Consts}} + {{- if $constdef.DocComments}} + {{- range $commentindex, $commentdef := $constdef.DocComments}} + {{$commentdef -}} + {{- end }} {{- end}} - export enum {{$enumdef.Name}} { - {{- range $constindex, $constdef := .Consts}} - {{- if $constdef.DocComment}} - // {{$constdef.DocComment}} - {{- end}} - {{$constdef.Name}} = {{$constdef.Value}},{{end}} - } - {{- end}} - {{range $name, $def := .Models}} - export interface {{$def.Name}} { {{range $def.Fields}} - {{.JSDef $pkg}}{{end}} - } - {{end}} + {{$constdef.Name}} = {{$constdef.Value}},{{end}} } +{{- end}} +{{range $name, $def := .Models}} +{{- if $def.DocComments}} +{{- range $commentindex, $commentdef := $def.DocComments}} +{{$commentdef -}} +{{- end }} +{{- end}} +export interface {{$def.Name}} { {{- range $def.Fields}} + {{.JSDef $pkg}}{{end}} +} +{{end}} \ No newline at end of file diff --git a/v3/internal/parser/templates/model.js.tmpl b/v3/internal/parser/templates/model.js.tmpl index e204a9044..b03e704c4 100644 --- a/v3/internal/parser/templates/model.js.tmpl +++ b/v3/internal/parser/templates/model.js.tmpl @@ -1,21 +1,32 @@ {{$pkg := .Package}} -// Defining the {{$pkg}} namespace -export const {{$pkg}} = {}; -{{range $enumindex, $enumdef := .Enums}} -// Simulating the enum with an object -{{$pkg}}.{{$enumdef.Name}} = { +{{- if .Imports }} +/** +{{- range .Imports}} + * @typedef {import('{{.Path}}/models').{{.Name -}} } {{.VarName}} +{{- end}} + */ +{{end}} +{{- range $enumindex, $enumdef := .Enums}} +{{- range $commentindex, $commentdef := $enumdef.DocComments}} +{{$commentdef -}} +{{- end}} +export const {{$enumdef.Name}} = { {{- range $constindex, $constdef := .Consts}} - {{- if $constdef.DocComment}} - // {{$constdef.DocComment}} + {{- if $constdef.DocComments}} + {{- range $commentindex, $commentdef := $constdef.DocComments}} + {{$commentdef -}} + {{- end }} {{- end}} {{$constdef.Name}}: {{$constdef.Value}},{{end}} }; +{{end}} +{{- range $name, $def := .Models}} +{{- if $def.DocComments}} +{{- range $commentindex, $commentdef := $def.DocComments}} +{{$commentdef -}} +{{- end }} {{- end}} -{{range $name, $def := .Models}} -{{- if $def.DocComment}} -// {{$def.DocComment}} -{{- end -}} -{{$pkg}}.{{$def.Name}} = class { +export const {{$def.Name}} = class { /** * Creates a new {{$def.Name}} instance. * @constructor @@ -31,11 +42,11 @@ export const {{$pkg}} = {}; /** * Creates a new {{$def.Name}} instance from a string or object. * @param {string|object} source - The source data to create a {{$def.Name}} instance from. - * @returns {{$pkg}}.{{$def.Name}} A new {{$def.Name}} instance. + * @returns { {{- $def.Name -}} } A new {{$def.Name}} instance. */ - static createFrom(source = {}) { + static createFrom(source) { let parsedSource = typeof source === 'string' ? JSON.parse(source) : source; - return new {{$pkg}}.{{$def.Name}}(parsedSource); + return new {{$def.Name}}(parsedSource); } }; {{end}} diff --git a/v3/internal/parser/templates/model.ts.tmpl b/v3/internal/parser/templates/model.ts.tmpl index 820ef8a87..15972a674 100644 --- a/v3/internal/parser/templates/model.ts.tmpl +++ b/v3/internal/parser/templates/model.ts.tmpl @@ -1,31 +1,38 @@ -{{$pkg := .Package}} -export namespace {{.Package}} { - {{range $enumindex, $enumdef := .Enums}} - {{- range $commentindex, $commentdef := .DocComments}} - {{$commentdef -}} +{{- $pkg := .Package}}{{- range .Imports}} +import * as {{.PackageName}} from "{{.Path}}/models";{{- end}} +{{- range $enumindex, $enumdef := .Enums}} +{{- range $commentindex, $commentdef := $enumdef.DocComments}} +{{$commentdef -}} +{{- end}} +export enum {{$enumdef.Name}} { + {{- range $constindex, $constdef := .Consts}} + {{- if $constdef.DocComments}} + {{- range $commentindex, $commentdef := $constdef.DocComments}} + {{$commentdef -}} + {{- end }} {{- end}} - export enum {{$enumdef.Name}} { - {{- range $constindex, $constdef := .Consts}} - {{- if $constdef.DocComment}} - // {{$constdef.DocComment}} - {{- end}} - {{$constdef.Name}} = {{$constdef.Value}},{{end}} - } - {{- end}} - {{range $name, $def := .Models}} - export class {{$def.Name}} { - {{range $def.Fields}}{{.JSDef $pkg}} - {{end}} - constructor(source: Partial<{{$def.Name}}> = {}) { - const { {{$def.DefaultValueList}} } = source; {{range $def.Fields}} - this.{{.JSName}} = {{.JSName}};{{end}} - } - - static createFrom(source: string | object = {}): {{$def.Name}} { - let parsedSource = typeof source === 'string' ? JSON.parse(source) : source; - return new {{$def.Name}}(parsedSource as Partial<{{$def.Name}}>); - } + {{$constdef.Name}} = {{$constdef.Value}},{{end}} +} +{{- end}} +{{range $name, $def := .Models}} +{{- if $def.DocComments}} +{{- range $commentindex, $commentdef := $def.DocComments}} +{{$commentdef -}} +{{- end }} +{{- end}} +export class {{$def.Name}} { + {{- range $def.Fields}} + {{.JSDef $pkg}}{{end}} + constructor(source: Partial<{{$def.Name}}> = {}) { + const { {{- $def.DefaultValueList -}} } = source; +{{- range $def.Fields}} + this.{{.JSName}} = {{.JSName}};{{end}} } - {{end}} -} \ No newline at end of file + + static createFrom(source: string | object = {}): {{$def.Name}} { + let parsedSource = typeof source === 'string' ? JSON.parse(source) : source; + return new {{$def.Name}}(parsedSource as Partial<{{$def.Name}}>); + } +} +{{end}} \ No newline at end of file diff --git a/v3/internal/parser/testdata/enum-interface/bindings_main.js b/v3/internal/parser/testdata/enum-interface/bindings_main.js deleted file mode 100644 index e00a30769..000000000 --- a/v3/internal/parser/testdata/enum-interface/bindings_main.js +++ /dev/null @@ -1,29 +0,0 @@ -// @ts-check -// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL -// This file is automatically generated. DO NOT EDIT - -/** - * @typedef {import('./models').main.Title} mainTitle - * @typedef {import('./models').main.Person} mainPerson - */ - -export const GreetService = { - - /** - * GreetService.Greet - * Greet does XYZ - * @param name {string} - * @param title {mainTitle} - * @returns {Promise} - **/ - Greet: function(name, title) { return wails.CallByID(1411160069, ...Array.prototype.slice.call(arguments, 0)); }, - - /** - * GreetService.NewPerson - * NewPerson creates a new person - * @param name {string} - * @returns {Promise} - **/ - NewPerson: function(name) { return wails.CallByID(1661412647, ...Array.prototype.slice.call(arguments, 0)); }, -}; - diff --git a/v3/internal/parser/testdata/enum-interface/bindings_main.name.js b/v3/internal/parser/testdata/enum-interface/bindings_main.name.js deleted file mode 100644 index 5d77e1346..000000000 --- a/v3/internal/parser/testdata/enum-interface/bindings_main.name.js +++ /dev/null @@ -1,29 +0,0 @@ -// @ts-check -// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL -// This file is automatically generated. DO NOT EDIT - -/** - * @typedef {import('./models').main.Title} mainTitle - * @typedef {import('./models').main.Person} mainPerson - */ - -export const GreetService = { - - /** - * GreetService.Greet - * Greet does XYZ - * @param name {string} - * @param title {mainTitle} - * @returns {Promise} - **/ - Greet: function(name, title) { return wails.CallByName("main.GreetService.Greet", ...Array.prototype.slice.call(arguments, 0)); }, - - /** - * GreetService.NewPerson - * NewPerson creates a new person - * @param name {string} - * @returns {Promise} - **/ - NewPerson: function(name) { return wails.CallByName("main.GreetService.NewPerson", ...Array.prototype.slice.call(arguments, 0)); }, -}; - diff --git a/v3/internal/parser/testdata/enum-interface/models.ts b/v3/internal/parser/testdata/enum-interface/models.ts deleted file mode 100644 index 468455922..000000000 --- a/v3/internal/parser/testdata/enum-interface/models.ts +++ /dev/null @@ -1,21 +0,0 @@ -// @ts-check -// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL -// This file is automatically generated. DO NOT EDIT - -export namespace main { - - export enum Title { - // Mister is a title - Mister = "Mr", - Miss = "Miss", - Ms = "Ms", - Mrs = "Mrs", - Dr = "Dr", - } - - export interface Person { - title: Title; - name: string; - } - -} diff --git a/v3/internal/parser/testdata/enum/bindings_main.js b/v3/internal/parser/testdata/enum/bindings_main.js deleted file mode 100644 index e00a30769..000000000 --- a/v3/internal/parser/testdata/enum/bindings_main.js +++ /dev/null @@ -1,29 +0,0 @@ -// @ts-check -// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL -// This file is automatically generated. DO NOT EDIT - -/** - * @typedef {import('./models').main.Title} mainTitle - * @typedef {import('./models').main.Person} mainPerson - */ - -export const GreetService = { - - /** - * GreetService.Greet - * Greet does XYZ - * @param name {string} - * @param title {mainTitle} - * @returns {Promise} - **/ - Greet: function(name, title) { return wails.CallByID(1411160069, ...Array.prototype.slice.call(arguments, 0)); }, - - /** - * GreetService.NewPerson - * NewPerson creates a new person - * @param name {string} - * @returns {Promise} - **/ - NewPerson: function(name) { return wails.CallByID(1661412647, ...Array.prototype.slice.call(arguments, 0)); }, -}; - diff --git a/v3/internal/parser/testdata/enum/bindings_main.name.js b/v3/internal/parser/testdata/enum/bindings_main.name.js deleted file mode 100644 index 5d77e1346..000000000 --- a/v3/internal/parser/testdata/enum/bindings_main.name.js +++ /dev/null @@ -1,29 +0,0 @@ -// @ts-check -// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL -// This file is automatically generated. DO NOT EDIT - -/** - * @typedef {import('./models').main.Title} mainTitle - * @typedef {import('./models').main.Person} mainPerson - */ - -export const GreetService = { - - /** - * GreetService.Greet - * Greet does XYZ - * @param name {string} - * @param title {mainTitle} - * @returns {Promise} - **/ - Greet: function(name, title) { return wails.CallByName("main.GreetService.Greet", ...Array.prototype.slice.call(arguments, 0)); }, - - /** - * GreetService.NewPerson - * NewPerson creates a new person - * @param name {string} - * @returns {Promise} - **/ - NewPerson: function(name) { return wails.CallByName("main.GreetService.NewPerson", ...Array.prototype.slice.call(arguments, 0)); }, -}; - diff --git a/v3/internal/parser/testdata/enum/frontend/bindings/main/GreetService.js b/v3/internal/parser/testdata/enum/frontend/bindings/main/GreetService.js new file mode 100644 index 000000000..f368ca8b7 --- /dev/null +++ b/v3/internal/parser/testdata/enum/frontend/bindings/main/GreetService.js @@ -0,0 +1,29 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +/** + * @typedef {import('./models').Person} Person + * @typedef {import('./models').Title} Title + */ + +/** + * Greet does XYZ + * @function Greet + * @param name {string} + * @param title {Title} + * @returns {Promise} + **/ +export function Greet(name, title) { + return wails.CallByID(1411160069, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * NewPerson creates a new person + * @function NewPerson + * @param name {string} + * @returns {Promise} + **/ +export function NewPerson(name) { + return wails.CallByID(1661412647, ...Array.prototype.slice.call(arguments, 0)); +} diff --git a/v3/internal/parser/testdata/enum/frontend/bindings/main/GreetService.name.js b/v3/internal/parser/testdata/enum/frontend/bindings/main/GreetService.name.js new file mode 100644 index 000000000..96d1ab60a --- /dev/null +++ b/v3/internal/parser/testdata/enum/frontend/bindings/main/GreetService.name.js @@ -0,0 +1,29 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +/** + * @typedef {import('./models').Person} Person + * @typedef {import('./models').Title} Title + */ + +/** + * Greet does XYZ + * @function Greet + * @param name {string} + * @param title {Title} + * @returns {Promise} + **/ +export function Greet(name, title) { + return wails.CallByName("main.GreetService.Greet", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * NewPerson creates a new person + * @function NewPerson + * @param name {string} + * @returns {Promise} + **/ +export function NewPerson(name) { + return wails.CallByName("main.GreetService.NewPerson", ...Array.prototype.slice.call(arguments, 0)); +} diff --git a/v3/internal/parser/testdata/enum/frontend/bindings/main/models.interfaces.ts b/v3/internal/parser/testdata/enum/frontend/bindings/main/models.interfaces.ts new file mode 100644 index 000000000..85955ba5b --- /dev/null +++ b/v3/internal/parser/testdata/enum/frontend/bindings/main/models.interfaces.ts @@ -0,0 +1,19 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +// Title is a title +export enum Title { + // Mister is a title + Mister = "Mr", + Miss = "Miss", + Ms = "Ms", + Mrs = "Mrs", + Dr = "Dr", +} + +// Person represents a person +export interface Person { + title: Title; + name: string; +} diff --git a/v3/internal/parser/testdata/enum/models.js b/v3/internal/parser/testdata/enum/frontend/bindings/main/models.js similarity index 73% rename from v3/internal/parser/testdata/enum/models.js rename to v3/internal/parser/testdata/enum/frontend/bindings/main/models.js index 28f774a0d..229a5fff0 100644 --- a/v3/internal/parser/testdata/enum/models.js +++ b/v3/internal/parser/testdata/enum/frontend/bindings/main/models.js @@ -2,11 +2,8 @@ // Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL // This file is automatically generated. DO NOT EDIT -// Defining the main namespace -export const main = {}; - -// Simulating the enum with an object -main.Title = { +// Title is a title +export const Title = { // Mister is a title Mister: "Mr", Miss: "Miss", @@ -14,12 +11,14 @@ main.Title = { Mrs: "Mrs", Dr: "Dr", }; -main.Person = class { + +// Person represents a person +export const Person = class { /** * Creates a new Person instance. * @constructor * @param {Object} source - The source object to create the Person. - * @param {main.Title} source.Title + * @param {Title} source.Title * @param {string} source.Name */ constructor(source = {}) { @@ -31,11 +30,11 @@ main.Person = class { /** * Creates a new Person instance from a string or object. * @param {string|object} source - The source data to create a Person instance from. - * @returns main.Person A new Person instance. + * @returns {Person} A new Person instance. */ - static createFrom(source = {}) { + static createFrom(source) { let parsedSource = typeof source === 'string' ? JSON.parse(source) : source; - return new main.Person(parsedSource); + return new Person(parsedSource); } }; diff --git a/v3/internal/parser/testdata/enum/frontend/bindings/main/models.ts b/v3/internal/parser/testdata/enum/frontend/bindings/main/models.ts new file mode 100644 index 000000000..543740103 --- /dev/null +++ b/v3/internal/parser/testdata/enum/frontend/bindings/main/models.ts @@ -0,0 +1,30 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +// Title is a title +export enum Title { + // Mister is a title + Mister = "Mr", + Miss = "Miss", + Ms = "Ms", + Mrs = "Mrs", + Dr = "Dr", +} + +// Person represents a person +export class Person { + title: Title; + name: string; + + constructor(source: Partial = {}) { + const {title = null, name = ""} = source; + this.title = title; + this.name = name; + } + + static createFrom(source: string | object = {}): Person { + let parsedSource = typeof source === 'string' ? JSON.parse(source) : source; + return new Person(parsedSource as Partial); + } +} diff --git a/v3/internal/parser/testdata/enum/main.go b/v3/internal/parser/testdata/enum/main.go index d332966ed..a52284763 100644 --- a/v3/internal/parser/testdata/enum/main.go +++ b/v3/internal/parser/testdata/enum/main.go @@ -7,6 +7,7 @@ import ( "github.com/wailsapp/wails/v3/pkg/application" ) +// Title is a title type Title string const ( diff --git a/v3/internal/parser/testdata/enum/models.ts b/v3/internal/parser/testdata/enum/models.ts deleted file mode 100644 index a0a731498..000000000 --- a/v3/internal/parser/testdata/enum/models.ts +++ /dev/null @@ -1,33 +0,0 @@ -// @ts-check -// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL -// This file is automatically generated. DO NOT EDIT - -export namespace main { - - export enum Title { - // Mister is a title - Mister = "Mr", - Miss = "Miss", - Ms = "Ms", - Mrs = "Mrs", - Dr = "Dr", - } - - export class Person { - title: Title; - name: string; - - constructor(source: Partial = {}) { - const { title = null, name = "" } = source; - this.title = title; - this.name = name; - } - - static createFrom(source: string | object = {}): Person { - let parsedSource = typeof source === 'string' ? JSON.parse(source) : source; - return new Person(parsedSource as Partial); - } - - } - -} \ No newline at end of file diff --git a/v3/internal/parser/testdata/enum_from_imported_package/bindings_main.js b/v3/internal/parser/testdata/enum_from_imported_package/bindings_main.js deleted file mode 100644 index 489f40012..000000000 --- a/v3/internal/parser/testdata/enum_from_imported_package/bindings_main.js +++ /dev/null @@ -1,20 +0,0 @@ -// @ts-check -// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL -// This file is automatically generated. DO NOT EDIT - -/** - * @typedef {import('./models').services.Title} servicesTitle - */ - -export const GreetService = { - - /** - * GreetService.Greet - * Greet does XYZ - * @param name {string} - * @param title {servicesTitle} - * @returns {Promise} - **/ - Greet: function(name, title) { return wails.CallByID(1411160069, ...Array.prototype.slice.call(arguments, 0)); }, -}; - diff --git a/v3/internal/parser/testdata/enum_from_imported_package/bindings_main.name.js b/v3/internal/parser/testdata/enum_from_imported_package/bindings_main.name.js deleted file mode 100644 index 82c895cc7..000000000 --- a/v3/internal/parser/testdata/enum_from_imported_package/bindings_main.name.js +++ /dev/null @@ -1,20 +0,0 @@ -// @ts-check -// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL -// This file is automatically generated. DO NOT EDIT - -/** - * @typedef {import('./models').services.Title} servicesTitle - */ - -export const GreetService = { - - /** - * GreetService.Greet - * Greet does XYZ - * @param name {string} - * @param title {servicesTitle} - * @returns {Promise} - **/ - Greet: function(name, title) { return wails.CallByName("main.GreetService.Greet", ...Array.prototype.slice.call(arguments, 0)); }, -}; - diff --git a/v3/internal/parser/testdata/enum_from_imported_package/frontend/bindings/main/GreetService.js b/v3/internal/parser/testdata/enum_from_imported_package/frontend/bindings/main/GreetService.js new file mode 100644 index 000000000..17bb36f6f --- /dev/null +++ b/v3/internal/parser/testdata/enum_from_imported_package/frontend/bindings/main/GreetService.js @@ -0,0 +1,18 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +/** + * @typedef {import('../services/models').Title} servicesTitle + */ + +/** + * Greet does XYZ + * @function Greet + * @param name {string} + * @param title {servicesTitle} + * @returns {Promise} + **/ +export function Greet(name, title) { + return wails.CallByID(1411160069, ...Array.prototype.slice.call(arguments, 0)); +} diff --git a/v3/internal/parser/testdata/enum_from_imported_package/frontend/bindings/main/GreetService.name.js b/v3/internal/parser/testdata/enum_from_imported_package/frontend/bindings/main/GreetService.name.js new file mode 100644 index 000000000..37c044e56 --- /dev/null +++ b/v3/internal/parser/testdata/enum_from_imported_package/frontend/bindings/main/GreetService.name.js @@ -0,0 +1,18 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +/** + * @typedef {import('../services/models').Title} servicesTitle + */ + +/** + * Greet does XYZ + * @function Greet + * @param name {string} + * @param title {servicesTitle} + * @returns {Promise} + **/ +export function Greet(name, title) { + return wails.CallByName("main.GreetService.Greet", ...Array.prototype.slice.call(arguments, 0)); +} diff --git a/v3/internal/parser/testdata/enum_from_imported_package/frontend/bindings/services/models.interfaces.ts b/v3/internal/parser/testdata/enum_from_imported_package/frontend/bindings/services/models.interfaces.ts new file mode 100644 index 000000000..293207034 --- /dev/null +++ b/v3/internal/parser/testdata/enum_from_imported_package/frontend/bindings/services/models.interfaces.ts @@ -0,0 +1,12 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +export enum Title { + // Mister is a title + Mister = "Mr", + Miss = "Miss", + Ms = "Ms", + Mrs = "Mrs", + Dr = "Dr", +} diff --git a/v3/internal/parser/testdata/enum_from_imported_package/models.js b/v3/internal/parser/testdata/enum_from_imported_package/frontend/bindings/services/models.js similarity index 66% rename from v3/internal/parser/testdata/enum_from_imported_package/models.js rename to v3/internal/parser/testdata/enum_from_imported_package/frontend/bindings/services/models.js index 1dd20f0ff..2ea24de75 100644 --- a/v3/internal/parser/testdata/enum_from_imported_package/models.js +++ b/v3/internal/parser/testdata/enum_from_imported_package/frontend/bindings/services/models.js @@ -2,11 +2,7 @@ // Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL // This file is automatically generated. DO NOT EDIT -// Defining the services namespace -export const services = {}; - -// Simulating the enum with an object -services.Title = { +export const Title = { // Mister is a title Mister: "Mr", Miss: "Miss", diff --git a/v3/internal/parser/testdata/enum_from_imported_package/frontend/bindings/services/models.ts b/v3/internal/parser/testdata/enum_from_imported_package/frontend/bindings/services/models.ts new file mode 100644 index 000000000..293207034 --- /dev/null +++ b/v3/internal/parser/testdata/enum_from_imported_package/frontend/bindings/services/models.ts @@ -0,0 +1,12 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +export enum Title { + // Mister is a title + Mister = "Mr", + Miss = "Miss", + Ms = "Ms", + Mrs = "Mrs", + Dr = "Dr", +} diff --git a/v3/internal/parser/testdata/enum_from_imported_package/models.ts b/v3/internal/parser/testdata/enum_from_imported_package/models.ts deleted file mode 100644 index 79cee99b4..000000000 --- a/v3/internal/parser/testdata/enum_from_imported_package/models.ts +++ /dev/null @@ -1,16 +0,0 @@ -// @ts-check -// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL -// This file is automatically generated. DO NOT EDIT - -export namespace services { - - export enum Title { - // Mister is a title - Mister = "Mr", - Miss = "Miss", - Ms = "Ms", - Mrs = "Mrs", - Dr = "Dr", - } - -} \ No newline at end of file diff --git a/v3/internal/parser/testdata/function_from_imported_package/bindings_main.js b/v3/internal/parser/testdata/function_from_imported_package/bindings_main.js deleted file mode 100644 index ae0db8c58..000000000 --- a/v3/internal/parser/testdata/function_from_imported_package/bindings_main.js +++ /dev/null @@ -1,27 +0,0 @@ -// @ts-check -// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL -// This file is automatically generated. DO NOT EDIT - -/** - * @typedef {import('./models').main.Person} mainPerson - */ - -export const GreetService = { - - /** - * GreetService.Greet - * Greet does XYZ - * @param name {string} - * @returns {Promise} - **/ - Greet: function(name) { return wails.CallByID(1411160069, ...Array.prototype.slice.call(arguments, 0)); }, - - /** - * GreetService.NewPerson - * NewPerson creates a new person - * @param name {string} - * @returns {Promise} - **/ - NewPerson: function(name) { return wails.CallByID(1661412647, ...Array.prototype.slice.call(arguments, 0)); }, -}; - diff --git a/v3/internal/parser/testdata/function_from_imported_package/bindings_services.got.js b/v3/internal/parser/testdata/function_from_imported_package/bindings_services.got.js deleted file mode 100644 index 2ea85cd1e..000000000 --- a/v3/internal/parser/testdata/function_from_imported_package/bindings_services.got.js +++ /dev/null @@ -1,19 +0,0 @@ -// @ts-check -// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL -// This file is automatically generated. DO NOT EDIT - -/** - * @typedef {import('./models').services.Address} servicesAddress - */ - -export const OtherService = { - - /** - * OtherService.Yay - * - * - * @returns {Promise} - **/ - - Yay: function() { return wails.CallByID(302702907, ...Array.prototype.slice.call(arguments, 0)); },}; - diff --git a/v3/internal/parser/testdata/function_from_imported_package/bindings_services.js b/v3/internal/parser/testdata/function_from_imported_package/bindings_services.js deleted file mode 100644 index 9b0d9d63d..000000000 --- a/v3/internal/parser/testdata/function_from_imported_package/bindings_services.js +++ /dev/null @@ -1,19 +0,0 @@ -// @ts-check -// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL -// This file is automatically generated. DO NOT EDIT - -/** - * @typedef {import('./models').services.Address} servicesAddress - */ - -export const OtherService = { - - /** - * OtherService.Yay - * - * - * @returns {Promise} - **/ - Yay: function() { return wails.CallByID(302702907, ...Array.prototype.slice.call(arguments, 0)); }, -}; - diff --git a/v3/internal/parser/testdata/function_from_imported_package/boundmethods.got.json b/v3/internal/parser/testdata/function_from_imported_package/boundmethods.got.json new file mode 100644 index 000000000..a3502e53c --- /dev/null +++ b/v3/internal/parser/testdata/function_from_imported_package/boundmethods.got.json @@ -0,0 +1 @@ +map[string]map[string][]*parser.BoundMethod{"github.com/wailsapp/wails/v3/internal/parser/testdata/function_from_imported_package/services":map[string][]*parser.BoundMethod{"OtherService":[]*parser.BoundMethod{(*parser.BoundMethod)(0xc000148000)}}, "main":map[string][]*parser.BoundMethod{"GreetService":[]*parser.BoundMethod{(*parser.BoundMethod)(0xc0000c8a80), (*parser.BoundMethod)(0xc0000c8b00)}}} \ No newline at end of file diff --git a/v3/internal/parser/testdata/function_from_imported_package/frontend/bindings/main/GreetService.js b/v3/internal/parser/testdata/function_from_imported_package/frontend/bindings/main/GreetService.js new file mode 100644 index 000000000..e654b5d6c --- /dev/null +++ b/v3/internal/parser/testdata/function_from_imported_package/frontend/bindings/main/GreetService.js @@ -0,0 +1,27 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +/** + * @typedef {import('./models').Person} Person + */ + +/** + * Greet does XYZ + * @function Greet + * @param name {string} + * @returns {Promise} + **/ +export function Greet(name) { + return wails.CallByID(1411160069, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * NewPerson creates a new person + * @function NewPerson + * @param name {string} + * @returns {Promise} + **/ +export function NewPerson(name) { + return wails.CallByID(1661412647, ...Array.prototype.slice.call(arguments, 0)); +} diff --git a/v3/internal/parser/testdata/function_from_imported_package/frontend/bindings/main/GreetService.name.js b/v3/internal/parser/testdata/function_from_imported_package/frontend/bindings/main/GreetService.name.js new file mode 100644 index 000000000..56f3bea1c --- /dev/null +++ b/v3/internal/parser/testdata/function_from_imported_package/frontend/bindings/main/GreetService.name.js @@ -0,0 +1,27 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +/** + * @typedef {import('./models').Person} Person + */ + +/** + * Greet does XYZ + * @function Greet + * @param name {string} + * @returns {Promise} + **/ +export function Greet(name) { + return wails.CallByName("main.GreetService.Greet", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * NewPerson creates a new person + * @function NewPerson + * @param name {string} + * @returns {Promise} + **/ +export function NewPerson(name) { + return wails.CallByName("main.GreetService.NewPerson", ...Array.prototype.slice.call(arguments, 0)); +} diff --git a/v3/internal/parser/testdata/function_from_imported_package/frontend/bindings/main/models.interfaces.ts b/v3/internal/parser/testdata/function_from_imported_package/frontend/bindings/main/models.interfaces.ts new file mode 100644 index 000000000..93bfa75cc --- /dev/null +++ b/v3/internal/parser/testdata/function_from_imported_package/frontend/bindings/main/models.interfaces.ts @@ -0,0 +1,11 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +import * as services from "../services/models"; + +// Person is a person +export interface Person { + name: string; + address: services.Address; +} diff --git a/v3/internal/parser/testdata/function_from_imported_package/frontend/bindings/main/models.js b/v3/internal/parser/testdata/function_from_imported_package/frontend/bindings/main/models.js new file mode 100644 index 000000000..a09491b9a --- /dev/null +++ b/v3/internal/parser/testdata/function_from_imported_package/frontend/bindings/main/models.js @@ -0,0 +1,34 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +/** + * @typedef {import('../services/models').Address} servicesAddress + */ + +// Person is a person +export const Person = class { + /** + * Creates a new Person instance. + * @constructor + * @param {Object} source - The source object to create the Person. + * @param {string} source.Name + * @param {servicesAddress} source.Address + */ + constructor(source = {}) { + const { name = "", address = null } = source; + this.name = name; + this.address = address; + } + + /** + * Creates a new Person instance from a string or object. + * @param {string|object} source - The source data to create a Person instance from. + * @returns {Person} A new Person instance. + */ + static createFrom(source) { + let parsedSource = typeof source === 'string' ? JSON.parse(source) : source; + return new Person(parsedSource); + } +}; + diff --git a/v3/internal/parser/testdata/function_from_imported_package/frontend/bindings/main/models.ts b/v3/internal/parser/testdata/function_from_imported_package/frontend/bindings/main/models.ts new file mode 100644 index 000000000..ecd1f462a --- /dev/null +++ b/v3/internal/parser/testdata/function_from_imported_package/frontend/bindings/main/models.ts @@ -0,0 +1,22 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +import * as services from "../services/models"; + +// Person is a person +export class Person { + name: string; + address: services.Address; + + constructor(source: Partial = {}) { + const {name = "", address = null} = source; + this.name = name; + this.address = address; + } + + static createFrom(source: string | object = {}): Person { + let parsedSource = typeof source === 'string' ? JSON.parse(source) : source; + return new Person(parsedSource as Partial); + } +} diff --git a/v3/internal/parser/testdata/function_from_imported_package/frontend/bindings/services/OtherService.js b/v3/internal/parser/testdata/function_from_imported_package/frontend/bindings/services/OtherService.js new file mode 100644 index 000000000..2906a2a43 --- /dev/null +++ b/v3/internal/parser/testdata/function_from_imported_package/frontend/bindings/services/OtherService.js @@ -0,0 +1,16 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +/** + * @typedef {import('./models').Address} Address + */ + +/** + * Yay does this and that + * @function Yay + * @returns {Promise
} + **/ +export function Yay() { + return wails.CallByID(1592414782, ...Array.prototype.slice.call(arguments, 0)); +} diff --git a/v3/internal/parser/testdata/function_from_imported_package/frontend/bindings/services/OtherService.name.js b/v3/internal/parser/testdata/function_from_imported_package/frontend/bindings/services/OtherService.name.js new file mode 100644 index 000000000..43a778cd2 --- /dev/null +++ b/v3/internal/parser/testdata/function_from_imported_package/frontend/bindings/services/OtherService.name.js @@ -0,0 +1,16 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +/** + * @typedef {import('./models').Address} Address + */ + +/** + * Yay does this and that + * @function Yay + * @returns {Promise
} + **/ +export function Yay() { + return wails.CallByName("services.OtherService.Yay", ...Array.prototype.slice.call(arguments, 0)); +} diff --git a/v3/internal/parser/testdata/struct_literal_multiple_files/models.ts b/v3/internal/parser/testdata/function_from_imported_package/frontend/bindings/services/models.interfaces.ts similarity index 58% rename from v3/internal/parser/testdata/struct_literal_multiple_files/models.ts rename to v3/internal/parser/testdata/function_from_imported_package/frontend/bindings/services/models.interfaces.ts index 0817f259b..9470a4945 100644 --- a/v3/internal/parser/testdata/struct_literal_multiple_files/models.ts +++ b/v3/internal/parser/testdata/function_from_imported_package/frontend/bindings/services/models.interfaces.ts @@ -2,4 +2,9 @@ // Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL // This file is automatically generated. DO NOT EDIT -// TODO : nothing generated yet \ No newline at end of file + +export interface Address { + street: string; + state: string; + country: string; +} diff --git a/v3/internal/parser/testdata/function_from_imported_package/frontend/bindings/services/models.js b/v3/internal/parser/testdata/function_from_imported_package/frontend/bindings/services/models.js new file mode 100644 index 000000000..4c7637020 --- /dev/null +++ b/v3/internal/parser/testdata/function_from_imported_package/frontend/bindings/services/models.js @@ -0,0 +1,31 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +export const Address = class { + /** + * Creates a new Address instance. + * @constructor + * @param {Object} source - The source object to create the Address. + * @param {string} source.Street + * @param {string} source.State + * @param {string} source.Country + */ + constructor(source = {}) { + const { street = "", state = "", country = "" } = source; + this.street = street; + this.state = state; + this.country = country; + } + + /** + * Creates a new Address instance from a string or object. + * @param {string|object} source - The source data to create a Address instance from. + * @returns {Address} A new Address instance. + */ + static createFrom(source) { + let parsedSource = typeof source === 'string' ? JSON.parse(source) : source; + return new Address(parsedSource); + } +}; + diff --git a/v3/internal/parser/testdata/function_from_imported_package/frontend/bindings/services/models.ts b/v3/internal/parser/testdata/function_from_imported_package/frontend/bindings/services/models.ts new file mode 100644 index 000000000..dc2a7446f --- /dev/null +++ b/v3/internal/parser/testdata/function_from_imported_package/frontend/bindings/services/models.ts @@ -0,0 +1,22 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + + +export class Address { + street: string; + state: string; + country: string; + + constructor(source: Partial
= {}) { + const {street = "", state = "", country = ""} = source; + this.street = street; + this.state = state; + this.country = country; + } + + static createFrom(source: string | object = {}): Address { + let parsedSource = typeof source === 'string' ? JSON.parse(source) : source; + return new Address(parsedSource as Partial
); + } +} diff --git a/v3/internal/parser/testdata/function_from_imported_package/main.go b/v3/internal/parser/testdata/function_from_imported_package/main.go index 3c061aa9b..d696456b1 100644 --- a/v3/internal/parser/testdata/function_from_imported_package/main.go +++ b/v3/internal/parser/testdata/function_from_imported_package/main.go @@ -2,7 +2,7 @@ package main import ( _ "embed" - "github.com/wailsapp/wails/v3/internal/parser/testdata/variable_single_from_other_function/services" + "github.com/wailsapp/wails/v3/internal/parser/testdata/function_from_imported_package/services" "log" "github.com/wailsapp/wails/v3/pkg/application" @@ -15,6 +15,7 @@ type GreetService struct { target *Person } +// Person is a person type Person struct { Name string Address *services.Address diff --git a/v3/internal/parser/testdata/function_from_imported_package/models.js b/v3/internal/parser/testdata/function_from_imported_package/models.js deleted file mode 100644 index 94fe6bc9b..000000000 --- a/v3/internal/parser/testdata/function_from_imported_package/models.js +++ /dev/null @@ -1,63 +0,0 @@ -// @ts-check -// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL -// This file is automatically generated. DO NOT EDIT - -// Defining the main namespace -export const main = {}; - -main.Person = class { - /** - * Creates a new Person instance. - * @constructor - * @param {Object} source - The source object to create the Person. - * @param {string} source.Name - * @param {services.Address} source.Address - */ - constructor(source = {}) { - const { name = "", address = null } = source; - this.name = name; - this.address = address; - } - - /** - * Creates a new Person instance from a string or object. - * @param {string|object} source - The source data to create a Person instance from. - * @returns main.Person A new Person instance. - */ - static createFrom(source = {}) { - let parsedSource = typeof source === 'string' ? JSON.parse(source) : source; - return new main.Person(parsedSource); - } -}; - - -// Defining the services namespace -export const services = {}; - -services.Address = class { - /** - * Creates a new Address instance. - * @constructor - * @param {Object} source - The source object to create the Address. - * @param {string} source.Street - * @param {string} source.State - * @param {string} source.Country - */ - constructor(source = {}) { - const { street = "", state = "", country = "" } = source; - this.street = street; - this.state = state; - this.country = country; - } - - /** - * Creates a new Address instance from a string or object. - * @param {string|object} source - The source data to create a Address instance from. - * @returns services.Address A new Address instance. - */ - static createFrom(source = {}) { - let parsedSource = typeof source === 'string' ? JSON.parse(source) : source; - return new services.Address(parsedSource); - } -}; - diff --git a/v3/internal/parser/testdata/function_from_imported_package/models.ts b/v3/internal/parser/testdata/function_from_imported_package/models.ts deleted file mode 100644 index c44731c20..000000000 --- a/v3/internal/parser/testdata/function_from_imported_package/models.ts +++ /dev/null @@ -1,48 +0,0 @@ -// @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; - address: services.Address; - - constructor(source: Partial = {}) { - const { name = "", address = null } = source; - this.name = name; - this.address = address; - } - - static createFrom(source: string | object = {}): Person { - let parsedSource = typeof source === 'string' ? JSON.parse(source) : source; - return new Person(parsedSource as Partial); - } - - } - -} -export namespace services { - - - export class Address { - street: string; - state: string; - country: string; - - constructor(source: Partial
= {}) { - const { street = "", state = "", country = "" } = source; - this.street = street; - this.state = state; - this.country = country; - } - - static createFrom(source: string | object = {}): Address { - let parsedSource = typeof source === 'string' ? JSON.parse(source) : source; - return new Address(parsedSource as Partial
); - } - - } - -} \ No newline at end of file diff --git a/v3/internal/parser/testdata/function_from_nested_imported_package/frontend/bindings/main/GreetService.js b/v3/internal/parser/testdata/function_from_nested_imported_package/frontend/bindings/main/GreetService.js new file mode 100644 index 000000000..e654b5d6c --- /dev/null +++ b/v3/internal/parser/testdata/function_from_nested_imported_package/frontend/bindings/main/GreetService.js @@ -0,0 +1,27 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +/** + * @typedef {import('./models').Person} Person + */ + +/** + * Greet does XYZ + * @function Greet + * @param name {string} + * @returns {Promise} + **/ +export function Greet(name) { + return wails.CallByID(1411160069, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * NewPerson creates a new person + * @function NewPerson + * @param name {string} + * @returns {Promise} + **/ +export function NewPerson(name) { + return wails.CallByID(1661412647, ...Array.prototype.slice.call(arguments, 0)); +} diff --git a/v3/internal/parser/testdata/function_from_nested_imported_package/frontend/bindings/main/GreetService.name.js b/v3/internal/parser/testdata/function_from_nested_imported_package/frontend/bindings/main/GreetService.name.js new file mode 100644 index 000000000..56f3bea1c --- /dev/null +++ b/v3/internal/parser/testdata/function_from_nested_imported_package/frontend/bindings/main/GreetService.name.js @@ -0,0 +1,27 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +/** + * @typedef {import('./models').Person} Person + */ + +/** + * Greet does XYZ + * @function Greet + * @param name {string} + * @returns {Promise} + **/ +export function Greet(name) { + return wails.CallByName("main.GreetService.Greet", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * NewPerson creates a new person + * @function NewPerson + * @param name {string} + * @returns {Promise} + **/ +export function NewPerson(name) { + return wails.CallByName("main.GreetService.NewPerson", ...Array.prototype.slice.call(arguments, 0)); +} diff --git a/v3/internal/parser/testdata/function_from_nested_imported_package/frontend/bindings/main/models.ts b/v3/internal/parser/testdata/function_from_nested_imported_package/frontend/bindings/main/models.ts new file mode 100644 index 000000000..f584b37a4 --- /dev/null +++ b/v3/internal/parser/testdata/function_from_nested_imported_package/frontend/bindings/main/models.ts @@ -0,0 +1,17 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +export enum Title { + // Mister is a title + Mister = "Mr", + Miss = "Miss", + Ms = "Ms", + Mrs = "Mrs", + Dr = "Dr", +} + +export interface Person { + title: Title; + name: string; +} \ No newline at end of file diff --git a/v3/internal/parser/testdata/function_from_nested_imported_package/frontend/bindings/services/other/OtherService.js b/v3/internal/parser/testdata/function_from_nested_imported_package/frontend/bindings/services/other/OtherService.js new file mode 100644 index 000000000..7c3ec1d6d --- /dev/null +++ b/v3/internal/parser/testdata/function_from_nested_imported_package/frontend/bindings/services/other/OtherService.js @@ -0,0 +1,16 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +/** + * @typedef {import('./models').Address} Address + */ + +/** + * Yay does this and that + * @function Yay + * @returns {Promise
} + **/ +export function Yay() { + return wails.CallByID(2189323817, ...Array.prototype.slice.call(arguments, 0)); +} diff --git a/v3/internal/parser/testdata/function_from_nested_imported_package/frontend/bindings/services/other/OtherService.name.js b/v3/internal/parser/testdata/function_from_nested_imported_package/frontend/bindings/services/other/OtherService.name.js new file mode 100644 index 000000000..5f56bd686 --- /dev/null +++ b/v3/internal/parser/testdata/function_from_nested_imported_package/frontend/bindings/services/other/OtherService.name.js @@ -0,0 +1,16 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +/** + * @typedef {import('./models').Address} Address + */ + +/** + * Yay does this and that + * @function Yay + * @returns {Promise
} + **/ +export function Yay() { + return wails.CallByName("other.OtherService.Yay", ...Array.prototype.slice.call(arguments, 0)); +} diff --git a/v3/internal/parser/testdata/function_single/models.ts b/v3/internal/parser/testdata/function_from_nested_imported_package/frontend/bindings/services/other/models.ts similarity index 58% rename from v3/internal/parser/testdata/function_single/models.ts rename to v3/internal/parser/testdata/function_from_nested_imported_package/frontend/bindings/services/other/models.ts index 0817f259b..aa3f01c82 100644 --- a/v3/internal/parser/testdata/function_single/models.ts +++ b/v3/internal/parser/testdata/function_from_nested_imported_package/frontend/bindings/services/other/models.ts @@ -2,4 +2,8 @@ // Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL // This file is automatically generated. DO NOT EDIT -// TODO : nothing generated yet \ No newline at end of file +export interface Address { + Street: string; + State: string; + Country: string; +} \ No newline at end of file diff --git a/v3/internal/parser/testdata/enum-interface/main.go b/v3/internal/parser/testdata/function_from_nested_imported_package/main.go similarity index 65% rename from v3/internal/parser/testdata/enum-interface/main.go rename to v3/internal/parser/testdata/function_from_nested_imported_package/main.go index e4677ec70..105386f0f 100644 --- a/v3/internal/parser/testdata/enum-interface/main.go +++ b/v3/internal/parser/testdata/function_from_nested_imported_package/main.go @@ -2,22 +2,12 @@ package main import ( _ "embed" + "github.com/wailsapp/wails/v3/internal/parser/testdata/function_from_nested_imported_package/services/other" "log" "github.com/wailsapp/wails/v3/pkg/application" ) -type Title string - -const ( - // Mister is a title - Mister Title = "Mr" - Miss Title = "Miss" - Ms Title = "Ms" - Mrs Title = "Mrs" - Dr Title = "Dr" -) - // GreetService is great type GreetService struct { SomeVariable int @@ -26,13 +16,13 @@ type GreetService struct { } type Person struct { - Title Title - Name string + Name string + Address *other.Address } // Greet does XYZ -func (*GreetService) Greet(name string, title Title) string { - return "Hello " + string(title) + " " + name +func (*GreetService) Greet(name string) string { + return "Hello " + name } // NewPerson creates a new person @@ -44,6 +34,7 @@ func main() { app := application.New(application.Options{ Bind: []interface{}{ &GreetService{}, + other.NewOtherService(), }, }) diff --git a/v3/internal/parser/testdata/function_from_nested_imported_package/services/other/other.go b/v3/internal/parser/testdata/function_from_nested_imported_package/services/other/other.go new file mode 100644 index 000000000..f44b3548a --- /dev/null +++ b/v3/internal/parser/testdata/function_from_nested_imported_package/services/other/other.go @@ -0,0 +1,26 @@ +package other + +// OtherService is a struct +// that does things +type OtherService struct { + t int +} + +type Address struct { + Street string + State string + Country string +} + +// Yay does this and that +func (o *OtherService) Yay() *Address { + return &Address{ + Street: "123 Pitt Street", + State: "New South Wales", + Country: "Australia", + } +} + +func NewOtherService() *OtherService { + return &OtherService{} +} diff --git a/v3/internal/parser/testdata/function_single/bindings_main.js b/v3/internal/parser/testdata/function_single/bindings_main.js deleted file mode 100644 index 0707d98ff..000000000 --- a/v3/internal/parser/testdata/function_single/bindings_main.js +++ /dev/null @@ -1,15 +0,0 @@ -// @ts-check -// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL -// This file is automatically generated. DO NOT EDIT - -export const GreetService = { - - /** - * GreetService.Greet - * Greet someone - * @param name {string} - * @returns {Promise} - **/ - Greet: function(name) { return wails.CallByID(1411160069, ...Array.prototype.slice.call(arguments, 0)); }, -}; - diff --git a/v3/internal/parser/testdata/function_single/frontend/bindings/main/GreetService.js b/v3/internal/parser/testdata/function_single/frontend/bindings/main/GreetService.js new file mode 100644 index 000000000..d60dc2185 --- /dev/null +++ b/v3/internal/parser/testdata/function_single/frontend/bindings/main/GreetService.js @@ -0,0 +1,14 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + + +/** + * Greet someone + * @function Greet + * @param name {string} + * @returns {Promise} + **/ +export function Greet(name) { + return wails.CallByID(1411160069, ...Array.prototype.slice.call(arguments, 0)); +} diff --git a/v3/internal/parser/testdata/function_single/frontend/bindings/main/GreetService.name.js b/v3/internal/parser/testdata/function_single/frontend/bindings/main/GreetService.name.js new file mode 100644 index 000000000..bcb53f126 --- /dev/null +++ b/v3/internal/parser/testdata/function_single/frontend/bindings/main/GreetService.name.js @@ -0,0 +1,14 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + + +/** + * Greet someone + * @function Greet + * @param name {string} + * @returns {Promise} + **/ +export function Greet(name) { + return wails.CallByName("main.GreetService.Greet", ...Array.prototype.slice.call(arguments, 0)); +} diff --git a/v3/internal/parser/testdata/struct_literal_multiple/bindings_main.js b/v3/internal/parser/testdata/struct_literal_multiple/bindings_main.js deleted file mode 100644 index e4ed6e6ca..000000000 --- a/v3/internal/parser/testdata/struct_literal_multiple/bindings_main.js +++ /dev/null @@ -1,26 +0,0 @@ -// @ts-check -// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL -// This file is automatically generated. DO NOT EDIT - -export const GreetService = { - - /** - * GreetService.Greet - * - * @param name {string} - * @returns {Promise} - **/ - Greet: function(name) { return wails.CallByID(1411160069, ...Array.prototype.slice.call(arguments, 0)); }, -}; - -export const OtherService = { - - /** - * OtherService.Hello - * - * - * @returns {Promise} - **/ - Hello: function() { return wails.CallByID(4249972365, ...Array.prototype.slice.call(arguments, 0)); }, -}; - diff --git a/v3/internal/parser/testdata/struct_literal_multiple/frontend/bindings/main/GreetService.js b/v3/internal/parser/testdata/struct_literal_multiple/frontend/bindings/main/GreetService.js new file mode 100644 index 000000000..f74993c03 --- /dev/null +++ b/v3/internal/parser/testdata/struct_literal_multiple/frontend/bindings/main/GreetService.js @@ -0,0 +1,13 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + + +/** + * @function Greet + * @param name {string} + * @returns {Promise} + **/ +export function Greet(name) { + return wails.CallByID(1411160069, ...Array.prototype.slice.call(arguments, 0)); +} diff --git a/v3/internal/parser/testdata/struct_literal_multiple/frontend/bindings/main/GreetService.name.js b/v3/internal/parser/testdata/struct_literal_multiple/frontend/bindings/main/GreetService.name.js new file mode 100644 index 000000000..7531fd456 --- /dev/null +++ b/v3/internal/parser/testdata/struct_literal_multiple/frontend/bindings/main/GreetService.name.js @@ -0,0 +1,13 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + + +/** + * @function Greet + * @param name {string} + * @returns {Promise} + **/ +export function Greet(name) { + return wails.CallByName("main.GreetService.Greet", ...Array.prototype.slice.call(arguments, 0)); +} diff --git a/v3/internal/parser/testdata/struct_literal_multiple/frontend/bindings/main/OtherService.js b/v3/internal/parser/testdata/struct_literal_multiple/frontend/bindings/main/OtherService.js new file mode 100644 index 000000000..fbf49bdf0 --- /dev/null +++ b/v3/internal/parser/testdata/struct_literal_multiple/frontend/bindings/main/OtherService.js @@ -0,0 +1,12 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + + +/** + * @function Hello + * @returns {Promise} + **/ +export function Hello() { + return wails.CallByID(4249972365, ...Array.prototype.slice.call(arguments, 0)); +} diff --git a/v3/internal/parser/testdata/struct_literal_multiple/frontend/bindings/main/OtherService.name.js b/v3/internal/parser/testdata/struct_literal_multiple/frontend/bindings/main/OtherService.name.js new file mode 100644 index 000000000..05bcf975b --- /dev/null +++ b/v3/internal/parser/testdata/struct_literal_multiple/frontend/bindings/main/OtherService.name.js @@ -0,0 +1,12 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + + +/** + * @function Hello + * @returns {Promise} + **/ +export function Hello() { + return wails.CallByName("main.OtherService.Hello", ...Array.prototype.slice.call(arguments, 0)); +} diff --git a/v3/internal/parser/testdata/struct_literal_multiple_files/bindings_main.js b/v3/internal/parser/testdata/struct_literal_multiple_files/bindings_main.js deleted file mode 100644 index e4ed6e6ca..000000000 --- a/v3/internal/parser/testdata/struct_literal_multiple_files/bindings_main.js +++ /dev/null @@ -1,26 +0,0 @@ -// @ts-check -// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL -// This file is automatically generated. DO NOT EDIT - -export const GreetService = { - - /** - * GreetService.Greet - * - * @param name {string} - * @returns {Promise} - **/ - Greet: function(name) { return wails.CallByID(1411160069, ...Array.prototype.slice.call(arguments, 0)); }, -}; - -export const OtherService = { - - /** - * OtherService.Hello - * - * - * @returns {Promise} - **/ - Hello: function() { return wails.CallByID(4249972365, ...Array.prototype.slice.call(arguments, 0)); }, -}; - diff --git a/v3/internal/parser/testdata/struct_literal_multiple_files/frontend/bindings/main/GreetService.js b/v3/internal/parser/testdata/struct_literal_multiple_files/frontend/bindings/main/GreetService.js new file mode 100644 index 000000000..f74993c03 --- /dev/null +++ b/v3/internal/parser/testdata/struct_literal_multiple_files/frontend/bindings/main/GreetService.js @@ -0,0 +1,13 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + + +/** + * @function Greet + * @param name {string} + * @returns {Promise} + **/ +export function Greet(name) { + return wails.CallByID(1411160069, ...Array.prototype.slice.call(arguments, 0)); +} diff --git a/v3/internal/parser/testdata/struct_literal_multiple_files/frontend/bindings/main/GreetService.name.js b/v3/internal/parser/testdata/struct_literal_multiple_files/frontend/bindings/main/GreetService.name.js new file mode 100644 index 000000000..7531fd456 --- /dev/null +++ b/v3/internal/parser/testdata/struct_literal_multiple_files/frontend/bindings/main/GreetService.name.js @@ -0,0 +1,13 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + + +/** + * @function Greet + * @param name {string} + * @returns {Promise} + **/ +export function Greet(name) { + return wails.CallByName("main.GreetService.Greet", ...Array.prototype.slice.call(arguments, 0)); +} diff --git a/v3/internal/parser/testdata/struct_literal_multiple_files/frontend/bindings/main/OtherService.js b/v3/internal/parser/testdata/struct_literal_multiple_files/frontend/bindings/main/OtherService.js new file mode 100644 index 000000000..fbf49bdf0 --- /dev/null +++ b/v3/internal/parser/testdata/struct_literal_multiple_files/frontend/bindings/main/OtherService.js @@ -0,0 +1,12 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + + +/** + * @function Hello + * @returns {Promise} + **/ +export function Hello() { + return wails.CallByID(4249972365, ...Array.prototype.slice.call(arguments, 0)); +} diff --git a/v3/internal/parser/testdata/struct_literal_multiple_files/frontend/bindings/main/OtherService.name.js b/v3/internal/parser/testdata/struct_literal_multiple_files/frontend/bindings/main/OtherService.name.js new file mode 100644 index 000000000..05bcf975b --- /dev/null +++ b/v3/internal/parser/testdata/struct_literal_multiple_files/frontend/bindings/main/OtherService.name.js @@ -0,0 +1,12 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + + +/** + * @function Hello + * @returns {Promise} + **/ +export function Hello() { + return wails.CallByName("main.OtherService.Hello", ...Array.prototype.slice.call(arguments, 0)); +} diff --git a/v3/internal/parser/testdata/struct_literal_multiple_other/bindings_main.js b/v3/internal/parser/testdata/struct_literal_multiple_other/bindings_main.js deleted file mode 100644 index ae0db8c58..000000000 --- a/v3/internal/parser/testdata/struct_literal_multiple_other/bindings_main.js +++ /dev/null @@ -1,27 +0,0 @@ -// @ts-check -// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL -// This file is automatically generated. DO NOT EDIT - -/** - * @typedef {import('./models').main.Person} mainPerson - */ - -export const GreetService = { - - /** - * GreetService.Greet - * Greet does XYZ - * @param name {string} - * @returns {Promise} - **/ - Greet: function(name) { return wails.CallByID(1411160069, ...Array.prototype.slice.call(arguments, 0)); }, - - /** - * GreetService.NewPerson - * NewPerson creates a new person - * @param name {string} - * @returns {Promise} - **/ - NewPerson: function(name) { return wails.CallByID(1661412647, ...Array.prototype.slice.call(arguments, 0)); }, -}; - diff --git a/v3/internal/parser/testdata/struct_literal_multiple_other/bindings_services.js b/v3/internal/parser/testdata/struct_literal_multiple_other/bindings_services.js deleted file mode 100644 index b96474615..000000000 --- a/v3/internal/parser/testdata/struct_literal_multiple_other/bindings_services.js +++ /dev/null @@ -1,19 +0,0 @@ -// @ts-check -// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL -// This file is automatically generated. DO NOT EDIT - -/** - * @typedef {import('./models').services.Address} servicesAddress - */ - -export const OtherService = { - - /** - * OtherService.Yay - * - * - * @returns {Promise} - **/ - Yay: function() { return wails.CallByID(469445984, ...Array.prototype.slice.call(arguments, 0)); }, -}; - diff --git a/v3/internal/parser/testdata/struct_literal_multiple_other/frontend/bindings/main/GreetService.js b/v3/internal/parser/testdata/struct_literal_multiple_other/frontend/bindings/main/GreetService.js new file mode 100644 index 000000000..e654b5d6c --- /dev/null +++ b/v3/internal/parser/testdata/struct_literal_multiple_other/frontend/bindings/main/GreetService.js @@ -0,0 +1,27 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +/** + * @typedef {import('./models').Person} Person + */ + +/** + * Greet does XYZ + * @function Greet + * @param name {string} + * @returns {Promise} + **/ +export function Greet(name) { + return wails.CallByID(1411160069, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * NewPerson creates a new person + * @function NewPerson + * @param name {string} + * @returns {Promise} + **/ +export function NewPerson(name) { + return wails.CallByID(1661412647, ...Array.prototype.slice.call(arguments, 0)); +} diff --git a/v3/internal/parser/testdata/struct_literal_multiple_other/frontend/bindings/main/GreetService.name.js b/v3/internal/parser/testdata/struct_literal_multiple_other/frontend/bindings/main/GreetService.name.js new file mode 100644 index 000000000..56f3bea1c --- /dev/null +++ b/v3/internal/parser/testdata/struct_literal_multiple_other/frontend/bindings/main/GreetService.name.js @@ -0,0 +1,27 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +/** + * @typedef {import('./models').Person} Person + */ + +/** + * Greet does XYZ + * @function Greet + * @param name {string} + * @returns {Promise} + **/ +export function Greet(name) { + return wails.CallByName("main.GreetService.Greet", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * NewPerson creates a new person + * @function NewPerson + * @param name {string} + * @returns {Promise} + **/ +export function NewPerson(name) { + return wails.CallByName("main.GreetService.NewPerson", ...Array.prototype.slice.call(arguments, 0)); +} diff --git a/v3/internal/parser/testdata/struct_literal_multiple_other/frontend/bindings/main/models.interfaces.ts b/v3/internal/parser/testdata/struct_literal_multiple_other/frontend/bindings/main/models.interfaces.ts new file mode 100644 index 000000000..ec779d0cf --- /dev/null +++ b/v3/internal/parser/testdata/struct_literal_multiple_other/frontend/bindings/main/models.interfaces.ts @@ -0,0 +1,10 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +import * as services from "../services/models"; + +export interface Person { + name: string; + address: services.Address; +} diff --git a/v3/internal/parser/testdata/struct_literal_multiple_other/frontend/bindings/main/models.js b/v3/internal/parser/testdata/struct_literal_multiple_other/frontend/bindings/main/models.js new file mode 100644 index 000000000..e9e9503c1 --- /dev/null +++ b/v3/internal/parser/testdata/struct_literal_multiple_other/frontend/bindings/main/models.js @@ -0,0 +1,33 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +/** + * @typedef {import('../services/models').Address} servicesAddress + */ + +export const Person = class { + /** + * Creates a new Person instance. + * @constructor + * @param {Object} source - The source object to create the Person. + * @param {string} source.Name + * @param {servicesAddress} source.Address + */ + constructor(source = {}) { + const { name = "", address = null } = source; + this.name = name; + this.address = address; + } + + /** + * Creates a new Person instance from a string or object. + * @param {string|object} source - The source data to create a Person instance from. + * @returns {Person} A new Person instance. + */ + static createFrom(source) { + let parsedSource = typeof source === 'string' ? JSON.parse(source) : source; + return new Person(parsedSource); + } +}; + diff --git a/v3/internal/parser/testdata/struct_literal_multiple_other/frontend/bindings/main/models.ts b/v3/internal/parser/testdata/struct_literal_multiple_other/frontend/bindings/main/models.ts new file mode 100644 index 000000000..7f8d7b489 --- /dev/null +++ b/v3/internal/parser/testdata/struct_literal_multiple_other/frontend/bindings/main/models.ts @@ -0,0 +1,21 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +import * as services from "../services/models"; + +export class Person { + name: string; + address: services.Address; + + constructor(source: Partial = {}) { + const {name = "", address = null} = source; + this.name = name; + this.address = address; + } + + static createFrom(source: string | object = {}): Person { + let parsedSource = typeof source === 'string' ? JSON.parse(source) : source; + return new Person(parsedSource as Partial); + } +} diff --git a/v3/internal/parser/testdata/struct_literal_multiple_other/frontend/bindings/services/OtherService.js b/v3/internal/parser/testdata/struct_literal_multiple_other/frontend/bindings/services/OtherService.js new file mode 100644 index 000000000..ffdac47f0 --- /dev/null +++ b/v3/internal/parser/testdata/struct_literal_multiple_other/frontend/bindings/services/OtherService.js @@ -0,0 +1,16 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +/** + * @typedef {import('./models').Address} Address + */ + +/** + * Yay does this and that + * @function Yay + * @returns {Promise
} + **/ +export function Yay() { + return wails.CallByID(469445984, ...Array.prototype.slice.call(arguments, 0)); +} diff --git a/v3/internal/parser/testdata/struct_literal_multiple_other/frontend/bindings/services/OtherService.name.js b/v3/internal/parser/testdata/struct_literal_multiple_other/frontend/bindings/services/OtherService.name.js new file mode 100644 index 000000000..43a778cd2 --- /dev/null +++ b/v3/internal/parser/testdata/struct_literal_multiple_other/frontend/bindings/services/OtherService.name.js @@ -0,0 +1,16 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +/** + * @typedef {import('./models').Address} Address + */ + +/** + * Yay does this and that + * @function Yay + * @returns {Promise
} + **/ +export function Yay() { + return wails.CallByName("services.OtherService.Yay", ...Array.prototype.slice.call(arguments, 0)); +} diff --git a/v3/internal/parser/testdata/variable_single/models.ts b/v3/internal/parser/testdata/struct_literal_multiple_other/frontend/bindings/services/models.interfaces.ts similarity index 58% rename from v3/internal/parser/testdata/variable_single/models.ts rename to v3/internal/parser/testdata/struct_literal_multiple_other/frontend/bindings/services/models.interfaces.ts index 0817f259b..9470a4945 100644 --- a/v3/internal/parser/testdata/variable_single/models.ts +++ b/v3/internal/parser/testdata/struct_literal_multiple_other/frontend/bindings/services/models.interfaces.ts @@ -2,4 +2,9 @@ // Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL // This file is automatically generated. DO NOT EDIT -// TODO : nothing generated yet \ No newline at end of file + +export interface Address { + street: string; + state: string; + country: string; +} diff --git a/v3/internal/parser/testdata/struct_literal_multiple_other/frontend/bindings/services/models.js b/v3/internal/parser/testdata/struct_literal_multiple_other/frontend/bindings/services/models.js new file mode 100644 index 000000000..4c7637020 --- /dev/null +++ b/v3/internal/parser/testdata/struct_literal_multiple_other/frontend/bindings/services/models.js @@ -0,0 +1,31 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +export const Address = class { + /** + * Creates a new Address instance. + * @constructor + * @param {Object} source - The source object to create the Address. + * @param {string} source.Street + * @param {string} source.State + * @param {string} source.Country + */ + constructor(source = {}) { + const { street = "", state = "", country = "" } = source; + this.street = street; + this.state = state; + this.country = country; + } + + /** + * Creates a new Address instance from a string or object. + * @param {string|object} source - The source data to create a Address instance from. + * @returns {Address} A new Address instance. + */ + static createFrom(source) { + let parsedSource = typeof source === 'string' ? JSON.parse(source) : source; + return new Address(parsedSource); + } +}; + diff --git a/v3/internal/parser/testdata/struct_literal_multiple_other/frontend/bindings/services/models.ts b/v3/internal/parser/testdata/struct_literal_multiple_other/frontend/bindings/services/models.ts new file mode 100644 index 000000000..dc2a7446f --- /dev/null +++ b/v3/internal/parser/testdata/struct_literal_multiple_other/frontend/bindings/services/models.ts @@ -0,0 +1,22 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + + +export class Address { + street: string; + state: string; + country: string; + + constructor(source: Partial
= {}) { + const {street = "", state = "", country = ""} = source; + this.street = street; + this.state = state; + this.country = country; + } + + static createFrom(source: string | object = {}): Address { + let parsedSource = typeof source === 'string' ? JSON.parse(source) : source; + return new Address(parsedSource as Partial
); + } +} diff --git a/v3/internal/parser/testdata/struct_literal_multiple_other/models.js b/v3/internal/parser/testdata/struct_literal_multiple_other/models.js deleted file mode 100644 index 94fe6bc9b..000000000 --- a/v3/internal/parser/testdata/struct_literal_multiple_other/models.js +++ /dev/null @@ -1,63 +0,0 @@ -// @ts-check -// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL -// This file is automatically generated. DO NOT EDIT - -// Defining the main namespace -export const main = {}; - -main.Person = class { - /** - * Creates a new Person instance. - * @constructor - * @param {Object} source - The source object to create the Person. - * @param {string} source.Name - * @param {services.Address} source.Address - */ - constructor(source = {}) { - const { name = "", address = null } = source; - this.name = name; - this.address = address; - } - - /** - * Creates a new Person instance from a string or object. - * @param {string|object} source - The source data to create a Person instance from. - * @returns main.Person A new Person instance. - */ - static createFrom(source = {}) { - let parsedSource = typeof source === 'string' ? JSON.parse(source) : source; - return new main.Person(parsedSource); - } -}; - - -// Defining the services namespace -export const services = {}; - -services.Address = class { - /** - * Creates a new Address instance. - * @constructor - * @param {Object} source - The source object to create the Address. - * @param {string} source.Street - * @param {string} source.State - * @param {string} source.Country - */ - constructor(source = {}) { - const { street = "", state = "", country = "" } = source; - this.street = street; - this.state = state; - this.country = country; - } - - /** - * Creates a new Address instance from a string or object. - * @param {string|object} source - The source data to create a Address instance from. - * @returns services.Address A new Address instance. - */ - static createFrom(source = {}) { - let parsedSource = typeof source === 'string' ? JSON.parse(source) : source; - return new services.Address(parsedSource); - } -}; - diff --git a/v3/internal/parser/testdata/struct_literal_multiple_other/models.ts b/v3/internal/parser/testdata/struct_literal_multiple_other/models.ts deleted file mode 100644 index c44731c20..000000000 --- a/v3/internal/parser/testdata/struct_literal_multiple_other/models.ts +++ /dev/null @@ -1,48 +0,0 @@ -// @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; - address: services.Address; - - constructor(source: Partial = {}) { - const { name = "", address = null } = source; - this.name = name; - this.address = address; - } - - static createFrom(source: string | object = {}): Person { - let parsedSource = typeof source === 'string' ? JSON.parse(source) : source; - return new Person(parsedSource as Partial); - } - - } - -} -export namespace services { - - - export class Address { - street: string; - state: string; - country: string; - - constructor(source: Partial
= {}) { - const { street = "", state = "", country = "" } = source; - this.street = street; - this.state = state; - this.country = country; - } - - static createFrom(source: string | object = {}): Address { - let parsedSource = typeof source === 'string' ? JSON.parse(source) : source; - return new Address(parsedSource as Partial
); - } - - } - -} \ No newline at end of file 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 deleted file mode 100644 index 893b066bc..000000000 --- a/v3/internal/parser/testdata/struct_literal_non_pointer_single/bindings_main.js +++ /dev/null @@ -1,356 +0,0 @@ -// @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/frontend/bindings/main/GreetService.js b/v3/internal/parser/testdata/struct_literal_non_pointer_single/frontend/bindings/main/GreetService.js new file mode 100644 index 000000000..41faca336 --- /dev/null +++ b/v3/internal/parser/testdata/struct_literal_non_pointer_single/frontend/bindings/main/GreetService.js @@ -0,0 +1,394 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +/** + * @typedef {import('./models').Person} Person + */ + +/** + * @function ArrayInt + * @param _in {number[]} + * @returns {Promise} + **/ +export function ArrayInt(_in) { + return wails.CallByID(3862002418, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function BoolInBoolOut + * @param _in {boolean} + * @returns {Promise} + **/ +export function BoolInBoolOut(_in) { + return wails.CallByID(2424639793, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function Float32InFloat32Out + * @param _in {number} + * @returns {Promise} + **/ +export function Float32InFloat32Out(_in) { + return wails.CallByID(3132595881, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function Float64InFloat64Out + * @param _in {number} + * @returns {Promise} + **/ +export function Float64InFloat64Out(_in) { + return wails.CallByID(2182412247, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * Greet someone + * @function Greet + * @param name {string} + * @returns {Promise} + **/ +export function Greet(name) { + return wails.CallByID(1411160069, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function Int16InIntOut + * @param _in {number} + * @returns {Promise} + **/ +export function Int16InIntOut(_in) { + return wails.CallByID(3306292566, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function Int16PointerInAndOutput + * @param _in {number | null} + * @returns {Promise} + **/ +export function Int16PointerInAndOutput(_in) { + return wails.CallByID(1754277916, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function Int32InIntOut + * @param _in {number} + * @returns {Promise} + **/ +export function Int32InIntOut(_in) { + return wails.CallByID(1909469092, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function Int32PointerInAndOutput + * @param _in {number | null} + * @returns {Promise} + **/ +export function Int32PointerInAndOutput(_in) { + return wails.CallByID(4251088558, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function Int64InIntOut + * @param _in {number} + * @returns {Promise} + **/ +export function Int64InIntOut(_in) { + return wails.CallByID(1343888303, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function Int64PointerInAndOutput + * @param _in {number | null} + * @returns {Promise} + **/ +export function Int64PointerInAndOutput(_in) { + return wails.CallByID(2205561041, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function Int8InIntOut + * @param _in {number} + * @returns {Promise} + **/ +export function Int8InIntOut(_in) { + return wails.CallByID(572240879, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function Int8PointerInAndOutput + * @param _in {number | null} + * @returns {Promise} + **/ +export function Int8PointerInAndOutput(_in) { + return wails.CallByID(2189402897, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function IntInIntOut + * @param _in {number} + * @returns {Promise} + **/ +export function IntInIntOut(_in) { + return wails.CallByID(642881729, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function IntPointerInAndOutput + * @param _in {number | null} + * @returns {Promise} + **/ +export function IntPointerInAndOutput(_in) { + return wails.CallByID(1066151743, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function IntPointerInputNamedOutputs + * @param _in {number | null} + * @returns {Promise} + **/ +export function IntPointerInputNamedOutputs(_in) { + return wails.CallByID(2718999663, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function MapIntInt + * @param _in {map} + * @returns {Promise} + **/ +export function MapIntInt(_in) { + return wails.CallByID(2386486356, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function MapIntPointerInt + * @param _in {map} + * @returns {Promise} + **/ +export function MapIntPointerInt(_in) { + return wails.CallByID(550413585, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function MapIntSliceInt + * @param _in {map} + * @returns {Promise} + **/ +export function MapIntSliceInt(_in) { + return wails.CallByID(2900172572, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function MapIntSliceIntInMapIntSliceIntOut + * @param _in {map} + * @returns {Promise} + **/ +export function MapIntSliceIntInMapIntSliceIntOut(_in) { + return wails.CallByID(881980169, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function NoInputsStringOut + * @returns {Promise} + **/ +export function NoInputsStringOut() { + return wails.CallByID(1075577233, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function PointerBoolInBoolOut + * @param _in {boolean | null} + * @returns {Promise} + **/ +export function PointerBoolInBoolOut(_in) { + return wails.CallByID(3589606958, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function PointerFloat32InFloat32Out + * @param _in {number | null} + * @returns {Promise} + **/ +export function PointerFloat32InFloat32Out(_in) { + return wails.CallByID(224675106, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function PointerFloat64InFloat64Out + * @param _in {number | null} + * @returns {Promise} + **/ +export function PointerFloat64InFloat64Out(_in) { + return wails.CallByID(2124953624, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function PointerMapIntInt + * @param _in {map | null} + * @returns {Promise} + **/ +export function PointerMapIntInt(_in) { + return wails.CallByID(3516977899, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function PointerStringInStringOut + * @param _in {string | null} + * @returns {Promise} + **/ +export function PointerStringInStringOut(_in) { + return wails.CallByID(229603958, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function StringArrayInputNamedOutput + * @param _in {string[]} + * @returns {Promise} + **/ +export function StringArrayInputNamedOutput(_in) { + return wails.CallByID(3678582682, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function StringArrayInputNamedOutputs + * @param _in {string[]} + * @returns {Promise} + **/ +export function StringArrayInputNamedOutputs(_in) { + return wails.CallByID(319259595, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function StringArrayInputStringArrayOut + * @param _in {string[]} + * @returns {Promise} + **/ +export function StringArrayInputStringArrayOut(_in) { + return wails.CallByID(383995060, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function StringArrayInputStringOut + * @param _in {string[]} + * @returns {Promise} + **/ +export function StringArrayInputStringOut(_in) { + return wails.CallByID(1091960237, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function StructInputStructOutput + * @param _in {Person} + * @returns {Promise} + **/ +export function StructInputStructOutput(_in) { + return wails.CallByID(3835643147, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function StructPointerInputErrorOutput + * @param _in {Person | null} + * @returns {Promise} + **/ +export function StructPointerInputErrorOutput(_in) { + return wails.CallByID(2447692557, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function StructPointerInputStructPointerOutput + * @param _in {Person | null} + * @returns {Promise} + **/ +export function StructPointerInputStructPointerOutput(_in) { + return wails.CallByID(2943477349, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function UInt16InUIntOut + * @param _in {number} + * @returns {Promise} + **/ +export function UInt16InUIntOut(_in) { + return wails.CallByID(3401034892, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function UInt16PointerInAndOutput + * @param _in {number | null} + * @returns {Promise} + **/ +export function UInt16PointerInAndOutput(_in) { + return wails.CallByID(1236957573, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function UInt32InUIntOut + * @param _in {number} + * @returns {Promise} + **/ +export function UInt32InUIntOut(_in) { + return wails.CallByID(1160383782, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function UInt32PointerInAndOutput + * @param _in {number | null} + * @returns {Promise} + **/ +export function UInt32PointerInAndOutput(_in) { + return wails.CallByID(1739300671, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function UInt64InUIntOut + * @param _in {number} + * @returns {Promise} + **/ +export function UInt64InUIntOut(_in) { + return wails.CallByID(793803239, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function UInt64PointerInAndOutput + * @param _in {number | null} + * @returns {Promise} + **/ +export function UInt64PointerInAndOutput(_in) { + return wails.CallByID(1403757716, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function UInt8InUIntOut + * @param _in {number} + * @returns {Promise} + **/ +export function UInt8InUIntOut(_in) { + return wails.CallByID(2988345717, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function UInt8PointerInAndOutput + * @param _in {number | null} + * @returns {Promise} + **/ +export function UInt8PointerInAndOutput(_in) { + return wails.CallByID(518250834, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function UIntInUIntOut + * @param _in {number} + * @returns {Promise} + **/ +export function UIntInUIntOut(_in) { + return wails.CallByID(2836661285, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function UIntPointerInAndOutput + * @param _in {number | null} + * @returns {Promise} + **/ +export function UIntPointerInAndOutput(_in) { + return wails.CallByID(1367187362, ...Array.prototype.slice.call(arguments, 0)); +} diff --git a/v3/internal/parser/testdata/struct_literal_non_pointer_single/frontend/bindings/main/GreetService.name.js b/v3/internal/parser/testdata/struct_literal_non_pointer_single/frontend/bindings/main/GreetService.name.js new file mode 100644 index 000000000..a40109ed4 --- /dev/null +++ b/v3/internal/parser/testdata/struct_literal_non_pointer_single/frontend/bindings/main/GreetService.name.js @@ -0,0 +1,394 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +/** + * @typedef {import('./models').Person} Person + */ + +/** + * @function ArrayInt + * @param _in {number[]} + * @returns {Promise} + **/ +export function ArrayInt(_in) { + return wails.CallByName("main.GreetService.ArrayInt", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function BoolInBoolOut + * @param _in {boolean} + * @returns {Promise} + **/ +export function BoolInBoolOut(_in) { + return wails.CallByName("main.GreetService.BoolInBoolOut", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function Float32InFloat32Out + * @param _in {number} + * @returns {Promise} + **/ +export function Float32InFloat32Out(_in) { + return wails.CallByName("main.GreetService.Float32InFloat32Out", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function Float64InFloat64Out + * @param _in {number} + * @returns {Promise} + **/ +export function Float64InFloat64Out(_in) { + return wails.CallByName("main.GreetService.Float64InFloat64Out", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * Greet someone + * @function Greet + * @param name {string} + * @returns {Promise} + **/ +export function Greet(name) { + return wails.CallByName("main.GreetService.Greet", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function Int16InIntOut + * @param _in {number} + * @returns {Promise} + **/ +export function Int16InIntOut(_in) { + return wails.CallByName("main.GreetService.Int16InIntOut", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function Int16PointerInAndOutput + * @param _in {number | null} + * @returns {Promise} + **/ +export function Int16PointerInAndOutput(_in) { + return wails.CallByName("main.GreetService.Int16PointerInAndOutput", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function Int32InIntOut + * @param _in {number} + * @returns {Promise} + **/ +export function Int32InIntOut(_in) { + return wails.CallByName("main.GreetService.Int32InIntOut", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function Int32PointerInAndOutput + * @param _in {number | null} + * @returns {Promise} + **/ +export function Int32PointerInAndOutput(_in) { + return wails.CallByName("main.GreetService.Int32PointerInAndOutput", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function Int64InIntOut + * @param _in {number} + * @returns {Promise} + **/ +export function Int64InIntOut(_in) { + return wails.CallByName("main.GreetService.Int64InIntOut", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function Int64PointerInAndOutput + * @param _in {number | null} + * @returns {Promise} + **/ +export function Int64PointerInAndOutput(_in) { + return wails.CallByName("main.GreetService.Int64PointerInAndOutput", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function Int8InIntOut + * @param _in {number} + * @returns {Promise} + **/ +export function Int8InIntOut(_in) { + return wails.CallByName("main.GreetService.Int8InIntOut", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function Int8PointerInAndOutput + * @param _in {number | null} + * @returns {Promise} + **/ +export function Int8PointerInAndOutput(_in) { + return wails.CallByName("main.GreetService.Int8PointerInAndOutput", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function IntInIntOut + * @param _in {number} + * @returns {Promise} + **/ +export function IntInIntOut(_in) { + return wails.CallByName("main.GreetService.IntInIntOut", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function IntPointerInAndOutput + * @param _in {number | null} + * @returns {Promise} + **/ +export function IntPointerInAndOutput(_in) { + return wails.CallByName("main.GreetService.IntPointerInAndOutput", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function IntPointerInputNamedOutputs + * @param _in {number | null} + * @returns {Promise} + **/ +export function IntPointerInputNamedOutputs(_in) { + return wails.CallByName("main.GreetService.IntPointerInputNamedOutputs", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function MapIntInt + * @param _in {map} + * @returns {Promise} + **/ +export function MapIntInt(_in) { + return wails.CallByName("main.GreetService.MapIntInt", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function MapIntPointerInt + * @param _in {map} + * @returns {Promise} + **/ +export function MapIntPointerInt(_in) { + return wails.CallByName("main.GreetService.MapIntPointerInt", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function MapIntSliceInt + * @param _in {map} + * @returns {Promise} + **/ +export function MapIntSliceInt(_in) { + return wails.CallByName("main.GreetService.MapIntSliceInt", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function MapIntSliceIntInMapIntSliceIntOut + * @param _in {map} + * @returns {Promise} + **/ +export function MapIntSliceIntInMapIntSliceIntOut(_in) { + return wails.CallByName("main.GreetService.MapIntSliceIntInMapIntSliceIntOut", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function NoInputsStringOut + * @returns {Promise} + **/ +export function NoInputsStringOut() { + return wails.CallByName("main.GreetService.NoInputsStringOut", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function PointerBoolInBoolOut + * @param _in {boolean | null} + * @returns {Promise} + **/ +export function PointerBoolInBoolOut(_in) { + return wails.CallByName("main.GreetService.PointerBoolInBoolOut", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function PointerFloat32InFloat32Out + * @param _in {number | null} + * @returns {Promise} + **/ +export function PointerFloat32InFloat32Out(_in) { + return wails.CallByName("main.GreetService.PointerFloat32InFloat32Out", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function PointerFloat64InFloat64Out + * @param _in {number | null} + * @returns {Promise} + **/ +export function PointerFloat64InFloat64Out(_in) { + return wails.CallByName("main.GreetService.PointerFloat64InFloat64Out", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function PointerMapIntInt + * @param _in {map | null} + * @returns {Promise} + **/ +export function PointerMapIntInt(_in) { + return wails.CallByName("main.GreetService.PointerMapIntInt", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function PointerStringInStringOut + * @param _in {string | null} + * @returns {Promise} + **/ +export function PointerStringInStringOut(_in) { + return wails.CallByName("main.GreetService.PointerStringInStringOut", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function StringArrayInputNamedOutput + * @param _in {string[]} + * @returns {Promise} + **/ +export function StringArrayInputNamedOutput(_in) { + return wails.CallByName("main.GreetService.StringArrayInputNamedOutput", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function StringArrayInputNamedOutputs + * @param _in {string[]} + * @returns {Promise} + **/ +export function StringArrayInputNamedOutputs(_in) { + return wails.CallByName("main.GreetService.StringArrayInputNamedOutputs", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function StringArrayInputStringArrayOut + * @param _in {string[]} + * @returns {Promise} + **/ +export function StringArrayInputStringArrayOut(_in) { + return wails.CallByName("main.GreetService.StringArrayInputStringArrayOut", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function StringArrayInputStringOut + * @param _in {string[]} + * @returns {Promise} + **/ +export function StringArrayInputStringOut(_in) { + return wails.CallByName("main.GreetService.StringArrayInputStringOut", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function StructInputStructOutput + * @param _in {Person} + * @returns {Promise} + **/ +export function StructInputStructOutput(_in) { + return wails.CallByName("main.GreetService.StructInputStructOutput", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function StructPointerInputErrorOutput + * @param _in {Person | null} + * @returns {Promise} + **/ +export function StructPointerInputErrorOutput(_in) { + return wails.CallByName("main.GreetService.StructPointerInputErrorOutput", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function StructPointerInputStructPointerOutput + * @param _in {Person | null} + * @returns {Promise} + **/ +export function StructPointerInputStructPointerOutput(_in) { + return wails.CallByName("main.GreetService.StructPointerInputStructPointerOutput", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function UInt16InUIntOut + * @param _in {number} + * @returns {Promise} + **/ +export function UInt16InUIntOut(_in) { + return wails.CallByName("main.GreetService.UInt16InUIntOut", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function UInt16PointerInAndOutput + * @param _in {number | null} + * @returns {Promise} + **/ +export function UInt16PointerInAndOutput(_in) { + return wails.CallByName("main.GreetService.UInt16PointerInAndOutput", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function UInt32InUIntOut + * @param _in {number} + * @returns {Promise} + **/ +export function UInt32InUIntOut(_in) { + return wails.CallByName("main.GreetService.UInt32InUIntOut", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function UInt32PointerInAndOutput + * @param _in {number | null} + * @returns {Promise} + **/ +export function UInt32PointerInAndOutput(_in) { + return wails.CallByName("main.GreetService.UInt32PointerInAndOutput", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function UInt64InUIntOut + * @param _in {number} + * @returns {Promise} + **/ +export function UInt64InUIntOut(_in) { + return wails.CallByName("main.GreetService.UInt64InUIntOut", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function UInt64PointerInAndOutput + * @param _in {number | null} + * @returns {Promise} + **/ +export function UInt64PointerInAndOutput(_in) { + return wails.CallByName("main.GreetService.UInt64PointerInAndOutput", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function UInt8InUIntOut + * @param _in {number} + * @returns {Promise} + **/ +export function UInt8InUIntOut(_in) { + return wails.CallByName("main.GreetService.UInt8InUIntOut", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function UInt8PointerInAndOutput + * @param _in {number | null} + * @returns {Promise} + **/ +export function UInt8PointerInAndOutput(_in) { + return wails.CallByName("main.GreetService.UInt8PointerInAndOutput", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function UIntInUIntOut + * @param _in {number} + * @returns {Promise} + **/ +export function UIntInUIntOut(_in) { + return wails.CallByName("main.GreetService.UIntInUIntOut", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function UIntPointerInAndOutput + * @param _in {number | null} + * @returns {Promise} + **/ +export function UIntPointerInAndOutput(_in) { + return wails.CallByName("main.GreetService.UIntPointerInAndOutput", ...Array.prototype.slice.call(arguments, 0)); +} diff --git a/v3/internal/parser/testdata/struct_literal_non_pointer_single/frontend/bindings/main/models.interfaces.ts b/v3/internal/parser/testdata/struct_literal_non_pointer_single/frontend/bindings/main/models.interfaces.ts new file mode 100644 index 000000000..7074f18c9 --- /dev/null +++ b/v3/internal/parser/testdata/struct_literal_non_pointer_single/frontend/bindings/main/models.interfaces.ts @@ -0,0 +1,19 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + + +export interface Person { + name: string; + parent: Person; + details: anon1; +} + +export interface anon1 { + age: number; + address: anon2; +} + +export interface anon2 { + street: string; +} diff --git a/v3/internal/parser/testdata/struct_literal_non_pointer_single/models.js b/v3/internal/parser/testdata/struct_literal_non_pointer_single/frontend/bindings/main/models.js similarity index 74% rename from v3/internal/parser/testdata/struct_literal_non_pointer_single/models.js rename to v3/internal/parser/testdata/struct_literal_non_pointer_single/frontend/bindings/main/models.js index 2b6af5068..59f0b9356 100644 --- a/v3/internal/parser/testdata/struct_literal_non_pointer_single/models.js +++ b/v3/internal/parser/testdata/struct_literal_non_pointer_single/frontend/bindings/main/models.js @@ -2,17 +2,14 @@ // Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL // This file is automatically generated. DO NOT EDIT -// Defining the main namespace -export const main = {}; - -main.Person = class { +export const Person = class { /** * Creates a new Person instance. * @constructor * @param {Object} source - The source object to create the Person. * @param {string} source.Name - * @param {main.Person} source.Parent - * @param {main.anon1} source.Details + * @param {Person} source.Parent + * @param {anon1} source.Details */ constructor(source = {}) { const { name = "", parent = null, details = null } = source; @@ -24,20 +21,21 @@ main.Person = class { /** * Creates a new Person instance from a string or object. * @param {string|object} source - The source data to create a Person instance from. - * @returns main.Person A new Person instance. + * @returns {Person} A new Person instance. */ - static createFrom(source = {}) { + static createFrom(source) { let parsedSource = typeof source === 'string' ? JSON.parse(source) : source; - return new main.Person(parsedSource); + return new Person(parsedSource); } }; -main.anon1 = class { + +export const anon1 = class { /** * Creates a new anon1 instance. * @constructor * @param {Object} source - The source object to create the anon1. * @param {number} source.Age - * @param {main.anon2} source.Address + * @param {anon2} source.Address */ constructor(source = {}) { const { age = 0, address = null } = source; @@ -48,14 +46,15 @@ main.anon1 = class { /** * Creates a new anon1 instance from a string or object. * @param {string|object} source - The source data to create a anon1 instance from. - * @returns main.anon1 A new anon1 instance. + * @returns {anon1} A new anon1 instance. */ - static createFrom(source = {}) { + static createFrom(source) { let parsedSource = typeof source === 'string' ? JSON.parse(source) : source; - return new main.anon1(parsedSource); + return new anon1(parsedSource); } }; -main.anon2 = class { + +export const anon2 = class { /** * Creates a new anon2 instance. * @constructor @@ -70,11 +69,11 @@ main.anon2 = class { /** * Creates a new anon2 instance from a string or object. * @param {string|object} source - The source data to create a anon2 instance from. - * @returns main.anon2 A new anon2 instance. + * @returns {anon2} A new anon2 instance. */ - static createFrom(source = {}) { + static createFrom(source) { let parsedSource = typeof source === 'string' ? JSON.parse(source) : source; - return new main.anon2(parsedSource); + return new anon2(parsedSource); } }; diff --git a/v3/internal/parser/testdata/struct_literal_non_pointer_single/frontend/bindings/main/models.ts b/v3/internal/parser/testdata/struct_literal_non_pointer_single/frontend/bindings/main/models.ts new file mode 100644 index 000000000..83431809b --- /dev/null +++ b/v3/internal/parser/testdata/struct_literal_non_pointer_single/frontend/bindings/main/models.ts @@ -0,0 +1,52 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + + +export class Person { + name: string; + parent: Person; + details: anon1; + + constructor(source: Partial = {}) { + const {name = "", parent = null, details = null} = source; + this.name = name; + this.parent = parent; + this.details = details; + } + + static createFrom(source: string | object = {}): Person { + let parsedSource = typeof source === 'string' ? JSON.parse(source) : source; + return new Person(parsedSource as Partial); + } +} + +export class anon1 { + age: number; + address: anon2; + + constructor(source: Partial = {}) { + const {age = 0, address = null} = source; + this.age = age; + this.address = address; + } + + static createFrom(source: string | object = {}): anon1 { + let parsedSource = typeof source === 'string' ? JSON.parse(source) : source; + return new anon1(parsedSource as Partial); + } +} + +export class anon2 { + street: string; + + constructor(source: Partial = {}) { + const {street = ""} = source; + this.street = street; + } + + static createFrom(source: string | object = {}): anon2 { + let parsedSource = typeof source === 'string' ? JSON.parse(source) : source; + return new anon2(parsedSource as Partial); + } +} 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 deleted file mode 100644 index 1244c2330..000000000 --- a/v3/internal/parser/testdata/struct_literal_non_pointer_single/models.ts +++ /dev/null @@ -1,59 +0,0 @@ -// @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; - - constructor(source: Partial = {}) { - const { name = "", parent = null, details = null } = source; - this.name = name; - this.parent = parent; - this.details = details; - } - - static createFrom(source: string | object = {}): Person { - let parsedSource = typeof source === 'string' ? JSON.parse(source) : source; - return new Person(parsedSource as Partial); - } - - } - - export class anon1 { - age: number; - address: anon2; - - constructor(source: Partial = {}) { - const { age = 0, address = null } = source; - this.age = age; - this.address = address; - } - - static createFrom(source: string | object = {}): anon1 { - let parsedSource = typeof source === 'string' ? JSON.parse(source) : source; - return new anon1(parsedSource as Partial); - } - - } - - export class anon2 { - street: string; - - constructor(source: Partial = {}) { - const { street = "" } = source; - this.street = street; - } - - static createFrom(source: string | object = {}): anon2 { - let parsedSource = typeof source === 'string' ? JSON.parse(source) : source; - return new anon2(parsedSource as Partial); - } - - } - -} \ No newline at end of file diff --git a/v3/internal/parser/testdata/struct_literal_single/bindings_main.js b/v3/internal/parser/testdata/struct_literal_single/bindings_main.js deleted file mode 100644 index 0cdc9fbef..000000000 --- a/v3/internal/parser/testdata/struct_literal_single/bindings_main.js +++ /dev/null @@ -1,355 +0,0 @@ -// @ts-check -// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL -// This file is automatically generated. DO NOT EDIT - -/** - * @typedef {import('./models').main.Person} mainPerson - */ - -export const GreetService = { - - /** - * GreetService.ArrayInt - * - * @param _in {number[]} - * @returns {Promise} - **/ - ArrayInt: function(_in) { return wails.CallByID(3862002418, ...Array.prototype.slice.call(arguments, 0)); }, - - /** - * GreetService.BoolInBoolOut - * - * @param _in {boolean} - * @returns {Promise} - **/ - BoolInBoolOut: function(_in) { return wails.CallByID(2424639793, ...Array.prototype.slice.call(arguments, 0)); }, - - /** - * GreetService.Float32InFloat32Out - * - * @param _in {number} - * @returns {Promise} - **/ - Float32InFloat32Out: function(_in) { return wails.CallByID(3132595881, ...Array.prototype.slice.call(arguments, 0)); }, - - /** - * GreetService.Float64InFloat64Out - * - * @param _in {number} - * @returns {Promise} - **/ - Float64InFloat64Out: function(_in) { return wails.CallByID(2182412247, ...Array.prototype.slice.call(arguments, 0)); }, - - /** - * GreetService.Greet - * Greet someone - * @param name {string} - * @returns {Promise} - **/ - Greet: function(name) { return wails.CallByID(1411160069, ...Array.prototype.slice.call(arguments, 0)); }, - - /** - * GreetService.Int16InIntOut - * - * @param _in {number} - * @returns {Promise} - **/ - Int16InIntOut: function(_in) { return wails.CallByID(3306292566, ...Array.prototype.slice.call(arguments, 0)); }, - - /** - * GreetService.Int16PointerInAndOutput - * - * @param _in {number | null} - * @returns {Promise} - **/ - Int16PointerInAndOutput: function(_in) { return wails.CallByID(1754277916, ...Array.prototype.slice.call(arguments, 0)); }, - - /** - * GreetService.Int32InIntOut - * - * @param _in {number} - * @returns {Promise} - **/ - Int32InIntOut: function(_in) { return wails.CallByID(1909469092, ...Array.prototype.slice.call(arguments, 0)); }, - - /** - * GreetService.Int32PointerInAndOutput - * - * @param _in {number | null} - * @returns {Promise} - **/ - Int32PointerInAndOutput: function(_in) { return wails.CallByID(4251088558, ...Array.prototype.slice.call(arguments, 0)); }, - - /** - * GreetService.Int64InIntOut - * - * @param _in {number} - * @returns {Promise} - **/ - Int64InIntOut: function(_in) { return wails.CallByID(1343888303, ...Array.prototype.slice.call(arguments, 0)); }, - - /** - * GreetService.Int64PointerInAndOutput - * - * @param _in {number | null} - * @returns {Promise} - **/ - Int64PointerInAndOutput: function(_in) { return wails.CallByID(2205561041, ...Array.prototype.slice.call(arguments, 0)); }, - - /** - * GreetService.Int8InIntOut - * - * @param _in {number} - * @returns {Promise} - **/ - Int8InIntOut: function(_in) { return wails.CallByID(572240879, ...Array.prototype.slice.call(arguments, 0)); }, - - /** - * GreetService.Int8PointerInAndOutput - * - * @param _in {number | null} - * @returns {Promise} - **/ - Int8PointerInAndOutput: function(_in) { return wails.CallByID(2189402897, ...Array.prototype.slice.call(arguments, 0)); }, - - /** - * GreetService.IntInIntOut - * - * @param _in {number} - * @returns {Promise} - **/ - IntInIntOut: function(_in) { return wails.CallByID(642881729, ...Array.prototype.slice.call(arguments, 0)); }, - - /** - * GreetService.IntPointerInAndOutput - * - * @param _in {number | null} - * @returns {Promise} - **/ - IntPointerInAndOutput: function(_in) { return wails.CallByID(1066151743, ...Array.prototype.slice.call(arguments, 0)); }, - - /** - * GreetService.IntPointerInputNamedOutputs - * - * @param _in {number | null} - * @returns {Promise} - **/ - IntPointerInputNamedOutputs: function(_in) { return wails.CallByID(2718999663, ...Array.prototype.slice.call(arguments, 0)); }, - - /** - * GreetService.MapIntInt - * - * @param _in {map} - * @returns {Promise} - **/ - MapIntInt: function(_in) { return wails.CallByID(2386486356, ...Array.prototype.slice.call(arguments, 0)); }, - - /** - * GreetService.MapIntPointerInt - * - * @param _in {map} - * @returns {Promise} - **/ - MapIntPointerInt: function(_in) { return wails.CallByID(550413585, ...Array.prototype.slice.call(arguments, 0)); }, - - /** - * GreetService.MapIntSliceInt - * - * @param _in {map} - * @returns {Promise} - **/ - MapIntSliceInt: function(_in) { return wails.CallByID(2900172572, ...Array.prototype.slice.call(arguments, 0)); }, - - /** - * GreetService.MapIntSliceIntInMapIntSliceIntOut - * - * @param _in {map} - * @returns {Promise} - **/ - MapIntSliceIntInMapIntSliceIntOut: function(_in) { return wails.CallByID(881980169, ...Array.prototype.slice.call(arguments, 0)); }, - - /** - * GreetService.NoInputsStringOut - * - * - * @returns {Promise} - **/ - NoInputsStringOut: function() { return wails.CallByID(1075577233, ...Array.prototype.slice.call(arguments, 0)); }, - - /** - * GreetService.PointerBoolInBoolOut - * - * @param _in {boolean | null} - * @returns {Promise} - **/ - PointerBoolInBoolOut: function(_in) { return wails.CallByID(3589606958, ...Array.prototype.slice.call(arguments, 0)); }, - - /** - * GreetService.PointerFloat32InFloat32Out - * - * @param _in {number | null} - * @returns {Promise} - **/ - PointerFloat32InFloat32Out: function(_in) { return wails.CallByID(224675106, ...Array.prototype.slice.call(arguments, 0)); }, - - /** - * GreetService.PointerFloat64InFloat64Out - * - * @param _in {number | null} - * @returns {Promise} - **/ - PointerFloat64InFloat64Out: function(_in) { return wails.CallByID(2124953624, ...Array.prototype.slice.call(arguments, 0)); }, - - /** - * GreetService.PointerMapIntInt - * - * @param _in {map | null} - * @returns {Promise} - **/ - PointerMapIntInt: function(_in) { return wails.CallByID(3516977899, ...Array.prototype.slice.call(arguments, 0)); }, - - /** - * GreetService.PointerStringInStringOut - * - * @param _in {string | null} - * @returns {Promise} - **/ - PointerStringInStringOut: function(_in) { return wails.CallByID(229603958, ...Array.prototype.slice.call(arguments, 0)); }, - - /** - * GreetService.StringArrayInputNamedOutput - * - * @param _in {string[]} - * @returns {Promise} - **/ - StringArrayInputNamedOutput: function(_in) { return wails.CallByID(3678582682, ...Array.prototype.slice.call(arguments, 0)); }, - - /** - * GreetService.StringArrayInputNamedOutputs - * - * @param _in {string[]} - * @returns {Promise} - **/ - StringArrayInputNamedOutputs: function(_in) { return wails.CallByID(319259595, ...Array.prototype.slice.call(arguments, 0)); }, - - /** - * GreetService.StringArrayInputStringArrayOut - * - * @param _in {string[]} - * @returns {Promise} - **/ - StringArrayInputStringArrayOut: function(_in) { return wails.CallByID(383995060, ...Array.prototype.slice.call(arguments, 0)); }, - - /** - * GreetService.StringArrayInputStringOut - * - * @param _in {string[]} - * @returns {Promise} - **/ - StringArrayInputStringOut: function(_in) { return wails.CallByID(1091960237, ...Array.prototype.slice.call(arguments, 0)); }, - - /** - * GreetService.StructInputStructOutput - * - * @param _in {mainPerson} - * @returns {Promise} - **/ - StructInputStructOutput: function(_in) { return wails.CallByID(3835643147, ...Array.prototype.slice.call(arguments, 0)); }, - - /** - * GreetService.StructPointerInputErrorOutput - * - * @param _in {mainPerson | null} - * @returns {Promise} - **/ - StructPointerInputErrorOutput: function(_in) { return wails.CallByID(2447692557, ...Array.prototype.slice.call(arguments, 0)); }, - - /** - * GreetService.StructPointerInputStructPointerOutput - * - * @param _in {mainPerson | null} - * @returns {Promise} - **/ - StructPointerInputStructPointerOutput: function(_in) { return wails.CallByID(2943477349, ...Array.prototype.slice.call(arguments, 0)); }, - - /** - * GreetService.UInt16InUIntOut - * - * @param _in {number} - * @returns {Promise} - **/ - UInt16InUIntOut: function(_in) { return wails.CallByID(3401034892, ...Array.prototype.slice.call(arguments, 0)); }, - - /** - * GreetService.UInt16PointerInAndOutput - * - * @param _in {number | null} - * @returns {Promise} - **/ - UInt16PointerInAndOutput: function(_in) { return wails.CallByID(1236957573, ...Array.prototype.slice.call(arguments, 0)); }, - - /** - * GreetService.UInt32InUIntOut - * - * @param _in {number} - * @returns {Promise} - **/ - UInt32InUIntOut: function(_in) { return wails.CallByID(1160383782, ...Array.prototype.slice.call(arguments, 0)); }, - - /** - * GreetService.UInt32PointerInAndOutput - * - * @param _in {number | null} - * @returns {Promise} - **/ - UInt32PointerInAndOutput: function(_in) { return wails.CallByID(1739300671, ...Array.prototype.slice.call(arguments, 0)); }, - - /** - * GreetService.UInt64InUIntOut - * - * @param _in {number} - * @returns {Promise} - **/ - UInt64InUIntOut: function(_in) { return wails.CallByID(793803239, ...Array.prototype.slice.call(arguments, 0)); }, - - /** - * GreetService.UInt64PointerInAndOutput - * - * @param _in {number | null} - * @returns {Promise} - **/ - UInt64PointerInAndOutput: function(_in) { return wails.CallByID(1403757716, ...Array.prototype.slice.call(arguments, 0)); }, - - /** - * GreetService.UInt8InUIntOut - * - * @param _in {number} - * @returns {Promise} - **/ - UInt8InUIntOut: function(_in) { return wails.CallByID(2988345717, ...Array.prototype.slice.call(arguments, 0)); }, - - /** - * GreetService.UInt8PointerInAndOutput - * - * @param _in {number | null} - * @returns {Promise} - **/ - UInt8PointerInAndOutput: function(_in) { return wails.CallByID(518250834, ...Array.prototype.slice.call(arguments, 0)); }, - - /** - * GreetService.UIntInUIntOut - * - * @param _in {number} - * @returns {Promise} - **/ - UIntInUIntOut: function(_in) { return wails.CallByID(2836661285, ...Array.prototype.slice.call(arguments, 0)); }, - - /** - * GreetService.UIntPointerInAndOutput - * - * @param _in {number | null} - * @returns {Promise} - **/ - UIntPointerInAndOutput: function(_in) { return wails.CallByID(1367187362, ...Array.prototype.slice.call(arguments, 0)); }, -}; - diff --git a/v3/internal/parser/testdata/struct_literal_single/frontend/bindings/main/GreetService.js b/v3/internal/parser/testdata/struct_literal_single/frontend/bindings/main/GreetService.js new file mode 100644 index 000000000..41faca336 --- /dev/null +++ b/v3/internal/parser/testdata/struct_literal_single/frontend/bindings/main/GreetService.js @@ -0,0 +1,394 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +/** + * @typedef {import('./models').Person} Person + */ + +/** + * @function ArrayInt + * @param _in {number[]} + * @returns {Promise} + **/ +export function ArrayInt(_in) { + return wails.CallByID(3862002418, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function BoolInBoolOut + * @param _in {boolean} + * @returns {Promise} + **/ +export function BoolInBoolOut(_in) { + return wails.CallByID(2424639793, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function Float32InFloat32Out + * @param _in {number} + * @returns {Promise} + **/ +export function Float32InFloat32Out(_in) { + return wails.CallByID(3132595881, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function Float64InFloat64Out + * @param _in {number} + * @returns {Promise} + **/ +export function Float64InFloat64Out(_in) { + return wails.CallByID(2182412247, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * Greet someone + * @function Greet + * @param name {string} + * @returns {Promise} + **/ +export function Greet(name) { + return wails.CallByID(1411160069, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function Int16InIntOut + * @param _in {number} + * @returns {Promise} + **/ +export function Int16InIntOut(_in) { + return wails.CallByID(3306292566, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function Int16PointerInAndOutput + * @param _in {number | null} + * @returns {Promise} + **/ +export function Int16PointerInAndOutput(_in) { + return wails.CallByID(1754277916, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function Int32InIntOut + * @param _in {number} + * @returns {Promise} + **/ +export function Int32InIntOut(_in) { + return wails.CallByID(1909469092, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function Int32PointerInAndOutput + * @param _in {number | null} + * @returns {Promise} + **/ +export function Int32PointerInAndOutput(_in) { + return wails.CallByID(4251088558, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function Int64InIntOut + * @param _in {number} + * @returns {Promise} + **/ +export function Int64InIntOut(_in) { + return wails.CallByID(1343888303, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function Int64PointerInAndOutput + * @param _in {number | null} + * @returns {Promise} + **/ +export function Int64PointerInAndOutput(_in) { + return wails.CallByID(2205561041, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function Int8InIntOut + * @param _in {number} + * @returns {Promise} + **/ +export function Int8InIntOut(_in) { + return wails.CallByID(572240879, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function Int8PointerInAndOutput + * @param _in {number | null} + * @returns {Promise} + **/ +export function Int8PointerInAndOutput(_in) { + return wails.CallByID(2189402897, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function IntInIntOut + * @param _in {number} + * @returns {Promise} + **/ +export function IntInIntOut(_in) { + return wails.CallByID(642881729, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function IntPointerInAndOutput + * @param _in {number | null} + * @returns {Promise} + **/ +export function IntPointerInAndOutput(_in) { + return wails.CallByID(1066151743, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function IntPointerInputNamedOutputs + * @param _in {number | null} + * @returns {Promise} + **/ +export function IntPointerInputNamedOutputs(_in) { + return wails.CallByID(2718999663, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function MapIntInt + * @param _in {map} + * @returns {Promise} + **/ +export function MapIntInt(_in) { + return wails.CallByID(2386486356, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function MapIntPointerInt + * @param _in {map} + * @returns {Promise} + **/ +export function MapIntPointerInt(_in) { + return wails.CallByID(550413585, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function MapIntSliceInt + * @param _in {map} + * @returns {Promise} + **/ +export function MapIntSliceInt(_in) { + return wails.CallByID(2900172572, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function MapIntSliceIntInMapIntSliceIntOut + * @param _in {map} + * @returns {Promise} + **/ +export function MapIntSliceIntInMapIntSliceIntOut(_in) { + return wails.CallByID(881980169, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function NoInputsStringOut + * @returns {Promise} + **/ +export function NoInputsStringOut() { + return wails.CallByID(1075577233, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function PointerBoolInBoolOut + * @param _in {boolean | null} + * @returns {Promise} + **/ +export function PointerBoolInBoolOut(_in) { + return wails.CallByID(3589606958, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function PointerFloat32InFloat32Out + * @param _in {number | null} + * @returns {Promise} + **/ +export function PointerFloat32InFloat32Out(_in) { + return wails.CallByID(224675106, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function PointerFloat64InFloat64Out + * @param _in {number | null} + * @returns {Promise} + **/ +export function PointerFloat64InFloat64Out(_in) { + return wails.CallByID(2124953624, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function PointerMapIntInt + * @param _in {map | null} + * @returns {Promise} + **/ +export function PointerMapIntInt(_in) { + return wails.CallByID(3516977899, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function PointerStringInStringOut + * @param _in {string | null} + * @returns {Promise} + **/ +export function PointerStringInStringOut(_in) { + return wails.CallByID(229603958, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function StringArrayInputNamedOutput + * @param _in {string[]} + * @returns {Promise} + **/ +export function StringArrayInputNamedOutput(_in) { + return wails.CallByID(3678582682, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function StringArrayInputNamedOutputs + * @param _in {string[]} + * @returns {Promise} + **/ +export function StringArrayInputNamedOutputs(_in) { + return wails.CallByID(319259595, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function StringArrayInputStringArrayOut + * @param _in {string[]} + * @returns {Promise} + **/ +export function StringArrayInputStringArrayOut(_in) { + return wails.CallByID(383995060, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function StringArrayInputStringOut + * @param _in {string[]} + * @returns {Promise} + **/ +export function StringArrayInputStringOut(_in) { + return wails.CallByID(1091960237, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function StructInputStructOutput + * @param _in {Person} + * @returns {Promise} + **/ +export function StructInputStructOutput(_in) { + return wails.CallByID(3835643147, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function StructPointerInputErrorOutput + * @param _in {Person | null} + * @returns {Promise} + **/ +export function StructPointerInputErrorOutput(_in) { + return wails.CallByID(2447692557, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function StructPointerInputStructPointerOutput + * @param _in {Person | null} + * @returns {Promise} + **/ +export function StructPointerInputStructPointerOutput(_in) { + return wails.CallByID(2943477349, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function UInt16InUIntOut + * @param _in {number} + * @returns {Promise} + **/ +export function UInt16InUIntOut(_in) { + return wails.CallByID(3401034892, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function UInt16PointerInAndOutput + * @param _in {number | null} + * @returns {Promise} + **/ +export function UInt16PointerInAndOutput(_in) { + return wails.CallByID(1236957573, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function UInt32InUIntOut + * @param _in {number} + * @returns {Promise} + **/ +export function UInt32InUIntOut(_in) { + return wails.CallByID(1160383782, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function UInt32PointerInAndOutput + * @param _in {number | null} + * @returns {Promise} + **/ +export function UInt32PointerInAndOutput(_in) { + return wails.CallByID(1739300671, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function UInt64InUIntOut + * @param _in {number} + * @returns {Promise} + **/ +export function UInt64InUIntOut(_in) { + return wails.CallByID(793803239, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function UInt64PointerInAndOutput + * @param _in {number | null} + * @returns {Promise} + **/ +export function UInt64PointerInAndOutput(_in) { + return wails.CallByID(1403757716, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function UInt8InUIntOut + * @param _in {number} + * @returns {Promise} + **/ +export function UInt8InUIntOut(_in) { + return wails.CallByID(2988345717, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function UInt8PointerInAndOutput + * @param _in {number | null} + * @returns {Promise} + **/ +export function UInt8PointerInAndOutput(_in) { + return wails.CallByID(518250834, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function UIntInUIntOut + * @param _in {number} + * @returns {Promise} + **/ +export function UIntInUIntOut(_in) { + return wails.CallByID(2836661285, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function UIntPointerInAndOutput + * @param _in {number | null} + * @returns {Promise} + **/ +export function UIntPointerInAndOutput(_in) { + return wails.CallByID(1367187362, ...Array.prototype.slice.call(arguments, 0)); +} diff --git a/v3/internal/parser/testdata/struct_literal_single/frontend/bindings/main/GreetService.name.js b/v3/internal/parser/testdata/struct_literal_single/frontend/bindings/main/GreetService.name.js new file mode 100644 index 000000000..a40109ed4 --- /dev/null +++ b/v3/internal/parser/testdata/struct_literal_single/frontend/bindings/main/GreetService.name.js @@ -0,0 +1,394 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +/** + * @typedef {import('./models').Person} Person + */ + +/** + * @function ArrayInt + * @param _in {number[]} + * @returns {Promise} + **/ +export function ArrayInt(_in) { + return wails.CallByName("main.GreetService.ArrayInt", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function BoolInBoolOut + * @param _in {boolean} + * @returns {Promise} + **/ +export function BoolInBoolOut(_in) { + return wails.CallByName("main.GreetService.BoolInBoolOut", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function Float32InFloat32Out + * @param _in {number} + * @returns {Promise} + **/ +export function Float32InFloat32Out(_in) { + return wails.CallByName("main.GreetService.Float32InFloat32Out", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function Float64InFloat64Out + * @param _in {number} + * @returns {Promise} + **/ +export function Float64InFloat64Out(_in) { + return wails.CallByName("main.GreetService.Float64InFloat64Out", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * Greet someone + * @function Greet + * @param name {string} + * @returns {Promise} + **/ +export function Greet(name) { + return wails.CallByName("main.GreetService.Greet", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function Int16InIntOut + * @param _in {number} + * @returns {Promise} + **/ +export function Int16InIntOut(_in) { + return wails.CallByName("main.GreetService.Int16InIntOut", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function Int16PointerInAndOutput + * @param _in {number | null} + * @returns {Promise} + **/ +export function Int16PointerInAndOutput(_in) { + return wails.CallByName("main.GreetService.Int16PointerInAndOutput", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function Int32InIntOut + * @param _in {number} + * @returns {Promise} + **/ +export function Int32InIntOut(_in) { + return wails.CallByName("main.GreetService.Int32InIntOut", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function Int32PointerInAndOutput + * @param _in {number | null} + * @returns {Promise} + **/ +export function Int32PointerInAndOutput(_in) { + return wails.CallByName("main.GreetService.Int32PointerInAndOutput", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function Int64InIntOut + * @param _in {number} + * @returns {Promise} + **/ +export function Int64InIntOut(_in) { + return wails.CallByName("main.GreetService.Int64InIntOut", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function Int64PointerInAndOutput + * @param _in {number | null} + * @returns {Promise} + **/ +export function Int64PointerInAndOutput(_in) { + return wails.CallByName("main.GreetService.Int64PointerInAndOutput", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function Int8InIntOut + * @param _in {number} + * @returns {Promise} + **/ +export function Int8InIntOut(_in) { + return wails.CallByName("main.GreetService.Int8InIntOut", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function Int8PointerInAndOutput + * @param _in {number | null} + * @returns {Promise} + **/ +export function Int8PointerInAndOutput(_in) { + return wails.CallByName("main.GreetService.Int8PointerInAndOutput", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function IntInIntOut + * @param _in {number} + * @returns {Promise} + **/ +export function IntInIntOut(_in) { + return wails.CallByName("main.GreetService.IntInIntOut", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function IntPointerInAndOutput + * @param _in {number | null} + * @returns {Promise} + **/ +export function IntPointerInAndOutput(_in) { + return wails.CallByName("main.GreetService.IntPointerInAndOutput", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function IntPointerInputNamedOutputs + * @param _in {number | null} + * @returns {Promise} + **/ +export function IntPointerInputNamedOutputs(_in) { + return wails.CallByName("main.GreetService.IntPointerInputNamedOutputs", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function MapIntInt + * @param _in {map} + * @returns {Promise} + **/ +export function MapIntInt(_in) { + return wails.CallByName("main.GreetService.MapIntInt", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function MapIntPointerInt + * @param _in {map} + * @returns {Promise} + **/ +export function MapIntPointerInt(_in) { + return wails.CallByName("main.GreetService.MapIntPointerInt", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function MapIntSliceInt + * @param _in {map} + * @returns {Promise} + **/ +export function MapIntSliceInt(_in) { + return wails.CallByName("main.GreetService.MapIntSliceInt", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function MapIntSliceIntInMapIntSliceIntOut + * @param _in {map} + * @returns {Promise} + **/ +export function MapIntSliceIntInMapIntSliceIntOut(_in) { + return wails.CallByName("main.GreetService.MapIntSliceIntInMapIntSliceIntOut", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function NoInputsStringOut + * @returns {Promise} + **/ +export function NoInputsStringOut() { + return wails.CallByName("main.GreetService.NoInputsStringOut", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function PointerBoolInBoolOut + * @param _in {boolean | null} + * @returns {Promise} + **/ +export function PointerBoolInBoolOut(_in) { + return wails.CallByName("main.GreetService.PointerBoolInBoolOut", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function PointerFloat32InFloat32Out + * @param _in {number | null} + * @returns {Promise} + **/ +export function PointerFloat32InFloat32Out(_in) { + return wails.CallByName("main.GreetService.PointerFloat32InFloat32Out", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function PointerFloat64InFloat64Out + * @param _in {number | null} + * @returns {Promise} + **/ +export function PointerFloat64InFloat64Out(_in) { + return wails.CallByName("main.GreetService.PointerFloat64InFloat64Out", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function PointerMapIntInt + * @param _in {map | null} + * @returns {Promise} + **/ +export function PointerMapIntInt(_in) { + return wails.CallByName("main.GreetService.PointerMapIntInt", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function PointerStringInStringOut + * @param _in {string | null} + * @returns {Promise} + **/ +export function PointerStringInStringOut(_in) { + return wails.CallByName("main.GreetService.PointerStringInStringOut", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function StringArrayInputNamedOutput + * @param _in {string[]} + * @returns {Promise} + **/ +export function StringArrayInputNamedOutput(_in) { + return wails.CallByName("main.GreetService.StringArrayInputNamedOutput", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function StringArrayInputNamedOutputs + * @param _in {string[]} + * @returns {Promise} + **/ +export function StringArrayInputNamedOutputs(_in) { + return wails.CallByName("main.GreetService.StringArrayInputNamedOutputs", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function StringArrayInputStringArrayOut + * @param _in {string[]} + * @returns {Promise} + **/ +export function StringArrayInputStringArrayOut(_in) { + return wails.CallByName("main.GreetService.StringArrayInputStringArrayOut", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function StringArrayInputStringOut + * @param _in {string[]} + * @returns {Promise} + **/ +export function StringArrayInputStringOut(_in) { + return wails.CallByName("main.GreetService.StringArrayInputStringOut", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function StructInputStructOutput + * @param _in {Person} + * @returns {Promise} + **/ +export function StructInputStructOutput(_in) { + return wails.CallByName("main.GreetService.StructInputStructOutput", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function StructPointerInputErrorOutput + * @param _in {Person | null} + * @returns {Promise} + **/ +export function StructPointerInputErrorOutput(_in) { + return wails.CallByName("main.GreetService.StructPointerInputErrorOutput", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function StructPointerInputStructPointerOutput + * @param _in {Person | null} + * @returns {Promise} + **/ +export function StructPointerInputStructPointerOutput(_in) { + return wails.CallByName("main.GreetService.StructPointerInputStructPointerOutput", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function UInt16InUIntOut + * @param _in {number} + * @returns {Promise} + **/ +export function UInt16InUIntOut(_in) { + return wails.CallByName("main.GreetService.UInt16InUIntOut", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function UInt16PointerInAndOutput + * @param _in {number | null} + * @returns {Promise} + **/ +export function UInt16PointerInAndOutput(_in) { + return wails.CallByName("main.GreetService.UInt16PointerInAndOutput", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function UInt32InUIntOut + * @param _in {number} + * @returns {Promise} + **/ +export function UInt32InUIntOut(_in) { + return wails.CallByName("main.GreetService.UInt32InUIntOut", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function UInt32PointerInAndOutput + * @param _in {number | null} + * @returns {Promise} + **/ +export function UInt32PointerInAndOutput(_in) { + return wails.CallByName("main.GreetService.UInt32PointerInAndOutput", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function UInt64InUIntOut + * @param _in {number} + * @returns {Promise} + **/ +export function UInt64InUIntOut(_in) { + return wails.CallByName("main.GreetService.UInt64InUIntOut", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function UInt64PointerInAndOutput + * @param _in {number | null} + * @returns {Promise} + **/ +export function UInt64PointerInAndOutput(_in) { + return wails.CallByName("main.GreetService.UInt64PointerInAndOutput", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function UInt8InUIntOut + * @param _in {number} + * @returns {Promise} + **/ +export function UInt8InUIntOut(_in) { + return wails.CallByName("main.GreetService.UInt8InUIntOut", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function UInt8PointerInAndOutput + * @param _in {number | null} + * @returns {Promise} + **/ +export function UInt8PointerInAndOutput(_in) { + return wails.CallByName("main.GreetService.UInt8PointerInAndOutput", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function UIntInUIntOut + * @param _in {number} + * @returns {Promise} + **/ +export function UIntInUIntOut(_in) { + return wails.CallByName("main.GreetService.UIntInUIntOut", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * @function UIntPointerInAndOutput + * @param _in {number | null} + * @returns {Promise} + **/ +export function UIntPointerInAndOutput(_in) { + return wails.CallByName("main.GreetService.UIntPointerInAndOutput", ...Array.prototype.slice.call(arguments, 0)); +} diff --git a/v3/internal/parser/testdata/struct_literal_single/frontend/bindings/main/models.interfaces.ts b/v3/internal/parser/testdata/struct_literal_single/frontend/bindings/main/models.interfaces.ts new file mode 100644 index 000000000..7074f18c9 --- /dev/null +++ b/v3/internal/parser/testdata/struct_literal_single/frontend/bindings/main/models.interfaces.ts @@ -0,0 +1,19 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + + +export interface Person { + name: string; + parent: Person; + details: anon1; +} + +export interface anon1 { + age: number; + address: anon2; +} + +export interface anon2 { + street: string; +} diff --git a/v3/internal/parser/testdata/struct_literal_single/frontend/bindings/main/models.js b/v3/internal/parser/testdata/struct_literal_single/frontend/bindings/main/models.js new file mode 100644 index 000000000..59f0b9356 --- /dev/null +++ b/v3/internal/parser/testdata/struct_literal_single/frontend/bindings/main/models.js @@ -0,0 +1,79 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +export const Person = class { + /** + * Creates a new Person instance. + * @constructor + * @param {Object} source - The source object to create the Person. + * @param {string} source.Name + * @param {Person} source.Parent + * @param {anon1} source.Details + */ + constructor(source = {}) { + const { name = "", parent = null, details = null } = source; + this.name = name; + this.parent = parent; + this.details = details; + } + + /** + * Creates a new Person instance from a string or object. + * @param {string|object} source - The source data to create a Person instance from. + * @returns {Person} A new Person instance. + */ + static createFrom(source) { + let parsedSource = typeof source === 'string' ? JSON.parse(source) : source; + return new Person(parsedSource); + } +}; + +export const anon1 = class { + /** + * Creates a new anon1 instance. + * @constructor + * @param {Object} source - The source object to create the anon1. + * @param {number} source.Age + * @param {anon2} source.Address + */ + constructor(source = {}) { + const { age = 0, address = null } = source; + this.age = age; + this.address = address; + } + + /** + * Creates a new anon1 instance from a string or object. + * @param {string|object} source - The source data to create a anon1 instance from. + * @returns {anon1} A new anon1 instance. + */ + static createFrom(source) { + let parsedSource = typeof source === 'string' ? JSON.parse(source) : source; + return new anon1(parsedSource); + } +}; + +export const anon2 = class { + /** + * Creates a new anon2 instance. + * @constructor + * @param {Object} source - The source object to create the anon2. + * @param {string} source.Street + */ + constructor(source = {}) { + const { street = "" } = source; + this.street = street; + } + + /** + * Creates a new anon2 instance from a string or object. + * @param {string|object} source - The source data to create a anon2 instance from. + * @returns {anon2} A new anon2 instance. + */ + static createFrom(source) { + let parsedSource = typeof source === 'string' ? JSON.parse(source) : source; + return new anon2(parsedSource); + } +}; + diff --git a/v3/internal/parser/testdata/struct_literal_single/frontend/bindings/main/models.ts b/v3/internal/parser/testdata/struct_literal_single/frontend/bindings/main/models.ts new file mode 100644 index 000000000..83431809b --- /dev/null +++ b/v3/internal/parser/testdata/struct_literal_single/frontend/bindings/main/models.ts @@ -0,0 +1,52 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + + +export class Person { + name: string; + parent: Person; + details: anon1; + + constructor(source: Partial = {}) { + const {name = "", parent = null, details = null} = source; + this.name = name; + this.parent = parent; + this.details = details; + } + + static createFrom(source: string | object = {}): Person { + let parsedSource = typeof source === 'string' ? JSON.parse(source) : source; + return new Person(parsedSource as Partial); + } +} + +export class anon1 { + age: number; + address: anon2; + + constructor(source: Partial = {}) { + const {age = 0, address = null} = source; + this.age = age; + this.address = address; + } + + static createFrom(source: string | object = {}): anon1 { + let parsedSource = typeof source === 'string' ? JSON.parse(source) : source; + return new anon1(parsedSource as Partial); + } +} + +export class anon2 { + street: string; + + constructor(source: Partial = {}) { + const {street = ""} = source; + this.street = street; + } + + static createFrom(source: string | object = {}): anon2 { + let parsedSource = typeof source === 'string' ? JSON.parse(source) : source; + return new anon2(parsedSource as Partial); + } +} diff --git a/v3/internal/parser/testdata/struct_literal_single/models.ts b/v3/internal/parser/testdata/struct_literal_single/models.ts deleted file mode 100644 index 1244c2330..000000000 --- a/v3/internal/parser/testdata/struct_literal_single/models.ts +++ /dev/null @@ -1,59 +0,0 @@ -// @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; - - constructor(source: Partial = {}) { - const { name = "", parent = null, details = null } = source; - this.name = name; - this.parent = parent; - this.details = details; - } - - static createFrom(source: string | object = {}): Person { - let parsedSource = typeof source === 'string' ? JSON.parse(source) : source; - return new Person(parsedSource as Partial); - } - - } - - export class anon1 { - age: number; - address: anon2; - - constructor(source: Partial = {}) { - const { age = 0, address = null } = source; - this.age = age; - this.address = address; - } - - static createFrom(source: string | object = {}): anon1 { - let parsedSource = typeof source === 'string' ? JSON.parse(source) : source; - return new anon1(parsedSource as Partial); - } - - } - - export class anon2 { - street: string; - - constructor(source: Partial = {}) { - const { street = "" } = source; - this.street = street; - } - - static createFrom(source: string | object = {}): anon2 { - let parsedSource = typeof source === 'string' ? JSON.parse(source) : source; - return new anon2(parsedSource as Partial); - } - - } - -} \ No newline at end of file diff --git a/v3/internal/parser/testdata/variable_single/bindings_main.js b/v3/internal/parser/testdata/variable_single/bindings_main.js deleted file mode 100644 index 0707d98ff..000000000 --- a/v3/internal/parser/testdata/variable_single/bindings_main.js +++ /dev/null @@ -1,15 +0,0 @@ -// @ts-check -// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL -// This file is automatically generated. DO NOT EDIT - -export const GreetService = { - - /** - * GreetService.Greet - * Greet someone - * @param name {string} - * @returns {Promise} - **/ - Greet: function(name) { return wails.CallByID(1411160069, ...Array.prototype.slice.call(arguments, 0)); }, -}; - diff --git a/v3/internal/parser/testdata/variable_single/frontend/bindings/main/GreetService.js b/v3/internal/parser/testdata/variable_single/frontend/bindings/main/GreetService.js new file mode 100644 index 000000000..d60dc2185 --- /dev/null +++ b/v3/internal/parser/testdata/variable_single/frontend/bindings/main/GreetService.js @@ -0,0 +1,14 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + + +/** + * Greet someone + * @function Greet + * @param name {string} + * @returns {Promise} + **/ +export function Greet(name) { + return wails.CallByID(1411160069, ...Array.prototype.slice.call(arguments, 0)); +} diff --git a/v3/internal/parser/testdata/variable_single/frontend/bindings/main/GreetService.name.js b/v3/internal/parser/testdata/variable_single/frontend/bindings/main/GreetService.name.js new file mode 100644 index 000000000..bcb53f126 --- /dev/null +++ b/v3/internal/parser/testdata/variable_single/frontend/bindings/main/GreetService.name.js @@ -0,0 +1,14 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + + +/** + * Greet someone + * @function Greet + * @param name {string} + * @returns {Promise} + **/ +export function Greet(name) { + return wails.CallByName("main.GreetService.Greet", ...Array.prototype.slice.call(arguments, 0)); +} diff --git a/v3/internal/parser/testdata/variable_single_from_function/bindings_main.js b/v3/internal/parser/testdata/variable_single_from_function/bindings_main.js deleted file mode 100644 index 0707d98ff..000000000 --- a/v3/internal/parser/testdata/variable_single_from_function/bindings_main.js +++ /dev/null @@ -1,15 +0,0 @@ -// @ts-check -// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL -// This file is automatically generated. DO NOT EDIT - -export const GreetService = { - - /** - * GreetService.Greet - * Greet someone - * @param name {string} - * @returns {Promise} - **/ - Greet: function(name) { return wails.CallByID(1411160069, ...Array.prototype.slice.call(arguments, 0)); }, -}; - diff --git a/v3/internal/parser/testdata/variable_single_from_function/frontend/bindings/main/GreetService.js b/v3/internal/parser/testdata/variable_single_from_function/frontend/bindings/main/GreetService.js new file mode 100644 index 000000000..d60dc2185 --- /dev/null +++ b/v3/internal/parser/testdata/variable_single_from_function/frontend/bindings/main/GreetService.js @@ -0,0 +1,14 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + + +/** + * Greet someone + * @function Greet + * @param name {string} + * @returns {Promise} + **/ +export function Greet(name) { + return wails.CallByID(1411160069, ...Array.prototype.slice.call(arguments, 0)); +} diff --git a/v3/internal/parser/testdata/variable_single_from_function/frontend/bindings/main/GreetService.name.js b/v3/internal/parser/testdata/variable_single_from_function/frontend/bindings/main/GreetService.name.js new file mode 100644 index 000000000..bcb53f126 --- /dev/null +++ b/v3/internal/parser/testdata/variable_single_from_function/frontend/bindings/main/GreetService.name.js @@ -0,0 +1,14 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + + +/** + * Greet someone + * @function Greet + * @param name {string} + * @returns {Promise} + **/ +export function Greet(name) { + return wails.CallByName("main.GreetService.Greet", ...Array.prototype.slice.call(arguments, 0)); +} diff --git a/v3/internal/parser/testdata/variable_single_from_function/models.ts b/v3/internal/parser/testdata/variable_single_from_function/models.ts deleted file mode 100644 index 0817f259b..000000000 --- a/v3/internal/parser/testdata/variable_single_from_function/models.ts +++ /dev/null @@ -1,5 +0,0 @@ -// @ts-check -// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL -// This file is automatically generated. DO NOT EDIT - -// TODO : nothing generated yet \ No newline at end of file diff --git a/v3/internal/parser/testdata/variable_single_from_other_function/bindings_main.js b/v3/internal/parser/testdata/variable_single_from_other_function/bindings_main.js deleted file mode 100644 index ae0db8c58..000000000 --- a/v3/internal/parser/testdata/variable_single_from_other_function/bindings_main.js +++ /dev/null @@ -1,27 +0,0 @@ -// @ts-check -// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL -// This file is automatically generated. DO NOT EDIT - -/** - * @typedef {import('./models').main.Person} mainPerson - */ - -export const GreetService = { - - /** - * GreetService.Greet - * Greet does XYZ - * @param name {string} - * @returns {Promise} - **/ - Greet: function(name) { return wails.CallByID(1411160069, ...Array.prototype.slice.call(arguments, 0)); }, - - /** - * GreetService.NewPerson - * NewPerson creates a new person - * @param name {string} - * @returns {Promise} - **/ - NewPerson: function(name) { return wails.CallByID(1661412647, ...Array.prototype.slice.call(arguments, 0)); }, -}; - diff --git a/v3/internal/parser/testdata/variable_single_from_other_function/bindings_services.js b/v3/internal/parser/testdata/variable_single_from_other_function/bindings_services.js deleted file mode 100644 index 9b0d9d63d..000000000 --- a/v3/internal/parser/testdata/variable_single_from_other_function/bindings_services.js +++ /dev/null @@ -1,19 +0,0 @@ -// @ts-check -// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL -// This file is automatically generated. DO NOT EDIT - -/** - * @typedef {import('./models').services.Address} servicesAddress - */ - -export const OtherService = { - - /** - * OtherService.Yay - * - * - * @returns {Promise} - **/ - Yay: function() { return wails.CallByID(302702907, ...Array.prototype.slice.call(arguments, 0)); }, -}; - diff --git a/v3/internal/parser/testdata/variable_single_from_other_function/frontend/bindings/main/GreetService.js b/v3/internal/parser/testdata/variable_single_from_other_function/frontend/bindings/main/GreetService.js new file mode 100644 index 000000000..e654b5d6c --- /dev/null +++ b/v3/internal/parser/testdata/variable_single_from_other_function/frontend/bindings/main/GreetService.js @@ -0,0 +1,27 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +/** + * @typedef {import('./models').Person} Person + */ + +/** + * Greet does XYZ + * @function Greet + * @param name {string} + * @returns {Promise} + **/ +export function Greet(name) { + return wails.CallByID(1411160069, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * NewPerson creates a new person + * @function NewPerson + * @param name {string} + * @returns {Promise} + **/ +export function NewPerson(name) { + return wails.CallByID(1661412647, ...Array.prototype.slice.call(arguments, 0)); +} diff --git a/v3/internal/parser/testdata/variable_single_from_other_function/frontend/bindings/main/GreetService.name.js b/v3/internal/parser/testdata/variable_single_from_other_function/frontend/bindings/main/GreetService.name.js new file mode 100644 index 000000000..56f3bea1c --- /dev/null +++ b/v3/internal/parser/testdata/variable_single_from_other_function/frontend/bindings/main/GreetService.name.js @@ -0,0 +1,27 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +/** + * @typedef {import('./models').Person} Person + */ + +/** + * Greet does XYZ + * @function Greet + * @param name {string} + * @returns {Promise} + **/ +export function Greet(name) { + return wails.CallByName("main.GreetService.Greet", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * NewPerson creates a new person + * @function NewPerson + * @param name {string} + * @returns {Promise} + **/ +export function NewPerson(name) { + return wails.CallByName("main.GreetService.NewPerson", ...Array.prototype.slice.call(arguments, 0)); +} diff --git a/v3/internal/parser/testdata/variable_single_from_other_function/frontend/bindings/main/models.interfaces.ts b/v3/internal/parser/testdata/variable_single_from_other_function/frontend/bindings/main/models.interfaces.ts new file mode 100644 index 000000000..2df3adf6d --- /dev/null +++ b/v3/internal/parser/testdata/variable_single_from_other_function/frontend/bindings/main/models.interfaces.ts @@ -0,0 +1,12 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +import * as services from "../services/models"; + +// Person is a person! +// They have a name and an address +export interface Person { + name: string; + address: services.Address; +} diff --git a/v3/internal/parser/testdata/variable_single_from_other_function/frontend/bindings/main/models.js b/v3/internal/parser/testdata/variable_single_from_other_function/frontend/bindings/main/models.js new file mode 100644 index 000000000..177fff3f3 --- /dev/null +++ b/v3/internal/parser/testdata/variable_single_from_other_function/frontend/bindings/main/models.js @@ -0,0 +1,35 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +/** + * @typedef {import('../services/models').Address} servicesAddress + */ + +// Person is a person! +// They have a name and an address +export const Person = class { + /** + * Creates a new Person instance. + * @constructor + * @param {Object} source - The source object to create the Person. + * @param {string} source.Name + * @param {servicesAddress} source.Address + */ + constructor(source = {}) { + const { name = "", address = null } = source; + this.name = name; + this.address = address; + } + + /** + * Creates a new Person instance from a string or object. + * @param {string|object} source - The source data to create a Person instance from. + * @returns {Person} A new Person instance. + */ + static createFrom(source) { + let parsedSource = typeof source === 'string' ? JSON.parse(source) : source; + return new Person(parsedSource); + } +}; + diff --git a/v3/internal/parser/testdata/variable_single_from_other_function/frontend/bindings/main/models.ts b/v3/internal/parser/testdata/variable_single_from_other_function/frontend/bindings/main/models.ts new file mode 100644 index 000000000..a3a61ca3a --- /dev/null +++ b/v3/internal/parser/testdata/variable_single_from_other_function/frontend/bindings/main/models.ts @@ -0,0 +1,23 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +import * as services from "../services/models"; + +// Person is a person! +// They have a name and an address +export class Person { + name: string; + address: services.Address; + + constructor(source: Partial = {}) { + const {name = "", address = null} = source; + this.name = name; + this.address = address; + } + + static createFrom(source: string | object = {}): Person { + let parsedSource = typeof source === 'string' ? JSON.parse(source) : source; + return new Person(parsedSource as Partial); + } +} diff --git a/v3/internal/parser/testdata/variable_single_from_other_function/frontend/bindings/services/OtherService.js b/v3/internal/parser/testdata/variable_single_from_other_function/frontend/bindings/services/OtherService.js new file mode 100644 index 000000000..78c9f8515 --- /dev/null +++ b/v3/internal/parser/testdata/variable_single_from_other_function/frontend/bindings/services/OtherService.js @@ -0,0 +1,16 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +/** + * @typedef {import('./models').Address} Address + */ + +/** + * Yay does this and that + * @function Yay + * @returns {Promise
} + **/ +export function Yay() { + return wails.CallByID(302702907, ...Array.prototype.slice.call(arguments, 0)); +} diff --git a/v3/internal/parser/testdata/variable_single_from_other_function/frontend/bindings/services/OtherService.name.js b/v3/internal/parser/testdata/variable_single_from_other_function/frontend/bindings/services/OtherService.name.js new file mode 100644 index 000000000..43a778cd2 --- /dev/null +++ b/v3/internal/parser/testdata/variable_single_from_other_function/frontend/bindings/services/OtherService.name.js @@ -0,0 +1,16 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +/** + * @typedef {import('./models').Address} Address + */ + +/** + * Yay does this and that + * @function Yay + * @returns {Promise
} + **/ +export function Yay() { + return wails.CallByName("services.OtherService.Yay", ...Array.prototype.slice.call(arguments, 0)); +} diff --git a/v3/internal/parser/testdata/struct_literal_multiple/models.ts b/v3/internal/parser/testdata/variable_single_from_other_function/frontend/bindings/services/models.interfaces.ts similarity index 58% rename from v3/internal/parser/testdata/struct_literal_multiple/models.ts rename to v3/internal/parser/testdata/variable_single_from_other_function/frontend/bindings/services/models.interfaces.ts index 0817f259b..9470a4945 100644 --- a/v3/internal/parser/testdata/struct_literal_multiple/models.ts +++ b/v3/internal/parser/testdata/variable_single_from_other_function/frontend/bindings/services/models.interfaces.ts @@ -2,4 +2,9 @@ // Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL // This file is automatically generated. DO NOT EDIT -// TODO : nothing generated yet \ No newline at end of file + +export interface Address { + street: string; + state: string; + country: string; +} diff --git a/v3/internal/parser/testdata/variable_single_from_other_function/frontend/bindings/services/models.js b/v3/internal/parser/testdata/variable_single_from_other_function/frontend/bindings/services/models.js new file mode 100644 index 000000000..4c7637020 --- /dev/null +++ b/v3/internal/parser/testdata/variable_single_from_other_function/frontend/bindings/services/models.js @@ -0,0 +1,31 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +export const Address = class { + /** + * Creates a new Address instance. + * @constructor + * @param {Object} source - The source object to create the Address. + * @param {string} source.Street + * @param {string} source.State + * @param {string} source.Country + */ + constructor(source = {}) { + const { street = "", state = "", country = "" } = source; + this.street = street; + this.state = state; + this.country = country; + } + + /** + * Creates a new Address instance from a string or object. + * @param {string|object} source - The source data to create a Address instance from. + * @returns {Address} A new Address instance. + */ + static createFrom(source) { + let parsedSource = typeof source === 'string' ? JSON.parse(source) : source; + return new Address(parsedSource); + } +}; + diff --git a/v3/internal/parser/testdata/variable_single_from_other_function/frontend/bindings/services/models.ts b/v3/internal/parser/testdata/variable_single_from_other_function/frontend/bindings/services/models.ts new file mode 100644 index 000000000..dc2a7446f --- /dev/null +++ b/v3/internal/parser/testdata/variable_single_from_other_function/frontend/bindings/services/models.ts @@ -0,0 +1,22 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + + +export class Address { + street: string; + state: string; + country: string; + + constructor(source: Partial
= {}) { + const {street = "", state = "", country = ""} = source; + this.street = street; + this.state = state; + this.country = country; + } + + static createFrom(source: string | object = {}): Address { + let parsedSource = typeof source === 'string' ? JSON.parse(source) : source; + return new Address(parsedSource as Partial
); + } +} diff --git a/v3/internal/parser/testdata/variable_single_from_other_function/main.go b/v3/internal/parser/testdata/variable_single_from_other_function/main.go index 9d10a301e..b7b19a163 100644 --- a/v3/internal/parser/testdata/variable_single_from_other_function/main.go +++ b/v3/internal/parser/testdata/variable_single_from_other_function/main.go @@ -15,6 +15,8 @@ type GreetService struct { target *Person } +// Person is a person! +// They have a name and an address type Person struct { Name string Address *services.Address diff --git a/v3/internal/parser/testdata/variable_single_from_other_function/models.ts b/v3/internal/parser/testdata/variable_single_from_other_function/models.ts deleted file mode 100644 index c44731c20..000000000 --- a/v3/internal/parser/testdata/variable_single_from_other_function/models.ts +++ /dev/null @@ -1,48 +0,0 @@ -// @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; - address: services.Address; - - constructor(source: Partial = {}) { - const { name = "", address = null } = source; - this.name = name; - this.address = address; - } - - static createFrom(source: string | object = {}): Person { - let parsedSource = typeof source === 'string' ? JSON.parse(source) : source; - return new Person(parsedSource as Partial); - } - - } - -} -export namespace services { - - - export class Address { - street: string; - state: string; - country: string; - - constructor(source: Partial
= {}) { - const { street = "", state = "", country = "" } = source; - this.street = street; - this.state = state; - this.country = country; - } - - static createFrom(source: string | object = {}): Address { - let parsedSource = typeof source === 'string' ? JSON.parse(source) : source; - return new Address(parsedSource as Partial
); - } - - } - -} \ No newline at end of file