Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions crates/oxc_mangler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ impl ManglerBuilder {

if !bindings.is_empty() {
// `bindings` are stored in order, traverse and increment slot
for symbol_id in bindings.values() {
slots[*symbol_id] = slot;
for symbol_id in bindings.values().copied() {
slots[symbol_id] = slot;
slot += 1;
}
}
Expand All @@ -121,9 +121,6 @@ impl ManglerBuilder {
let frequencies =
Self::tally_slot_frequencies(&symbol_table, total_number_of_slots, &slots);

let unresolved_references =
scope_tree.root_unresolved_references().keys().collect::<Vec<_>>();

let mut names = Vec::with_capacity(total_number_of_slots);

let generate_name = if self.debug { debug_name } else { base54 };
Expand All @@ -133,7 +130,9 @@ impl ManglerBuilder {
let name = generate_name(count);
count += 1;
// Do not mangle keywords and unresolved references
if !is_keyword(&name) && !unresolved_references.iter().any(|n| **n == name) {
if !is_keyword(&name)
&& !scope_tree.root_unresolved_references().contains_key(name.as_str())
{
break name;
}
});
Expand Down Expand Up @@ -169,7 +168,7 @@ impl ManglerBuilder {
// sorting by slot enables us to sort by the order at which the vars first appear in the source
// (this is possible because the slots are discovered currently in a DFS method which is the same order
// as variables appear in the source code)
symbols_renamed_in_this_batch.sort_by(|a, b| a.slot.cmp(&b.slot.clone()));
symbols_renamed_in_this_batch.sort_by(|a, b| a.slot.cmp(&b.slot));

// here we just zip the iterator of symbols to rename with the iterator of new names for the next for loop
let symbols_to_rename_with_new_names =
Expand Down