Skip to content

Commit 73a4781

Browse files
committed
refactor(mangler): simplify keep-name collection (#27833)
Inline keep-name collection, remove the collector's allocator state, and simplify recursive default-pattern searches while preserving which function and class names are kept.
1 parent 5c52975 commit 73a4781

1 file changed

Lines changed: 7 additions & 17 deletions

File tree

‎crates/oxc_mangler/src/keep_names.rs‎

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -172,27 +172,17 @@ impl<'a, 'b: 'a, 't> NameSymbolCollector<'a, 'b, 't> {
172172
match kind {
173173
BindingPattern::BindingIdentifier(_) => None,
174174
BindingPattern::ObjectPattern(object_pattern) => {
175-
for property in &object_pattern.properties {
176-
if let Some(value) = Self::find_assign_binding_pattern_kind_of_specific_symbol(
175+
object_pattern.properties.iter().find_map(|property| {
176+
Self::find_assign_binding_pattern_kind_of_specific_symbol(
177177
&property.value,
178178
symbol_id,
179-
) {
180-
return Some(value);
181-
}
182-
}
183-
None
179+
)
180+
})
184181
}
185182
BindingPattern::ArrayPattern(array_pattern) => {
186-
for element in &array_pattern.elements {
187-
let Some(binding) = element else { continue };
188-
189-
if let Some(value) = Self::find_assign_binding_pattern_kind_of_specific_symbol(
190-
binding, symbol_id,
191-
) {
192-
return Some(value);
193-
}
194-
}
195-
None
183+
array_pattern.elements.iter().flatten().find_map(|binding| {
184+
Self::find_assign_binding_pattern_kind_of_specific_symbol(binding, symbol_id)
185+
})
196186
}
197187
BindingPattern::AssignmentPattern(assign_pattern) => {
198188
if Self::is_binding_id_of_specific_symbol(&assign_pattern.left, symbol_id) {

0 commit comments

Comments
 (0)