Skip to content

Commit

Permalink
Bump syn/quote in jstraceable_derive
Browse files Browse the repository at this point in the history
  • Loading branch information
Eijebong committed Feb 12, 2018
1 parent c18137b commit 3670d4d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 35 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions components/jstraceable_derive/Cargo.toml
Expand Up @@ -10,6 +10,6 @@ path = "lib.rs"
proc-macro = true

[dependencies]
quote = "0.3.15"
syn = "0.11"
synstructure = "0.5"
quote = "0.4.2"
syn = "0.12.12"
synstructure = "0.7"
43 changes: 14 additions & 29 deletions components/jstraceable_derive/lib.rs
Expand Up @@ -2,39 +2,24 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

extern crate proc_macro;
#[macro_use] extern crate quote;
extern crate syn;
extern crate synstructure;
#[macro_use] extern crate syn;
#[macro_use] extern crate synstructure;

#[proc_macro_derive(JSTraceable)]
pub fn expand_token_stream(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
expand_string(&input.to_string()).parse().unwrap()
}

fn expand_string(input: &str) -> String {
let mut type_ = syn::parse_macro_input(input).unwrap();
decl_derive!([JSTraceable] => js_traceable_derive);

let style = synstructure::BindStyle::Ref.into();
let match_body = synstructure::each_field(&mut type_, &style, |binding| {
Some(quote! { #binding.trace(tracer); })
fn js_traceable_derive(s: synstructure::Structure) -> quote::Tokens {
let match_body = s.each(|binding| {
Some(quote!(#binding.trace(tracer);))
});

let name = &type_.ident;
let (impl_generics, ty_generics, where_clause) = type_.generics.split_for_impl();
let mut where_clause = where_clause.clone();
for param in &type_.generics.ty_params {
where_clause.predicates.push(syn::WherePredicate::BoundPredicate(syn::WhereBoundPredicate {
bound_lifetimes: Vec::new(),
bounded_ty: syn::Ty::Path(None, param.ident.clone().into()),
bounds: vec![syn::TyParamBound::Trait(
syn::PolyTraitRef {
bound_lifetimes: Vec::new(),
trait_ref: syn::parse_path("::dom::bindings::trace::JSTraceable").unwrap(),
},
syn::TraitBoundModifier::None
)],
}))
let ast = s.ast();
let name = ast.ident;
let (impl_generics, ty_generics, where_clause) = ast.generics.split_for_impl();
let mut where_clause = where_clause.unwrap_or(&parse_quote!(where)).clone();
for param in ast.generics.type_params() {
let ident = param.ident;
where_clause.predicates.push(parse_quote!(#ident: ::dom::bindings::trace::JSTraceable))
}

let tokens = quote! {
Expand All @@ -51,5 +36,5 @@ fn expand_string(input: &str) -> String {
}
};

tokens.to_string()
tokens
}

0 comments on commit 3670d4d

Please sign in to comment.