swc_ecma_ast

Macro op

source
macro_rules! op {
    (unary,"-") => { ... };
    (unary,"+") => { ... };
    ("!") => { ... };
    ("~") => { ... };
    ("typeof") => { ... };
    ("void") => { ... };
    ("delete") => { ... };
    ("++") => { ... };
    ("--") => { ... };
    ("==") => { ... };
    ("!=") => { ... };
    ("===") => { ... };
    ("!==") => { ... };
    ("<") => { ... };
    ("<=") => { ... };
    (">") => { ... };
    (">=") => { ... };
    ("<<") => { ... };
    (">>") => { ... };
    (">>>") => { ... };
    (bin,"+") => { ... };
    (bin,"-") => { ... };
    ("*") => { ... };
    ("/") => { ... };
    ("%") => { ... };
    ("|") => { ... };
    ("^") => { ... };
    ("&") => { ... };
    ("||") => { ... };
    ("&&") => { ... };
    ("in") => { ... };
    ("instanceof") => { ... };
    ("**") => { ... };
    ("??") => { ... };
    ("=") => { ... };
    ("+=") => { ... };
    ("-=") => { ... };
    ("*=") => { ... };
    ("/=") => { ... };
    ("%=") => { ... };
    ("<<=") => { ... };
    (">>=") => { ... };
    (">>>=") => { ... };
    ("|=") => { ... };
    ("^=") => { ... };
    ("&=") => { ... };
    ("**=") => { ... };
    ("&&=") => { ... };
    ("||=") => { ... };
    ("??=") => { ... };
}
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, "-").