mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-12 04:21:21 +00:00
Skip args in overloaded method names if all same
This commit updates how we name overloaded methods. Previously all argument names were concatenated, but after this commit it only concatenates argument names where at least one possibility has a different type. Otherwise if all possibilities have the same type name it in theory isn't adding too much more information! Additionally this commit also switches to using `_with_` consistently everywhere instead of `_with_` for constructors and `_using_` for methods. Closes #712
This commit is contained in:
@ -3,6 +3,6 @@ use web_sys::console;
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn test_console() {
|
||||
console::time_using_label("test label");
|
||||
console::time_end_using_label("test label");
|
||||
console::time_with_label("test label");
|
||||
console::time_end_with_label("test label");
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ use web_sys::{DomPoint, DomPointReadOnly};
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn dom_point() {
|
||||
let x = DomPoint::new_using_x_and_y_and_z_and_w(1.0, 2.0, 3.0, 4.0).unwrap();
|
||||
let x = DomPoint::new_with_x_and_y_and_z_and_w(1.0, 2.0, 3.0, 4.0).unwrap();
|
||||
assert_eq!(x.x(), 1.0);
|
||||
x.set_x(1.5);
|
||||
assert_eq!(x.x(), 1.5);
|
||||
@ -24,7 +24,7 @@ fn dom_point() {
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn dom_point_readonly() {
|
||||
let x = DomPoint::new_using_x_and_y_and_z_and_w(1.0, 2.0, 3.0, 4.0).unwrap();
|
||||
let x = DomPoint::new_with_x_and_y_and_z_and_w(1.0, 2.0, 3.0, 4.0).unwrap();
|
||||
let x = DomPointReadOnly::from(JsValue::from(x));
|
||||
assert_eq!(x.x(), 1.0);
|
||||
assert_eq!(x.y(), 2.0);
|
||||
|
@ -3,7 +3,7 @@ use web_sys::HtmlOptionElement;
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn test_option_element() {
|
||||
let option = HtmlOptionElement::new_using_text_and_value_and_default_selected_and_selected(
|
||||
let option = HtmlOptionElement::new_with_text_and_value_and_default_selected_and_selected(
|
||||
"option_text",
|
||||
"option_value",
|
||||
false,
|
||||
|
@ -99,7 +99,7 @@ fn test_table_element() {
|
||||
);
|
||||
|
||||
table
|
||||
.insert_row_using_index(0)
|
||||
.insert_row_with_index(0)
|
||||
.expect("Failed to insert row at index 0");
|
||||
assert!(
|
||||
table.rows().length() == 1,
|
||||
|
@ -50,7 +50,7 @@ fn static_property() {
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn one_method_using_an_undefined_import_doesnt_break_all_other_methods() {
|
||||
fn one_method_with_an_undefined_import_doesnt_break_all_other_methods() {
|
||||
let f = UndefinedMethod::new().unwrap();
|
||||
assert!(f.ok_method());
|
||||
}
|
||||
@ -81,14 +81,14 @@ fn indexing() {
|
||||
#[wasm_bindgen_test]
|
||||
fn optional_and_union_arguments() {
|
||||
let f = OptionalAndUnionArguments::new().unwrap();
|
||||
assert_eq!(f.m_using_a("abc"), "string, abc, boolean, true, number, 123, number, 456");
|
||||
assert_eq!(f.m_using_a_and_b("abc", false), "string, abc, boolean, false, number, 123, number, 456");
|
||||
assert_eq!(f.m_using_dom_str_and_bool_and_i16("abc", false, 5), "string, abc, boolean, false, number, 5, number, 456");
|
||||
assert_eq!(f.m_using_dom_str_and_bool_and_dom_str("abc", false, "5"), "string, abc, boolean, false, string, 5, number, 456");
|
||||
assert_eq!(f.m_using_dom_str_and_bool_and_i16_and_opt_i64("abc", false, 5, Some(10)), "string, abc, boolean, false, number, 5, bigint, 10");
|
||||
assert_eq!(f.m_using_dom_str_and_bool_and_i16_and_opt_bool("abc", false, 5, Some(true)), "string, abc, boolean, false, number, 5, boolean, true");
|
||||
assert_eq!(f.m_using_dom_str_and_bool_and_dom_str_and_opt_i64("abc", false, "5", Some(10)), "string, abc, boolean, false, string, 5, bigint, 10");
|
||||
assert_eq!(f.m_using_dom_str_and_bool_and_dom_str_and_opt_bool("abc", false, "5", Some(true)), "string, abc, boolean, false, string, 5, boolean, true");
|
||||
assert_eq!(f.m("abc"), "string, abc, boolean, true, number, 123, number, 456");
|
||||
assert_eq!(f.m_with_b("abc", false), "string, abc, boolean, false, number, 123, number, 456");
|
||||
assert_eq!(f.m_with_bool_and_i16("abc", false, 5), "string, abc, boolean, false, number, 5, number, 456");
|
||||
assert_eq!(f.m_with_bool_and_dom_str("abc", false, "5"), "string, abc, boolean, false, string, 5, number, 456");
|
||||
assert_eq!(f.m_with_bool_and_i16_and_opt_i64("abc", false, 5, Some(10)), "string, abc, boolean, false, number, 5, bigint, 10");
|
||||
assert_eq!(f.m_with_bool_and_i16_and_opt_bool("abc", false, 5, Some(true)), "string, abc, boolean, false, number, 5, boolean, true");
|
||||
assert_eq!(f.m_with_bool_and_dom_str_and_opt_i64("abc", false, "5", Some(10)), "string, abc, boolean, false, string, 5, bigint, 10");
|
||||
assert_eq!(f.m_with_bool_and_dom_str_and_opt_bool("abc", false, "5", Some(true)), "string, abc, boolean, false, string, 5, boolean, true");
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
|
@ -273,9 +273,13 @@ impl<'src> FirstPassRecord<'src> {
|
||||
let rust_name = if possibilities.len() > 1 {
|
||||
let mut rust_name = rust_name.clone();
|
||||
let mut first = true;
|
||||
for ((argument_name, _, _), idl_type) in arguments.iter().zip(idl_types) {
|
||||
let iter = arguments.iter().zip(idl_types).enumerate();
|
||||
for (i, ((argument_name, _, _), idl_type)) in iter {
|
||||
if possibilities.iter().all(|p| p.get(i) == Some(idl_type)) {
|
||||
continue
|
||||
}
|
||||
if first {
|
||||
rust_name.push_str("_using_");
|
||||
rust_name.push_str("_with_");
|
||||
first = false;
|
||||
} else {
|
||||
rust_name.push_str("_and_");
|
||||
|
Reference in New Issue
Block a user