Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions crates/oxc_minifier/src/peephole/remove_dead_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ impl<'a> PeepholeOptimizations {
self.try_fold_conditional_expression(e, state, ctx)
}
Expression::SequenceExpression(e) => self.try_fold_sequence_expression(e, state, ctx),
Expression::AssignmentExpression(_) => {
self.remove_unused_assignment_expression(expr, state, ctx);
None
}
_ => None,
} {
*expr = folded_expr;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use oxc_allocator::TakeIn;
use oxc_ast::ast::*;
use oxc_ecmascript::side_effects::MayHaveSideEffects;

use crate::{CompressOptionsUnused, ctx::Ctx};

Expand Down Expand Up @@ -79,13 +78,9 @@ impl<'a> PeepholeOptimizations {
if !ctx.scoping().get_resolved_references(symbol_id).all(|r| !r.flags().is_read()) {
return false;
}
*e = assign_expr.right.take_in(ctx.ast);
state.changed = true;
if assign_expr.right.may_have_side_effects(ctx) {
*e = assign_expr.right.take_in(ctx.ast);
false
} else {
true
}
false
}

/// Do remove top level vars in script mode.
Expand Down Expand Up @@ -132,7 +127,17 @@ mod test {
test_options("var x = 1; x = 2;", "", &options);
test_options("var x = 1; x = foo();", "foo()", &options);
test_same_options("var x = 1; x = 2, foo(x)", &options);
test_same_options("function foo() { var t; return t = x(); } foo();", &options);
test_same_options("function foo() { return t = x(); } foo();", &options);
test_options(
"function foo() { var t; return t = x(); } foo();",
"function foo() { return x(); } foo();",
&options,
);
test_options(
"function foo(t) { return t = x(); } foo();",
"function foo(t) { return x(); } foo();",
&options,
);
}

#[test]
Expand Down
8 changes: 4 additions & 4 deletions tasks/minsize/minsize.snap
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ Original | minified | minified | gzip | gzip | Fixture

544.10 kB | 71.38 kB | 72.48 kB | 25.85 kB | 26.20 kB | lodash.js

555.77 kB | 270.82 kB | 270.13 kB | 88.25 kB | 90.80 kB | d3.js
555.77 kB | 270.80 kB | 270.13 kB | 88.24 kB | 90.80 kB | d3.js

1.01 MB | 440.17 kB | 458.89 kB | 122.37 kB | 126.71 kB | bundle.min.js

1.25 MB | 647 kB | 646.76 kB | 160.28 kB | 163.73 kB | three.js

2.14 MB | 716.11 kB | 724.14 kB | 161.77 kB | 181.07 kB | victory.js
2.14 MB | 716.10 kB | 724.14 kB | 161.76 kB | 181.07 kB | victory.js

3.20 MB | 1.01 MB | 1.01 MB | 324.08 kB | 331.56 kB | echarts.js

6.69 MB | 2.25 MB | 2.31 MB | 463.06 kB | 488.28 kB | antd.js
6.69 MB | 2.24 MB | 2.31 MB | 462.45 kB | 488.28 kB | antd.js

10.95 MB | 3.35 MB | 3.49 MB | 860.92 kB | 915.50 kB | typescript.js
10.95 MB | 3.34 MB | 3.49 MB | 856.90 kB | 915.50 kB | typescript.js

Loading