File tree Expand file tree Collapse file tree 4 files changed +22
-17
lines changed Expand file tree Collapse file tree 4 files changed +22
-17
lines changed Original file line number Diff line number Diff line change @@ -292,6 +292,7 @@ pub enum ConstValue {
292
292
pub struct Dictionary {
293
293
pub name : Ident ,
294
294
pub fields : Vec < DictionaryField > ,
295
+ pub ctor : bool ,
295
296
}
296
297
297
298
#[ cfg_attr( feature = "extra-traits" , derive( Debug , PartialEq , Eq ) ) ]
Original file line number Diff line number Diff line change @@ -1282,6 +1282,18 @@ impl ToTokens for ast::Dictionary {
1282
1282
let required_names2 = required_names;
1283
1283
let required_names3 = required_names;
1284
1284
1285
+ let ctor = if self . ctor {
1286
+ quote ! {
1287
+ pub fn new( #( #required_names: #required_types) , * ) -> #name {
1288
+ let mut _ret = #name { obj: :: js_sys:: Object :: new( ) } ;
1289
+ #( _ret. #required_names2( #required_names3) ; ) *
1290
+ return _ret
1291
+ }
1292
+ }
1293
+ } else {
1294
+ quote ! { }
1295
+ } ;
1296
+
1285
1297
let const_name = Ident :: new ( & format ! ( "_CONST_{}" , name) , Span :: call_site ( ) ) ;
1286
1298
( quote ! {
1287
1299
#[ derive( Clone , Debug ) ]
@@ -1293,12 +1305,7 @@ impl ToTokens for ast::Dictionary {
1293
1305
1294
1306
#[ allow( clippy:: all) ]
1295
1307
impl #name {
1296
- pub fn new( #( #required_names: #required_types) , * ) -> #name {
1297
- let mut _ret = #name { obj: :: js_sys:: Object :: new( ) } ;
1298
- #( _ret. #required_names2( #required_names3) ; ) *
1299
- return _ret
1300
- }
1301
-
1308
+ #ctor
1302
1309
#methods
1303
1310
}
1304
1311
Original file line number Diff line number Diff line change @@ -348,25 +348,20 @@ impl RemoveUndefinedImports for ast::Program {
348
348
let mut changed = self . imports . remove_undefined_imports ( is_defined) ;
349
349
changed = self . consts . remove_undefined_imports ( is_defined) || changed;
350
350
351
- let mut dictionaries_to_remove = Vec :: new ( ) ;
352
- for ( i, dictionary) in self . dictionaries . iter_mut ( ) . enumerate ( ) {
351
+ for dictionary in self . dictionaries . iter_mut ( ) {
353
352
let num_required =
354
353
|dict : & ast:: Dictionary | dict. fields . iter ( ) . filter ( |f| f. required ) . count ( ) ;
355
354
let before = num_required ( dictionary) ;
356
355
changed = dictionary. fields . remove_undefined_imports ( is_defined) || changed;
356
+
357
+ // If a required field was removed we can no longer construct this
358
+ // dictionary so disable the constructor.
357
359
if before != num_required ( dictionary) {
358
- log:: warn!(
359
- "removing {} due to a required field being removed" ,
360
- dictionary. name
361
- ) ;
362
- dictionaries_to_remove. push ( i) ;
360
+ dictionary. ctor = false ;
363
361
}
364
362
}
365
- for i in dictionaries_to_remove. iter ( ) . rev ( ) {
366
- self . dictionaries . swap_remove ( * i) ;
367
- }
368
363
369
- changed || dictionaries_to_remove . len ( ) > 0
364
+ changed
370
365
}
371
366
}
372
367
Original file line number Diff line number Diff line change @@ -317,6 +317,7 @@ impl<'src> FirstPassRecord<'src> {
317
317
program. dictionaries . push ( ast:: Dictionary {
318
318
name : rust_ident ( & camel_case_ident ( def. identifier . 0 ) ) ,
319
319
fields,
320
+ ctor : true ,
320
321
} ) ;
321
322
}
322
323
@@ -784,6 +785,7 @@ impl<'src> FirstPassRecord<'src> {
784
785
program. dictionaries . push ( ast:: Dictionary {
785
786
name : rust_ident ( & camel_case_ident ( item. definition . identifier . 0 ) ) ,
786
787
fields,
788
+ ctor : true ,
787
789
} ) ;
788
790
}
789
791
}
You can’t perform that action at this time.
0 commit comments