From ba4b68cf638c406388766afebaaa440a92327dd0 Mon Sep 17 00:00:00 2001 From: Boshen <1430279+Boshen@users.noreply.github.com> Date: Wed, 4 Sep 2024 12:58:39 +0000 Subject: [PATCH] feat(minifier): remove parenthesized expression for dce (#5439) relates #5436 --- crates/oxc_minifier/src/options.rs | 7 ++++++- crates/oxc_minifier/tests/ast_passes/remove_dead_code.rs | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/crates/oxc_minifier/src/options.rs b/crates/oxc_minifier/src/options.rs index 30d88d41956ea..927d80ef83ada 100644 --- a/crates/oxc_minifier/src/options.rs +++ b/crates/oxc_minifier/src/options.rs @@ -93,6 +93,11 @@ impl CompressOptions { } pub fn dead_code_elimination() -> Self { - Self { fold_constants: true, remove_dead_code: true, ..Self::all_false() } + Self { + remove_syntax: true, + fold_constants: true, + remove_dead_code: true, + ..Self::all_false() + } } } diff --git a/crates/oxc_minifier/tests/ast_passes/remove_dead_code.rs b/crates/oxc_minifier/tests/ast_passes/remove_dead_code.rs index b0e8a3fe6bb7e..c5cacf8edbc8d 100644 --- a/crates/oxc_minifier/tests/ast_passes/remove_dead_code.rs +++ b/crates/oxc_minifier/tests/ast_passes/remove_dead_code.rs @@ -78,6 +78,9 @@ fn dce_if_statement() { "const a = { fn: function() { if (true) { foo; } } }", "const a = { fn: function() { { foo; } } }", ); + + // parenthesized + test("if (!!(false)) { REMOVE; } else { KEEP; }", "{ KEEP }"); } #[test]