@@ -125,7 +125,7 @@ fn shared_program<'a>(
125
125
. exports
126
126
. iter ( )
127
127
. map ( |a| shared_export ( a, intern) )
128
- . collect ( ) ,
128
+ . collect :: < Result < Vec < _ > , _ > > ( ) ? ,
129
129
structs : prog
130
130
. structs
131
131
. iter ( )
@@ -172,21 +172,23 @@ fn shared_program<'a>(
172
172
} )
173
173
}
174
174
175
- fn shared_export < ' a > ( export : & ' a ast:: Export , intern : & ' a Interner ) -> Export < ' a > {
176
- let ( method, consumed) = match export. method_self {
177
- Some ( ast:: MethodSelf :: ByValue ) => ( true , true ) ,
178
- Some ( _) => ( true , false ) ,
179
- None => ( false , false ) ,
175
+ fn shared_export < ' a > (
176
+ export : & ' a ast:: Export ,
177
+ intern : & ' a Interner ,
178
+ ) -> Result < Export < ' a > , Diagnostic > {
179
+ let consumed = match export. method_self {
180
+ Some ( ast:: MethodSelf :: ByValue ) => true ,
181
+ _ => false ,
180
182
} ;
181
- Export {
183
+ let method_kind = from_ast_method_kind ( & export. function , intern, & export. method_kind ) ?;
184
+ Ok ( Export {
182
185
class : export. js_class . as_ref ( ) . map ( |s| & * * s) ,
183
- method ,
186
+ comments : export . comments . iter ( ) . map ( |s| & * * s ) . collect ( ) ,
184
187
consumed,
185
- is_constructor : export. is_constructor ,
186
188
function : shared_function ( & export. function , intern) ,
187
- comments : export . comments . iter ( ) . map ( |s| & * * s ) . collect ( ) ,
189
+ method_kind ,
188
190
start : export. start ,
189
- }
191
+ } )
190
192
}
191
193
192
194
fn shared_function < ' a > ( func : & ' a ast:: Function , _intern : & ' a Interner ) -> Function < ' a > {
@@ -203,8 +205,8 @@ fn shared_function<'a>(func: &'a ast::Function, _intern: &'a Interner) -> Functi
203
205
} )
204
206
. collect :: < Vec < _ > > ( ) ;
205
207
Function {
206
- name : & func. name ,
207
208
arg_names,
209
+ name : & func. name ,
208
210
}
209
211
}
210
212
@@ -260,30 +262,7 @@ fn shared_import_function<'a>(
260
262
) -> Result < ImportFunction < ' a > , Diagnostic > {
261
263
let method = match & i. kind {
262
264
ast:: ImportFunctionKind :: Method { class, kind, .. } => {
263
- let kind = match kind {
264
- ast:: MethodKind :: Constructor => MethodKind :: Constructor ,
265
- ast:: MethodKind :: Operation ( ast:: Operation { is_static, kind } ) => {
266
- let is_static = * is_static;
267
- let kind = match kind {
268
- ast:: OperationKind :: Regular => OperationKind :: Regular ,
269
- ast:: OperationKind :: Getter ( g) => {
270
- let g = g. as_ref ( ) . map ( |g| intern. intern ( g) ) ;
271
- OperationKind :: Getter ( g. unwrap_or_else ( || i. infer_getter_property ( ) ) )
272
- }
273
- ast:: OperationKind :: Setter ( s) => {
274
- let s = s. as_ref ( ) . map ( |s| intern. intern ( s) ) ;
275
- OperationKind :: Setter ( match s {
276
- Some ( s) => s,
277
- None => intern. intern_str ( & i. infer_setter_property ( ) ?) ,
278
- } )
279
- }
280
- ast:: OperationKind :: IndexingGetter => OperationKind :: IndexingGetter ,
281
- ast:: OperationKind :: IndexingSetter => OperationKind :: IndexingSetter ,
282
- ast:: OperationKind :: IndexingDeleter => OperationKind :: IndexingDeleter ,
283
- } ;
284
- MethodKind :: Operation ( Operation { is_static, kind } )
285
- }
286
- } ;
265
+ let kind = from_ast_method_kind ( & i. function , intern, kind) ?;
287
266
Some ( MethodData { class, kind } )
288
267
}
289
268
ast:: ImportFunctionKind :: Normal => None ,
@@ -510,3 +489,34 @@ macro_rules! encode_api {
510
489
) ;
511
490
}
512
491
wasm_bindgen_shared:: shared_api!( encode_api) ;
492
+
493
+ fn from_ast_method_kind < ' a > (
494
+ function : & ' a ast:: Function ,
495
+ intern : & ' a Interner ,
496
+ method_kind : & ' a ast:: MethodKind ,
497
+ ) -> Result < MethodKind < ' a > , Diagnostic > {
498
+ Ok ( match method_kind {
499
+ ast:: MethodKind :: Constructor => MethodKind :: Constructor ,
500
+ ast:: MethodKind :: Operation ( ast:: Operation { is_static, kind } ) => {
501
+ let is_static = * is_static;
502
+ let kind = match kind {
503
+ ast:: OperationKind :: Getter ( g) => {
504
+ let g = g. as_ref ( ) . map ( |g| intern. intern ( g) ) ;
505
+ OperationKind :: Getter ( g. unwrap_or_else ( || function. infer_getter_property ( ) ) )
506
+ }
507
+ ast:: OperationKind :: Regular => OperationKind :: Regular ,
508
+ ast:: OperationKind :: Setter ( s) => {
509
+ let s = s. as_ref ( ) . map ( |s| intern. intern ( s) ) ;
510
+ OperationKind :: Setter ( match s {
511
+ Some ( s) => s,
512
+ None => intern. intern_str ( & function. infer_setter_property ( ) ?) ,
513
+ } )
514
+ }
515
+ ast:: OperationKind :: IndexingGetter => OperationKind :: IndexingGetter ,
516
+ ast:: OperationKind :: IndexingSetter => OperationKind :: IndexingSetter ,
517
+ ast:: OperationKind :: IndexingDeleter => OperationKind :: IndexingDeleter ,
518
+ } ;
519
+ MethodKind :: Operation ( Operation { is_static, kind } )
520
+ }
521
+ } )
522
+ }
0 commit comments