Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix binding generation special cases #1902

Merged
merged 6 commits into from
Oct 1, 2022

Conversation

JulioDRF
Copy link
Contributor

@JulioDRF JulioDRF commented Sep 26, 2022

Fixes #1901

These changes prevent binding.GenerateModels() from yielding broken TypeScript for the following special cases:

  • Struct fields of imported types that also use imported types don't create a namespace for the nested type (it's messy to explain, see the binding_nestedimport_test)
  • Struct fields of type []T or map[any]T where T is an imported struct don't reference the imported namespace in the generated code (e.g. we get foo: Foo[] instead of foo: imported.Foo[])
  • Struct fields with non-standard JS variable names (e.g. `` Foobar string json:"foo-bar")
  • Struct fields of type map[T]any (where T is anything but string)

And finally:

  • Added tests for all of the above

Extra notes:

I necromanced the binding tests from https://github.com/wailsapp/wails/tree/feature/ts-generation-tests and expanded upon them. I see that the branch has since been deleted, and the directory structure for the tests in this PR feels inelegant, so let me know if there's an obvious way to improve it and I will revise it.

As far as I can tell, the new tests cover these issues and they are resolved

@leaanthony
Copy link
Member

This is amazing! Thank you so much for taking the time and effort to look into this important area. It would be good to get feedback from those who opened the linked issues and see what the feedback is. Other than that, it looks great!

@leaanthony
Copy link
Member

I think we can go with this. Thank you so much 🙏

@leaanthony leaanthony merged commit 40e326a into wailsapp:master Oct 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Generated models.ts contains invalid TypeScript in a few edge cases
2 participants