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:
Alex Crichton
2018-07-20 12:01:28 -05:00
committed by GitHub
parent 61ef250dca
commit 9753f9150b
6 changed files with 103 additions and 6 deletions

View File

@ -709,3 +709,51 @@ fn double_consume() {
"#)
.test();
}
#[test]
fn rename_function_for_js() {
project()
.file("src/lib.rs", r#"
#![feature(use_extern_macros, wasm_import_module)]
extern crate wasm_bindgen;
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
pub struct Foo { }
#[wasm_bindgen]
impl Foo {
#[wasm_bindgen(constructor)]
pub fn new() -> Foo {
let f = Foo {};
f.foo();
return f
}
#[wasm_bindgen(js_name = bar)]
pub fn foo(&self) {
}
}
#[wasm_bindgen(js_name = js_foo)]
pub fn foo() {}
#[wasm_bindgen]
pub fn bar() {
foo();
}
"#)
.file("test.js", r#"
import { Foo, js_foo, bar } from "./out";
export function test() {
Foo.new().bar();
js_foo();
bar();
}
"#)
.test();
}