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

feat(es/minifier): Respect more options #8582

Merged
merged 32 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
b09220a
Enable test
kdy1 Feb 1, 2024
30e1a21
Respect option
kdy1 Feb 1, 2024
605873d
Respect option
kdy1 Feb 1, 2024
def61f5
Update test refs (verified)
kdy1 Feb 1, 2024
4c906c8
Update test refs (verified)
kdy1 Feb 1, 2024
6c474eb
Update test refs (verified)
kdy1 Feb 1, 2024
2438e42
Update the list
kdy1 Feb 1, 2024
a4ce877
Enable
kdy1 Feb 1, 2024
5041fd8
reduce_vars must enable seq inliner
kdy1 Feb 1, 2024
e863ccf
top_retain is now respected by seq inliner
kdy1 Feb 1, 2024
b5750e7
arguments is now ignored by seq inliner
kdy1 Feb 1, 2024
0f2b7de
Update test refs (verified)
kdy1 Feb 1, 2024
3e99208
top-level check
kdy1 Feb 1, 2024
053ab95
Update test refs (verified)
kdy1 Feb 1, 2024
387d8e4
fixup for top-level check
kdy1 Feb 1, 2024
d89aece
Revert test refs
kdy1 Feb 1, 2024
628e1c7
Revert test refs
kdy1 Feb 1, 2024
6daf545
Respect options in seq inliner via seq_exprs_of
kdy1 Feb 1, 2024
25f2cce
Revert test refs
kdy1 Feb 1, 2024
7bcc6db
Update test refs (likely revert)
kdy1 Feb 1, 2024
c1b4ea0
Fix context of function
kdy1 Feb 1, 2024
60bf1f4
Revert test refs
kdy1 Feb 1, 2024
4ab9ac3
seq option
kdy1 Feb 1, 2024
8ea4f7a
Update test refs (verified)
kdy1 Feb 1, 2024
451c2c4
Enable more tests
kdy1 Feb 1, 2024
4b10b35
Update test refs (better than terser)
kdy1 Feb 1, 2024
b80a7bb
Update test refs (verified)
kdy1 Feb 1, 2024
f4b743d
fixup for rebase
kdy1 Feb 2, 2024
c46ec43
Update the list
kdy1 Feb 2, 2024
e094f8b
Make top_retain correct
kdy1 Feb 2, 2024
f3550f1
fix
Austaras Feb 2, 2024
5bb6e5b
Merge branch 'main' into comp-rate-2
kdy1 Feb 2, 2024
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
4 changes: 3 additions & 1 deletion crates/swc_ecma_minifier/src/compress/optimize/iife.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,9 @@ impl Optimizer<'_> {
pub(super) fn invoke_iife(&mut self, e: &mut Expr) {
trace_op!("iife: invoke_iife");

if self.options.inline == 0 {
if self.options.inline == 0
&& !(self.options.reduce_vars && self.options.reduce_fns && self.options.evaluate)
{
let skip = match e {
Expr::Call(v) => !v.callee.span().is_dummy(),
_ => true,
Expand Down
10 changes: 9 additions & 1 deletion crates/swc_ecma_minifier/src/compress/optimize/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2041,6 +2041,7 @@ impl VisitMut for Optimizer<'_> {

let ctx = Ctx {
top_level: false,
in_fn_like: true,
is_lhs_of_assign: false,
is_exact_lhs_of_assign: false,
..self.ctx
Expand All @@ -2062,7 +2063,14 @@ impl VisitMut for Optimizer<'_> {
}
}

e.visit_mut_children_with(self);
let ctx = Ctx {
top_level: false,
in_fn_like: true,
is_lhs_of_assign: false,
is_exact_lhs_of_assign: false,
..self.ctx
};
e.visit_mut_children_with(&mut *self.with_ctx(ctx));
}

#[cfg_attr(feature = "debug", tracing::instrument(skip_all))]
Expand Down
24 changes: 22 additions & 2 deletions crates/swc_ecma_minifier/src/compress/optimize/sequences.rs
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,16 @@ impl Optimizer<'_> {
options: &CompressOptions,
) -> Option<Vec<Mergable<'a>>> {
Some(match s {
Stmt::Expr(e) => vec![Mergable::Expr(&mut e.expr)],
Stmt::Expr(e) => {
if self.options.sequences()
|| self.options.collapse_vars
|| self.options.side_effects
{
vec![Mergable::Expr(&mut e.expr)]
} else {
return None;
}
}
Stmt::Decl(Decl::Var(v)) => {
if options.reduce_vars || options.collapse_vars {
v.decls.iter_mut().map(Mergable::Var).collect()
Expand Down Expand Up @@ -612,7 +621,7 @@ impl Optimizer<'_> {
where
T: ModuleItemExt,
{
if !self.options.sequences() && !self.options.collapse_vars {
if !self.options.sequences() && !self.options.collapse_vars && !self.options.reduce_vars {
log_abort!("sequences: [x] Disabled");
return;
}
Expand Down Expand Up @@ -1513,6 +1522,17 @@ impl Optimizer<'_> {
)
};

// Respect top_retain
if let Some(a_id) = a.id() {
if a_id.0 == "arguments"
|| (self.ctx.in_top_level()
&& a_id.1 == self.marks.top_level_ctxt
&& self.options.top_retain.contains(&a_id.0))
{
return Ok(false);
}
}

if match &*b {
Expr::Arrow(..)
| Expr::Fn(..)
Expand Down
10 changes: 0 additions & 10 deletions crates/swc_ecma_minifier/tests/TODO.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ collapse_vars/issue_1858/input.js
collapse_vars/issue_2187_2/input.js
collapse_vars/issue_2203_2/input.js
collapse_vars/issue_2203_4/input.js
collapse_vars/issue_2298/input.js
collapse_vars/issue_2319_1/input.js
collapse_vars/issue_2319_3/input.js
collapse_vars/issue_2436_1/input.js
Expand Down Expand Up @@ -119,11 +118,8 @@ drop_unused/issue_2660_2/input.js
drop_unused/issue_2665/input.js
drop_unused/issue_2846/input.js
drop_unused/issue_t161_top_retain_10/input.js
drop_unused/issue_t161_top_retain_11/input.js
drop_unused/issue_t161_top_retain_12/input.js
drop_unused/issue_t161_top_retain_15/input.js
drop_unused/issue_t161_top_retain_8/input.js
drop_unused/issue_t161_top_retain_9/input.js
drop_unused/issue_t183/input.js
drop_unused/keep_assign/input.js
drop_unused/reassign_const/input.js
Expand Down Expand Up @@ -159,7 +155,6 @@ functions/issue_2107/input.js
functions/issue_2114_1/input.js
functions/issue_2114_2/input.js
functions/issue_2601_2/input.js
functions/issue_2604_2/input.js
functions/issue_2620_2/input.js
functions/issue_2620_3/input.js
functions/issue_2630_2/input.js
Expand Down Expand Up @@ -297,13 +292,8 @@ reduce_vars/iife/input.js
reduce_vars/iife_new/input.js
reduce_vars/inner_var_for_2/input.js
reduce_vars/inverted_var/input.js
reduce_vars/issue_1595_3/input.js
reduce_vars/issue_1670_2/input.js
reduce_vars/issue_1670_4/input.js
reduce_vars/issue_1670_5/input.js
reduce_vars/issue_1850_2/input.js
reduce_vars/issue_2485/input.js
reduce_vars/issue_2757_1/input.js
reduce_vars/issue_2799_2/input.js
reduce_vars/issue_2836/input.js
reduce_vars/issue_2860_2/input.js
Expand Down
Loading
Loading