mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-22 09:11:35 +00:00
web-sys: Don't remove dictionaries if required fields are removed
This commit updates the conditional binding generation for dictionaries to ensure that a dictionary is not entirely removed if any of its required fields are removed. If a required field is removed, however, it cannot be constructed, so the constructor is removed.
This commit is contained in:
@ -348,25 +348,20 @@ impl RemoveUndefinedImports for ast::Program {
|
||||
let mut changed = self.imports.remove_undefined_imports(is_defined);
|
||||
changed = self.consts.remove_undefined_imports(is_defined) || changed;
|
||||
|
||||
let mut dictionaries_to_remove = Vec::new();
|
||||
for (i, dictionary) in self.dictionaries.iter_mut().enumerate() {
|
||||
for dictionary in self.dictionaries.iter_mut() {
|
||||
let num_required =
|
||||
|dict: &ast::Dictionary| dict.fields.iter().filter(|f| f.required).count();
|
||||
let before = num_required(dictionary);
|
||||
changed = dictionary.fields.remove_undefined_imports(is_defined) || changed;
|
||||
|
||||
// If a required field was removed we can no longer construct this
|
||||
// dictionary so disable the constructor.
|
||||
if before != num_required(dictionary) {
|
||||
log::warn!(
|
||||
"removing {} due to a required field being removed",
|
||||
dictionary.name
|
||||
);
|
||||
dictionaries_to_remove.push(i);
|
||||
dictionary.ctor = false;
|
||||
}
|
||||
}
|
||||
for i in dictionaries_to_remove.iter().rev() {
|
||||
self.dictionaries.swap_remove(*i);
|
||||
}
|
||||
|
||||
changed || dictionaries_to_remove.len() > 0
|
||||
changed
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user