ActiveObject
ActiveObject

Reputation: 128

Sweet.js - Parenthesis in macros body

I want to use parenthesis in macros body to group expressions. For example:

macro m {
  rule { ($x, $y) } => {
    $x >>> ($y * 5)
  }
}

Sweet.js remove all parenthesis:

m(6, 7) => 6 >>> 7 * 5

I expect next output:

m(6, 7) => 6 >>> (7 * 5)

How can I escape parenthesis inside macros body?

Upvotes: 1

Views: 141

Answers (1)

timdisney
timdisney

Reputation: 5337

Sweet.js (technically escodegen which sweet.js uses for codegen) only removes redundant parens (ie precedence rules mean that 6 >>> 7 * 5 === 6 >>> (7 * 5) so the parens aren't needed) so you shouldn't need to do anything to escape parens in macros.

Upvotes: 3

Related Questions