@@ -158,6 +158,16 @@ impl BindgenAttrs {
158
158
} )
159
159
. next ( )
160
160
}
161
+
162
+ /// Return the list of classes that a type extends
163
+ fn extends ( & self ) -> impl Iterator < Item = & Ident > {
164
+ self . attrs
165
+ . iter ( )
166
+ . filter_map ( |a| match a {
167
+ BindgenAttr :: Extends ( s) => Some ( s) ,
168
+ _ => None ,
169
+ } )
170
+ }
161
171
}
162
172
163
173
impl syn:: synom:: Synom for BindgenAttrs {
@@ -190,6 +200,7 @@ pub enum BindgenAttr {
190
200
Readonly ,
191
201
JsName ( String ) ,
192
202
JsClass ( String ) ,
203
+ Extends ( Ident ) ,
193
204
}
194
205
195
206
impl syn:: synom:: Synom for BindgenAttr {
@@ -262,6 +273,13 @@ impl syn::synom::Synom for BindgenAttr {
262
273
s: syn!( syn:: LitStr ) >>
263
274
( s. value( ) )
264
275
) => { BindgenAttr :: JsClass }
276
+ |
277
+ do_parse!(
278
+ call!( term, "extends" ) >>
279
+ punct!( =) >>
280
+ ns: call!( term2ident) >>
281
+ ( ns)
282
+ ) => { BindgenAttr :: Extends }
265
283
) ) ;
266
284
}
267
285
@@ -478,17 +496,18 @@ impl<'a> ConvertToAst<(BindgenAttrs, &'a Option<String>)> for syn::ForeignItemFn
478
496
}
479
497
}
480
498
481
- impl ConvertToAst < ( ) > for syn:: ForeignItemType {
499
+ impl ConvertToAst < BindgenAttrs > for syn:: ForeignItemType {
482
500
type Target = ast:: ImportKind ;
483
501
484
- fn convert ( self , ( ) : ( ) ) -> Result < Self :: Target , Diagnostic > {
502
+ fn convert ( self , attrs : BindgenAttrs ) -> Result < Self :: Target , Diagnostic > {
485
503
let shim = format ! ( "__wbg_instanceof_{}_{}" , self . ident, ShortHash ( & self . ident) ) ;
486
504
Ok ( ast:: ImportKind :: Type ( ast:: ImportType {
487
505
vis : self . vis ,
488
506
attrs : self . attrs ,
489
507
doc_comment : None ,
490
508
instanceof_shim : shim,
491
509
name : self . ident ,
510
+ extends : attrs. extends ( ) . cloned ( ) . collect ( ) ,
492
511
} ) )
493
512
}
494
513
}
@@ -895,7 +914,7 @@ impl<'a> MacroParse<&'a BindgenAttrs> for syn::ForeignItem {
895
914
let js_namespace = item_opts. js_namespace ( ) . or ( opts. js_namespace ( ) ) . cloned ( ) ;
896
915
let kind = match self {
897
916
syn:: ForeignItem :: Fn ( f) => f. convert ( ( item_opts, & module) ) ?,
898
- syn:: ForeignItem :: Type ( t) => t. convert ( ( ) ) ?,
917
+ syn:: ForeignItem :: Type ( t) => t. convert ( item_opts ) ?,
899
918
syn:: ForeignItem :: Static ( s) => s. convert ( item_opts) ?,
900
919
_ => panic ! ( "only foreign functions/types allowed for now" ) ,
901
920
} ;
0 commit comments