From e89129f2cce1d7045b04d55c209af7bb2f7abb0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Wed, 21 Aug 2024 13:31:24 +0900 Subject: [PATCH] fix test --- .../src/pass/mangle_names/preserver.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/crates/swc_ecma_minifier/src/pass/mangle_names/preserver.rs b/crates/swc_ecma_minifier/src/pass/mangle_names/preserver.rs index 57232489c9ab..d68ab1602ba8 100644 --- a/crates/swc_ecma_minifier/src/pass/mangle_names/preserver.rs +++ b/crates/swc_ecma_minifier/src/pass/mangle_names/preserver.rs @@ -9,10 +9,10 @@ use crate::option::MangleOptions; /// Returns `(preserved, unresolved)` pub(crate) fn idents_to_preserve(options: MangleOptions, marks: Marks, n: &N) -> FxHashSet where - N: VisitWith, + N: for<'a> VisitWith>, { let mut v = Preserver { - options, + options: &options, preserved: Default::default(), should_preserve: false, in_top_level: false, @@ -23,13 +23,14 @@ where // 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.retain(|id| { + options.reserved.contains(&id.0) || id.1.outer().is_descendant_of(top_level_mark) + }); v.preserved } -pub(crate) struct Preserver { - options: MangleOptions, +pub(crate) struct Preserver<'a> { + options: &'a MangleOptions, preserved: FxHashSet, @@ -37,13 +38,13 @@ pub(crate) struct Preserver { in_top_level: bool, } -impl Preserver { +impl<'a> Preserver<'a> { fn is_reserved(&self, ident: &Ident) -> bool { self.options.reserved.contains(&ident.sym) } } -impl Visit for Preserver { +impl<'a> Visit for Preserver<'a> { noop_visit_type!(); fn visit_block_stmt(&mut self, n: &BlockStmt) {