mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-28 04:01:33 +00:00
Add ability to rename enums (js_name = new_name) (#2071)
* Add ability to rename enums (js_name = new_name) * Add a test
This commit is contained in:
@ -28,3 +28,7 @@ exports.js_expect_enum = (a, b) => {
|
||||
exports.js_expect_enum_none = a => {
|
||||
assert.strictEqual(a, undefined);
|
||||
};
|
||||
|
||||
exports.js_renamed_enum = b => {
|
||||
assert.strictEqual(wasm.JsRenamedEnum.B, b);
|
||||
};
|
||||
|
@ -9,6 +9,7 @@ extern "C" {
|
||||
fn js_handle_optional_enums(x: Option<Color>) -> Option<Color>;
|
||||
fn js_expect_enum(x: Color, y: Option<Color>);
|
||||
fn js_expect_enum_none(x: Option<Color>);
|
||||
fn js_renamed_enum(b: RenamedEnum);
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
@ -30,6 +31,13 @@ pub mod inner {
|
||||
}
|
||||
}
|
||||
|
||||
#[wasm_bindgen(js_name = JsRenamedEnum)]
|
||||
#[derive(Copy, Clone)]
|
||||
pub enum RenamedEnum {
|
||||
A = 10,
|
||||
B = 20,
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn enum_cycle(color: Color) -> Color {
|
||||
match color {
|
||||
@ -82,3 +90,8 @@ fn test_optional_enum_values() {
|
||||
js_expect_enum(Red, Some(Red));
|
||||
js_expect_enum_none(None);
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn test_renamed_enum() {
|
||||
js_renamed_enum(RenamedEnum::B);
|
||||
}
|
||||
|
Reference in New Issue
Block a user