From 18a58d472bb90b077f70d73f9c4f1e24f67e4529 Mon Sep 17 00:00:00 2001 From: Bradley Farias Date: Tue, 16 Jan 2024 21:22:02 -0600 Subject: [PATCH] feat(minifier): handle more expressions for side effects (#2062) Eventually these should return effects rather than a bool since some can be moved around and ignored. For now, keep it similar to previous code. --- crates/oxc_minifier/src/compressor/ast_util.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/crates/oxc_minifier/src/compressor/ast_util.rs b/crates/oxc_minifier/src/compressor/ast_util.rs index 53e4b5324..c51b08701 100644 --- a/crates/oxc_minifier/src/compressor/ast_util.rs +++ b/crates/oxc_minifier/src/compressor/ast_util.rs @@ -113,6 +113,9 @@ impl<'a, 'b> CheckForStateChange<'a, 'b> for Expression<'a> { | Self::BigintLiteral(_) | Self::NullLiteral(_) | Self::RegExpLiteral(_) + | Self::MetaProperty(_) + | Self::ThisExpression(_) + | Self::ClassExpression(_) | Self::FunctionExpression(_) => false, Self::TemplateLiteral(template) => template .expressions @@ -122,6 +125,17 @@ impl<'a, 'b> CheckForStateChange<'a, 'b> for Expression<'a> { Self::UnaryExpression(unary_expr) => { unary_expr.check_for_state_change(check_for_new_objects) } + Self::ParenthesizedExpression(p) => { + p.expression.check_for_state_change(check_for_new_objects) + } + Self::ConditionalExpression(p) => { + p.test.check_for_state_change(check_for_new_objects) + || p.consequent.check_for_state_change(check_for_new_objects) + || p.alternate.check_for_state_change(check_for_new_objects) + } + Self::SequenceExpression(s) => { + s.expressions.iter().any(|expr| expr.check_for_state_change(check_for_new_objects)) + } Self::BinaryExpression(binary_expr) => { binary_expr.check_for_state_change(check_for_new_objects) }