-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Improved string enum typing try 2 #4180
Improved string enum typing try 2 #4180
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work!
Missing a changelog entry.
Gonna wait for those tests as well like you said!
Also reverts #4175. |
@@ -83,6 +83,10 @@ export const ImplicitDiscriminant = Object.freeze({ A:0,"0":"A",B:1,"1":"B",C:42 | |||
|
|||
const __wbindgen_enum_ColorName = ["green", "yellow", "red"]; | |||
|
|||
const __wbindgen_enum_FooBar = ["foo", "bar"]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't used so it should not be generated as well.
I don't believe this is an issue this PR caused though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is a side effect of #4147 (point 3), though I also only noticed this yesterday. I'll make a PR fixing this tomorrow. I just wanted for this PR to be in, because I'll need to implement a similar usage analysis. Nothing complex, I just wanted to see would be acceptable in the first place.
Alright, let's try again. This PR reverts most of #4174 and restores most of #4147. I just made 2 changes:
This ensures that we don't repeat #4163 and puts us in a good position to make a fix for #2153, because we just have to decide when to export the generated type (but this will be its own PR).
Code-wise, not much is different from #4147. The only new part is how usage is detected. I hocked into the function that generates function signatures to keep track of which string enums are referenced. Since we always generate the type definition for exported functions before the type definitions for string enums, this works out beautifully and ensures that we know exactly which string enums are used.
If possible, please merge #4179 before this PR, so I can update this PR and have tests to ensure that #4163 isn't repeated.