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

Fixes #3929 Allow exporting functions named "default". #3930

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

nicklaswj
Copy link

This PR fixes #3929.
This PR adds the keyword defaultto the argument skip_keywords for fn function_from_decl when exporting functions.

Copy link
Collaborator

@daxpedda daxpedda left a 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?

@Liamolucko
Copy link
Collaborator

I believe that this should be safe to add. @Liamolucko would you mind double-checking me on this?

This doesn't work with --target web, since the default export is already used for init. But it works with all other targets.

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 --target web isn't really any weirder than discovering that it got silently renamed to _default.

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.

@nicklaswj
Copy link
Author

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 --target weband #[wasm_bindgen(js_name = default)]

@nicklaswj
Copy link
Author

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 😆

@nicklaswj nicklaswj requested a review from daxpedda April 22, 2024 08:56
@nicklaswj
Copy link
Author

@daxpedda @Liamolucko Not to be pushy, but is there a chance I can get a new review ?

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.

Exports with #[wasm_bindgen(js_name = default)] gets exported as fn _default
3 participants