swc_core::ecma::ast

Macro op

macro_rules! op {
    (unary,"-") => { ... };
    (unary,"+") => { ... };
    ("!") => { ... };
    ("~") => { ... };
    ("typeof") => { ... };
    ("void") => { ... };
    ("delete") => { ... };
    ("++") => { ... };
    ("--") => { ... };
    ("==") => { ... };
    ("!=") => { ... };
    ("===") => { ... };
    ("!==") => { ... };
    ("<") => { ... };
    ("<=") => { ... };
    (">") => { ... };
    (">=") => { ... };
    ("<<") => { ... };
    (">>") => { ... };
    (">>>") => { ... };
    (bin,"+") => { ... };
    (bin,"-") => { ... };
    ("*") => { ... };
    ("/") => { ... };
    ("%") => { ... };
    ("|") => { ... };
    ("^") => { ... };
    ("&") => { ... };
    ("||") => { ... };
    ("&&") => { ... };
    ("in") => { ... };
    ("instanceof") => { ... };
    ("**") => { ... };
    ("??") => { ... };
    ("=") => { ... };
    ("+=") => { ... };
    ("-=") => { ... };
    ("*=") => { ... };
    ("/=") => { ... };
    ("%=") => { ... };
    ("<<=") => { ... };
    (">>=") => { ... };
    (">>>=") => { ... };
    ("|=") => { ... };
    ("^=") => { ... };
    ("&=") => { ... };
    ("**=") => { ... };
    ("&&=") => { ... };
    ("||=") => { ... };
    ("??=") => { ... };
}
Available on crate features __ecma and ecma_ast only.
Expand description

Creates a corresponding operator. This macro is used to make code more readable.

This can used to represent UnaryOp, BinaryOp, or AssignOp.

Actual type is determined by the input.

ยงNote about + and -

As this macro is intended to be used in anywhere, including pattern bindings, this macro cannot use trick to determine type for + and -.

So we have to use some special syntax for + and -:

  • If you need UnaryOp, use op!(unary, "+") and op!(unary, "-").

  • If you need BinaryOp, use op!(bin, "+") and op!(bin, "-").