1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use swc_ecma_ast::BinaryOp;

pub trait BinaryOpExtensions {
    fn is_add_sub(&self) -> bool;
    fn is_mul_div(&self) -> bool;
    fn is_bitwise_or_arithmetic(&self) -> bool;
    fn is_logical(&self) -> bool;
    fn is_bit_logical(&self) -> bool;
    fn is_bit_shift(&self) -> bool;
    fn is_equality(&self) -> bool;
}

impl BinaryOpExtensions for BinaryOp {
    fn is_add_sub(&self) -> bool {
        match self {
            BinaryOp::Add | BinaryOp::Sub => true,
            _ => false,
        }
    }

    fn is_mul_div(&self) -> bool {
        match self {
            BinaryOp::Mul | BinaryOp::Div => true,
            _ => false,
        }
    }

    fn is_bitwise_or_arithmetic(&self) -> bool {
        match self {
            BinaryOp::LShift | BinaryOp::RShift | BinaryOp::ZeroFillRShift | BinaryOp::Add | BinaryOp::Sub | BinaryOp::Mul
                | BinaryOp::Div | BinaryOp::Mod | BinaryOp::BitOr | BinaryOp::BitXor
                | BinaryOp::BitAnd => true,
            _ => false,
        }
    }

    fn is_logical(&self) -> bool {
        match self {
            BinaryOp::LogicalAnd | BinaryOp::LogicalOr => true,
            _ => false,
        }
    }

    fn is_bit_logical(&self) -> bool {
        match self {
            BinaryOp::BitOr | BinaryOp::BitAnd | BinaryOp::BitXor => true,
            _ => false,
        }
    }

    fn is_bit_shift(&self) -> bool {
        match self {
            BinaryOp::LShift | BinaryOp::RShift | BinaryOp::ZeroFillRShift => true,
            _ => false,
        }
    }

    fn is_equality(&self) -> bool {
        match self {
            BinaryOp::EqEq | BinaryOp::NotEq | BinaryOp::EqEqEq | BinaryOp::NotEqEq | BinaryOp::Lt | BinaryOp::LtEq | BinaryOp::Gt | BinaryOp::GtEq => true,
            _ => false,
        }
    }
}