wasm-tool / parcel-plugin-wasm.rs

wasm-bindgen support for Parcel bundler
MIT License
66 stars 16 forks source link

Bundle fails to export enum correctly #17

Closed josephg closed 5 years ago

josephg commented 5 years ago

Given rust code which exports an enum:

#[wasm_bindgen]
pub enum MyEnum {
    Bar, Zot
}

The bindgen compiled code contains this:

export const MyEnum = Object.freeze({ Bar:0,Zot:1, });

But for some reason that gets exported on exports rather than __exports:

const MyEnum = Object.freeze({
  Bar: 0,
  Zot: 1
});

exports.MyEnum = MyEnum;

// Everything else is on __exports, and works fine!
__exports.some_fn = function (f) { 
  // ...
};

__exports.__wbindgen_throw = function (ptr, len) {
  throw new Error(getStringFromWasm(ptr, len));
};
// ... etc.

As a result the exported enum is unavailable in the bundled code. I have no idea if this is a bug in parcel or if its an issue in babel or something.

Using the latest versions of everything:

    "@babel/core": "^7.4.3",
    "@babel/preset-env": "^7.4.3",
    "parcel-bundler": "^1.12.3",
    "parcel-plugin-wasm.rs": "^1.2.8"
josephg commented 5 years ago

🙌 cheers!