wasm-bindgen
wasm-bindgen copied to clipboard
Fixed generated types for getters and setters
While working on #4201, I had the idea to test how wasm bindgen handles getter-setter pairs with different types. Not well was the answer.
This PR completely changes how the type definitions for getters and setters are generated and fixes several bugs:
- Static getters/setters with the same name as instance getters/setters would interfere with each other and only result in one generated property. Whether this property was static depended on the order in which the getters/setters were declared in Rust.
- Getters and setters with different types only produced one property with one of the types. Which type the property had depended on the order in which the getter and setter were declared in Rust.
- (minor bug) Write-only properties (setter but no getter) produced incorrect type definition that allowed reading the property.
There were also some minor issues:
- Fields were sorted by name and not written in the order in which they were declared like everything else.
- Doc comments weren't indented properly.
This PR fixes all of those issues and adds a test to verify correctness.
Fixing these issues is a requirement for #4188 and #4201.