|
0 |
--- a/Cargo.toml
|
|
1 |
+++ b/Cargo.toml
|
|
2 |
@@ -29,10 +29,10 @@
|
|
3 |
version = "0.2"
|
|
4 |
|
|
5 |
[dependencies.proc-macro2]
|
|
6 |
-version = "0.4"
|
|
7 |
+version = "1"
|
|
8 |
|
|
9 |
[dependencies.quote]
|
|
10 |
-version = "0.6"
|
|
11 |
+version = "1"
|
|
12 |
|
|
13 |
[dependencies.serde]
|
|
14 |
version = "1"
|
|
15 |
@@ -47,6 +47,6 @@
|
|
16 |
version = "0.6"
|
|
17 |
|
|
18 |
[dependencies.syn]
|
|
19 |
-version = "0.15"
|
|
20 |
+version = "1"
|
|
21 |
features = ["full", "parsing", "printing", "clone-impls"]
|
|
22 |
default-features = false
|
|
23 |
--- a/src/macro_js_export.rs
|
|
24 |
+++ b/src/macro_js_export.rs
|
|
25 |
@@ -262,7 +262,8 @@
|
|
26 |
quote! { #(#output)* }
|
|
27 |
}
|
|
28 |
|
|
29 |
-fn into_export( ident: syn::Ident, decl: &syn::FnDecl ) -> Export {
|
|
30 |
+fn into_export( decl: &syn::Signature ) -> Export {
|
|
31 |
+ let ident = decl.ident.clone();
|
|
32 |
assert!( decl.generics.lifetimes().next().is_none(), "Lifetimes are not yet not supported" );
|
|
33 |
assert!( decl.generics.type_params().next().is_none(), "Generics are not supported" );
|
|
34 |
assert!( decl.generics.where_clause.is_none(), "`where` clauses are not supported" );
|
|
35 |
@@ -276,22 +277,14 @@
|
|
36 |
let mut args = Vec::new();
|
|
37 |
for (index, arg) in decl.inputs.iter().cloned().enumerate() {
|
|
38 |
match arg {
|
|
39 |
- syn::FnArg::SelfRef( .. ) => panic!( "`&self` is not supported" ),
|
|
40 |
- syn::FnArg::SelfValue( .. ) => panic!( "`self` is not supported" ),
|
|
41 |
- syn::FnArg::Ignored( ty ) => {
|
|
42 |
- let ident = syn::Ident::new( &format!( "__arg_{}", index ), Span::call_site() );
|
|
43 |
- args.push( ExportArg {
|
|
44 |
- ident,
|
|
45 |
- ty: match_type( &ty )
|
|
46 |
- });
|
|
47 |
- },
|
|
48 |
- syn::FnArg::Captured( cap ) => {
|
|
49 |
- match cap.pat {
|
|
50 |
+ syn::FnArg::Receiver( .. ) => panic!( "`self` is not supported" ),
|
|
51 |
+ syn::FnArg::Typed( syn::PatType { pat, ty, .. } ) => {
|
|
52 |
+ match *pat {
|
|
53 |
syn::Pat::Wild( _ ) => {
|
|
54 |
let ident = syn::Ident::new( &format!( "__arg_{}", index ), Span::call_site() );
|
|
55 |
args.push( ExportArg {
|
|
56 |
ident,
|
|
57 |
- ty: match_type( &cap.ty )
|
|
58 |
+ ty: match_type( &ty )
|
|
59 |
});
|
|
60 |
},
|
|
61 |
syn::Pat::Ident( pat ) => {
|
|
62 |
@@ -301,13 +294,12 @@
|
|
63 |
|
|
64 |
args.push( ExportArg {
|
|
65 |
ident: pat.ident,
|
|
66 |
- ty: match_type( &cap.ty )
|
|
67 |
+ ty: match_type( &ty )
|
|
68 |
});
|
|
69 |
},
|
|
70 |
_ => panic!( "Argument patterns are not supported" )
|
|
71 |
}
|
|
72 |
- },
|
|
73 |
- syn::FnArg::Inferred( _ ) => panic!( "inferred argument types are not supported" )
|
|
74 |
+ }
|
|
75 |
}
|
|
76 |
}
|
|
77 |
|
|
78 |
@@ -329,7 +321,7 @@
|
|
79 |
|
|
80 |
match item {
|
|
81 |
syn::Item::Fn( ref function ) => {
|
|
82 |
- exports.push( into_export( function.ident.clone(), &function.decl ) );
|
|
83 |
+ exports.push( into_export( &function.sig ) );
|
|
84 |
},
|
|
85 |
_ => panic!( "`#[js_export]` attached to an unsupported element!" )
|
|
86 |
}
|
|
87 |
--- a/src/macro_async_test.rs
|
|
88 |
+++ b/src/macro_async_test.rs
|
|
89 |
@@ -29,7 +29,7 @@
|
|
90 |
}
|
|
91 |
|
|
92 |
// TODO: There must be a cleaner way to do this.
|
|
93 |
-fn check_decl( decl: &syn::FnDecl ) -> TestKind {
|
|
94 |
+fn check_decl( decl: &syn::Signature ) -> TestKind {
|
|
95 |
assert!( decl.generics.lifetimes().next().is_none(), "Lifetimes are yet not supported" );
|
|
96 |
assert!( decl.generics.where_clause.is_none(), "`where` clauses are not supported" );
|
|
97 |
assert!( decl.variadic.is_none(), "Variadic functions are not supported" );
|
|
98 |
@@ -137,19 +137,17 @@
|
|
99 |
panic!( "Expected a function with a single argument!" );
|
|
100 |
}
|
|
101 |
|
|
102 |
- let arg = decl.inputs.last().unwrap().into_value();
|
|
103 |
- match arg {
|
|
104 |
- syn::FnArg::SelfRef( .. ) => panic!( "`&self` is not supported" ),
|
|
105 |
- syn::FnArg::SelfValue( .. ) => panic!( "`self` is not supported" ),
|
|
106 |
- syn::FnArg::Ignored( .. ) => panic!( "ignored args are not supported" ),
|
|
107 |
- syn::FnArg::Captured( cap ) => {
|
|
108 |
- match cap.pat {
|
|
109 |
+ let arg = decl.inputs.last().unwrap();
|
|
110 |
+ match *arg {
|
|
111 |
+ syn::FnArg::Receiver( .. ) => panic!( "`self` is not supported" ),
|
|
112 |
+ syn::FnArg::Typed( syn::PatType { ref pat, ref ty, .. } ) => {
|
|
113 |
+ match **pat {
|
|
114 |
syn::Pat::Ident( ref pat ) => {
|
|
115 |
assert!( pat.by_ref.is_none(), "`ref` bindings are not supported" );
|
|
116 |
assert!( pat.mutability.is_none(), "`mut` bindings are not supported" );
|
|
117 |
assert!( pat.subpat.is_none(), "Subpatterns are not supported" );
|
|
118 |
|
|
119 |
- match cap.ty {
|
|
120 |
+ match **ty {
|
|
121 |
syn::Type::Path(
|
|
122 |
syn::TypePath {
|
|
123 |
qself: None,
|
|
124 |
@@ -177,16 +175,15 @@
|
|
125 |
},
|
|
126 |
_ => panic!( "Argument patterns are not supported" )
|
|
127 |
}
|
|
128 |
- },
|
|
129 |
- syn::FnArg::Inferred( _ ) => panic!( "inferred argument types are not supported" )
|
|
130 |
+ }
|
|
131 |
}
|
|
132 |
}
|
|
133 |
|
|
134 |
fn async_test_impl( item: syn::Item ) -> proc_macro2::TokenStream {
|
|
135 |
let (ident, block, test_kind) = match item {
|
|
136 |
syn::Item::Fn( function ) => {
|
|
137 |
- let test_kind = check_decl( &function.decl );
|
|
138 |
- (function.ident, function.block, test_kind)
|
|
139 |
+ let test_kind = check_decl( &function.sig );
|
|
140 |
+ (function.sig.ident.clone(), function.block, test_kind)
|
|
141 |
},
|
|
142 |
_ => panic!( "`#[async_test]` attached to an unsupported element!" )
|
|
143 |
};
|