mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-12 04:21:21 +00:00
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:
@ -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!(
|
||||
|
@ -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)
|
||||
};
|
||||
|
Reference in New Issue
Block a user