diff --git a/crates/swc_ecma_minifier/scripts/test.sh b/crates/swc_ecma_minifier/scripts/test.sh index e571dce1a494..7286403638e4 100755 --- a/crates/swc_ecma_minifier/scripts/test.sh +++ b/crates/swc_ecma_minifier/scripts/test.sh @@ -6,6 +6,8 @@ export UPDATE=1 export SWC_CHECK=0 export SWC_RUN=0 +touch tests/compress.rs + cargo test -q -p swc_ecma_minifier -p swc --no-fail-fast --test projects --test tsc --test compress --test mangle --features concurrent $@ # find ../swc/tests/ -type f -empty -delete \ No newline at end of file diff --git a/crates/swc_ecma_minifier/src/lib.rs b/crates/swc_ecma_minifier/src/lib.rs index 999b22e9db4a..427192037f8f 100644 --- a/crates/swc_ecma_minifier/src/lib.rs +++ b/crates/swc_ecma_minifier/src/lib.rs @@ -38,12 +38,7 @@ #![allow(clippy::match_like_matches_macro)] use once_cell::sync::Lazy; -use swc_common::{ - comments::Comments, - pass::{Repeat, Repeated}, - sync::Lrc, - SourceMap, SyntaxContext, -}; +use swc_common::{comments::Comments, pass::Repeated, sync::Lrc, SourceMap, SyntaxContext}; use swc_ecma_ast::*; use swc_ecma_transforms_optimization::debug_assert_valid; use swc_ecma_visit::VisitMutWith; @@ -230,17 +225,27 @@ pub fn optimize( let _timer = timer!("postcompress"); m.visit_mut_with(&mut postcompress_optimizer(options)); - m.visit_mut_with(&mut Repeat::new(pure_optimizer( - options, - None, - marks, - PureOptimizerConfig { - force_str_for_tpl: Minification::force_str_for_tpl(), - enable_join_vars: true, - #[cfg(feature = "debug")] - debug_infinite_loop: false, - }, - ))); + + let mut pass = 0; + loop { + pass += 1; + + let mut v = pure_optimizer( + options, + None, + marks, + PureOptimizerConfig { + force_str_for_tpl: Minification::force_str_for_tpl(), + enable_join_vars: true, + #[cfg(feature = "debug")] + debug_infinite_loop: false, + }, + ); + m.visit_mut_with(&mut v); + if !v.changed() || options.passes <= pass { + break; + } + } } if let Some(ref mut _t) = timings { diff --git a/crates/swc_ecma_minifier/tests/projects/output/jquery-1.9.1.js b/crates/swc_ecma_minifier/tests/projects/output/jquery-1.9.1.js index 6c6693138d3b..7864568630d6 100644 --- a/crates/swc_ecma_minifier/tests/projects/output/jquery-1.9.1.js +++ b/crates/swc_ecma_minifier/tests/projects/output/jquery-1.9.1.js @@ -440,7 +440,7 @@ } } function internalRemoveData(elem, name1, pvt) { - if (jQuery.acceptData(elem)) { + if (!!jQuery.acceptData(elem)) { var i, l, thisCache, isNode = elem.nodeType, cache = isNode ? jQuery.cache : elem, id = isNode ? elem[jQuery.expando] : jQuery.expando; if (cache[id]) { if (name1 && (thisCache = pvt ? cache[id] : cache[id].data)) {