mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-12 12:31:22 +00:00
Allow renaming exported functions into JS (#525)
Support the `js_name` attribute on exports as well as imports to allow exporting types as camelCase instead of snake_case, for example. Closes #221
This commit is contained in:
@ -51,3 +51,35 @@ possibilities!
|
||||
const f = new Foo();
|
||||
console.log(f.get_contents());
|
||||
```
|
||||
|
||||
* `js_name` - this can be used to export a different name in JS than what
|
||||
something is named in Rust, for example:
|
||||
|
||||
```rust
|
||||
#[wasm_bindgen]
|
||||
pub struct Foo {
|
||||
contents: u32,
|
||||
}
|
||||
|
||||
#[wasm_bindgen(js_name = makeFoo)]
|
||||
pub fn make_foo() -> Foo {
|
||||
Foo { contents: 6 }
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
impl Foo {
|
||||
#[wasm_bindgen(js_name = getContents)]
|
||||
pub fn get_contents(&self) -> u32 {
|
||||
self.contents
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Here this can be used in JS as:
|
||||
|
||||
```js
|
||||
import { makeFoo } from './my_module';
|
||||
|
||||
const foo = makeFoo();
|
||||
console.log(foo.getContents());
|
||||
```
|
||||
|
Reference in New Issue
Block a user