Skip to content

Commit 2cfffc6

Browse files
committed
add js_class attribute for defining what class an imported method is for
1 parent a804a0e commit 2cfffc6

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

crates/backend/src/ast.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,9 +405,11 @@ impl Program {
405405
};
406406
let class_name = extract_path_ident(class_name)
407407
.expect("first argument of method must be a bare type");
408+
let class_name = wasm.opts.js_class().map(Into::into)
409+
.unwrap_or_else(|| class_name.to_string());
408410

409411
ImportFunctionKind::Method {
410-
class: class_name.to_string(),
412+
class: class_name,
411413
ty: class.clone(),
412414
kind: MethodKind::Normal,
413415
}
@@ -947,6 +949,16 @@ impl BindgenAttrs {
947949
})
948950
.next()
949951
}
952+
953+
fn js_class(&self) -> Option<&str> {
954+
self.attrs
955+
.iter()
956+
.filter_map(|a| match a {
957+
BindgenAttr::JsClass(s) => Some(&s[..]),
958+
_ => None,
959+
})
960+
.next()
961+
}
950962
}
951963

952964
impl syn::synom::Synom for BindgenAttrs {
@@ -977,6 +989,7 @@ pub enum BindgenAttr {
977989
Structural,
978990
Readonly,
979991
JsName(Ident),
992+
JsClass(String),
980993
}
981994

982995
impl syn::synom::Synom for BindgenAttr {
@@ -1038,6 +1051,13 @@ impl syn::synom::Synom for BindgenAttr {
10381051
ns: call!(term2ident) >>
10391052
(ns)
10401053
)=> { BindgenAttr::JsName }
1054+
|
1055+
do_parse!(
1056+
call!(term, "js_class") >>
1057+
punct!(=) >>
1058+
s: syn!(syn::LitStr) >>
1059+
(s.value())
1060+
)=> { BindgenAttr::JsClass }
10411061
));
10421062
}
10431063

0 commit comments

Comments
 (0)