Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(es/minifier): Force rename synthesized identifiers #9473

Merged
merged 7 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix
  • Loading branch information
kdy1 committed Aug 21, 2024
commit 5e4fae2f9a06d9c04ad55e86d7746392302fa930
2 changes: 1 addition & 1 deletion crates/swc_ecma_minifier/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ pub fn optimize(
let _timer = timer!("mangle names");
// TODO: base54.reset();

let preserved = idents_to_preserve(mangle.clone(), &n);
let preserved = idents_to_preserve(mangle.clone(), marks, &n);

let chars = CharFreq::compute(
&n,
Expand Down
11 changes: 10 additions & 1 deletion crates/swc_ecma_minifier/src/pass/mangle_names/preserver.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use rustc_hash::FxHashSet;
use swc_ecma_ast::*;
use swc_ecma_usage_analyzer::marks::Marks;
use swc_ecma_utils::find_pat_ids;
use swc_ecma_visit::{noop_visit_type, Visit, VisitWith};

use crate::option::MangleOptions;

/// Returns `(preserved, unresolved)`
pub(crate) fn idents_to_preserve<N>(options: MangleOptions, n: &N) -> FxHashSet<Id>
pub(crate) fn idents_to_preserve<N>(options: MangleOptions, marks: Marks, n: &N) -> FxHashSet<Id>
where
N: VisitWith<Preserver>,
{
Expand All @@ -17,6 +18,14 @@ where
in_top_level: false,
};
n.visit_with(&mut v);

let top_level_mark = marks.top_level_ctxt.outer();

// Force rename synthesized names
// See https://github.com/swc-project/swc/issues/9468
v.preserved
.retain(|id| id.1.outer().is_descendant_of(top_level_mark));

v.preserved
}
pub(crate) struct Preserver {
Expand Down