try to fix js_name error when both getter and setter used (#2074)

* try to fix js_name error when both `getter` and `setter` used

* add tests
This commit is contained in:
a1trl9
2020-04-11 00:57:36 +08:00
committed by GitHub
parent 301a5f36eb
commit b9f78aba57
4 changed files with 195 additions and 7 deletions

View File

@ -330,12 +330,6 @@ impl Function {
pub fn infer_setter_property(&self) -> Result<String, Diagnostic> {
let name = self.name.to_string();
// if `#[wasm_bindgen(js_name = "...")]` is used then that explicitly
// because it was hand-written anyway.
if self.renamed_via_js_name {
return Ok(name);
}
// Otherwise we infer names based on the Rust function name.
if !name.starts_with("set_") {
bail_span!(

View File

@ -1,5 +1,6 @@
use std::cell::Cell;
use ast::OperationKind;
use backend::ast;
use backend::util::{ident_ty, ShortHash};
use backend::Diagnostic;
@ -710,7 +711,16 @@ fn function_from_decl(
let (name, name_span, renamed_via_js_name) =
if let Some((js_name, js_name_span)) = opts.js_name() {
(js_name.to_string(), js_name_span, true)
let kind = operation_kind(&opts);
let prefix = match kind {
OperationKind::Setter(_) => "set_",
_ => "",
};
(
format!("{}{}", prefix, js_name.to_string()),
js_name_span,
true,
)
} else {
(decl_name.to_string(), decl_name.span(), false)
};