Skip to content

Commit

Permalink
Move deprecation warning to function definition
Browse files Browse the repository at this point in the history
  • Loading branch information
danielronnkvist committed Jan 13, 2025
1 parent bb07a33 commit 11a9293
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
10 changes: 10 additions & 0 deletions crates/backend/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,16 @@ impl TryToTokens for ast::Export {
add_check(quote! {
let _: #wasm_bindgen::__rt::marker::CheckSupportsConstructor<#class>;
});

if self.function.r#async {
(quote_spanned! {
self.function.name_span =>
#[deprecated(note = "async constructors are not supported")]
fn constructor() {}
constructor();
})
.to_tokens(into);
}
}
ast::MethodKind::Operation(operation) => match operation.kind {
ast::OperationKind::Getter(_) | ast::OperationKind::Setter(_) => {
Expand Down
5 changes: 0 additions & 5 deletions crates/macro-support/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1418,11 +1418,6 @@ impl MacroParse<&ClassMarker> for &mut syn::ImplItemFn {
FunctionPosition::Impl { self_ty: class },
)?;
let method_kind = if opts.constructor().is_some() {
if function.r#async {
self.attrs.push(syn::parse_quote! {
#[deprecated(note = "constructors cannot be async")]
});
}
ast::MethodKind::Constructor
} else {
let is_static = method_self.is_none();
Expand Down

0 comments on commit 11a9293

Please sign in to comment.