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

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

Open
nicklaswj opened this issue Apr 19, 2024 · 0 comments · May be fixed by #3930
Open

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

nicklaswj opened this issue Apr 19, 2024 · 0 comments · May be fixed by #3930
Labels

Comments

@nicklaswj
Copy link

nicklaswj commented Apr 19, 2024

Describe the Bug

I'm trying to create a plugin for the javascript project EventCatalog in Rust with wasm_bindgen.
Their plugin system is fairly simple and it works by:

  1. Adding your plugin as a nodejs package.
  2. Place the name of the added package in a config file.
  3. When the EventCatalog gets build, it require your package/plugin that's defined in the config file and calls the default exported function, i.e. whats exported with export default ... in the main module of the added nodejs package. For the curios you can find the code for the plugin loading code here.

I tried to create my plugin with the following code:

#[wasm_bindgen(js_name = default)]
pub fn init_my_plugin() {
    ...
}

Unfortunately the above function gets exported as _default instead of default and the generated JS code (with --target nodejs) looks like this:

module.exports._default = function() {
    wasm._default();
};

which means that EventCatalog fails to call my plugin. This issue is very much related to #3012 and is just the other side of the coin. I think it's reasonable that if you can import fn default, you should also be able to export fn default.

Expected Behavior

The following Rust function

#[wasm_bindgen(js_name = default)]
pub fn init_my_plugin() {
    ...
}

should be exported as defaultand not _defaultand the generated javascript code should be:

module.exports.default = function() {
    wasm.default();
};

Additional Context

I'll create a PR soon (PR created #3930)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant