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.
This commit is contained in:
Bradley Farias 2024-01-16 21:22:02 -06:00 committed by GitHub
parent 3faa2aa2a8
commit 18a58d472b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -113,6 +113,9 @@ impl<'a, 'b> CheckForStateChange<'a, 'b> for Expression<'a> {
| Self::BigintLiteral(_) | Self::BigintLiteral(_)
| Self::NullLiteral(_) | Self::NullLiteral(_)
| Self::RegExpLiteral(_) | Self::RegExpLiteral(_)
| Self::MetaProperty(_)
| Self::ThisExpression(_)
| Self::ClassExpression(_)
| Self::FunctionExpression(_) => false, | Self::FunctionExpression(_) => false,
Self::TemplateLiteral(template) => template Self::TemplateLiteral(template) => template
.expressions .expressions
@ -122,6 +125,17 @@ impl<'a, 'b> CheckForStateChange<'a, 'b> for Expression<'a> {
Self::UnaryExpression(unary_expr) => { Self::UnaryExpression(unary_expr) => {
unary_expr.check_for_state_change(check_for_new_objects) 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) => { Self::BinaryExpression(binary_expr) => {
binary_expr.check_for_state_change(check_for_new_objects) binary_expr.check_for_state_change(check_for_new_objects)
} }