diff --git a/crates/oxc_mangler/src/lib.rs b/crates/oxc_mangler/src/lib.rs index f8e2f9f1e52db..802e63173fbe1 100644 --- a/crates/oxc_mangler/src/lib.rs +++ b/crates/oxc_mangler/src/lib.rs @@ -436,6 +436,19 @@ impl<'t> Mangler<'t> { let root_unresolved_references = scoping.root_unresolved_references(); let root_bindings = scoping.get_bindings(scoping.root_scope_id()); + let mut excluded_names: FxHashSet<&str> = FxHashSet::with_capacity_and_hasher( + root_unresolved_references.len() + keep_name_names.len() + root_bindings.len(), + rustc_hash::FxBuildHasher, + ); + excluded_names.extend(root_unresolved_references.keys()); + excluded_names.extend(keep_name_names.iter().copied()); + if self.options.top_level { + excluded_names + .extend(root_bindings.keys().filter(|&name| exported_names.contains::(name))); + } else { + excluded_names.extend(root_bindings.keys()); + } + let mut reserved_names = Vec::with_capacity_in(total_number_of_slots, temp_allocator); let mut count = 0; @@ -447,11 +460,7 @@ impl<'t> Mangler<'t> { let n = name.as_str(); if !oxc_syntax::keyword::is_reserved_keyword(n) && !is_special_name(n) - && !root_unresolved_references.contains_key(n) - && !(root_bindings.contains_key(n) - && (!self.options.top_level || exported_names.contains(n))) - // TODO: only skip the names that are kept in the current scope - && !keep_name_names.contains(n) + && !excluded_names.contains(n) { break name; } diff --git a/tasks/track_memory_allocations/allocs_minifier.snap b/tasks/track_memory_allocations/allocs_minifier.snap index 94eca5ee1ee0f..d7f57d6cc8e19 100644 --- a/tasks/track_memory_allocations/allocs_minifier.snap +++ b/tasks/track_memory_allocations/allocs_minifier.snap @@ -1,14 +1,14 @@ File | File size || Sys allocs | Sys reallocs || Arena allocs | Arena reallocs | Arena bytes ------------------------------------------------------------------------------------------------------------------------------------------- -checker.ts | 2.92 MB || 83502 | 14179 || 152592 | 28237 +checker.ts | 2.92 MB || 83503 | 14179 || 152592 | 28237 -cal.com.tsx | 1.06 MB || 40447 | 3032 || 37138 | 4586 +cal.com.tsx | 1.06 MB || 40448 | 3032 || 37138 | 4586 -RadixUIAdoptionSection.jsx | 2.52 kB || 85 | 9 || 30 | 6 +RadixUIAdoptionSection.jsx | 2.52 kB || 86 | 9 || 30 | 6 -pdf.mjs | 567.30 kB || 20193 | 2899 || 47453 | 7730 +pdf.mjs | 567.30 kB || 20194 | 2899 || 47453 | 7730 -antd.js | 6.69 MB || 99534 | 13524 || 331649 | 69358 +antd.js | 6.69 MB || 99535 | 13524 || 331649 | 69358 -binder.ts | 193.08 kB || 4759 | 974 || 7075 | 824 +binder.ts | 193.08 kB || 4760 | 974 || 7075 | 824