1use proc_macro2::TokenStream;
8use quote::quote_spanned;
9use syn::spanned::Spanned as _;
10use syn::{Error, Item, Result};
11
12use crate::class::r#impl::impl_js_class_impl;
13use crate::class::r#struct::impl_js_class_struct;
14
15mod accessor;
16pub(crate) mod constructor;
17mod r#impl;
18pub(crate) mod method;
19pub(crate) mod property;
20mod r#struct;
21
22pub(super) fn impl_js_class(item: Item) -> Result<TokenStream> {
23 match item {
24 Item::Struct(mut r#struct) => {
25 let impls = impl_js_class_struct(&mut r#struct)?;
26 Ok(quote_spanned!(r#struct.span() =>
27 #r#struct
28 #(#impls)*
29 ))
30 }
31 Item::Impl(mut r#impl) => {
32 let impls = impl_js_class_impl(&mut r#impl)?;
33 Ok(quote_spanned!(r#impl.span() =>
34 #r#impl
35 #(#impls)*
36 ))
37 }
38 _ => Err(Error::new(item.span(), "Expected Struct or Impl Block")),
39 }
40}