-
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
Fixes #3929 Allow exporting functions named "default". #3930
Fixes #3929 Allow exporting functions named "default". #3930
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.
Missing a changelog entry.
I believe that this should be safe to add. @Liamolucko would you mind double-checking me on this?
This doesn't work with I don't particularly like adding target-compatibility caveats like this, but I also can't really imagine a scenario where it's an issue - discovering that you aren't allowed to set the default export on If we do go ahead with this it'd be nice if the CLI printed a proper error when trying to create a default export on the web target, rather than delaying it until the JS is actually used and throws a 'duplicate default export' error. |
I think that sounds reasonable enough. I'll try to extend my PR with a check for |
I've added a check that throws an error if wasm-bindgen-cli is called with --target web and there exist a exported symbol called "default". I'm notoriously bad at creating good error messages, so feedback is welcome 😆 |
@daxpedda @Liamolucko Not to be pushy, but is there a chance I can get a new review ? |
I agree with whats said in #3930 (comment), I didn't know that this can't work with the Web target and I think its not the best idea to introduce such target-incompatible changes. In hindsight I believe that #2855 should not have simply renamed functions, but instead thrown an error. So I currently think the way forward is to instead of renaming exports where it would make a semantic difference, export them with the Let me know if this doesn't address your problem @nicklaswj. |
@daxpedda I'm sure it's because my JS knowledge is lacking. However I don't understand the semantic difference between your suggestion and what my most recent additions to my PR does. I'm willing to do the work, however I'm currently not sure what should be done. |
The point is to make exporting In this case the issue was that This work around could be applied to other keywords as well, therefore a fix should attempt to craft a general solution. Let me know if anything else is unclear. |
I agree.
The PR already ends up doing that though: more specifically The issue is that the default export is reserved for |
I do not really have an opinion on how we solve it, however it is blocking me. @Liamolucko, if I understand your latest comment correct, I feel like we haven't really reached a conclusion whether I should change anything in my PR or not - is that correctly understood? |
Well, there are 2 options:
At this point I'm leaning towards option 1 (how often do people really switch targets anyway?), but I was waiting to see what @daxpedda's thoughts were.
In the meantime, how important is it that the default export comes directly out of wasm-bindgen? Is there anything stopping you from making a JS wrapper that reexports it as |
Well that's unfortunate, and here I thought I found a solution that could work.
Yeah I think I'm fine with proceeding with the PR then. A solution that came to mind is to add an attribute to explicitly opt-in to the target incompatibility, but I think that's overkill. |
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.
Thanks!
This PR fixes #3929.
This PR adds the keyword
default
to the argumentskip_keywords
forfn function_from_decl
when exporting functions.