ast-types icon indicating copy to clipboard operation
ast-types copied to clipboard

`**` exponentiation operator has higher precedence than multiply/divide/modulo...

Open GerHobbelt opened this issue 7 years ago • 2 comments

..., as per https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence

GerHobbelt avatar Dec 12 '17 23:12 GerHobbelt

Noticed while looking at ast-types and Recast that there is quite a bit of duplication between node-path and fast-path‘s needParens. Seeing that only Recast uses that for printing, is there a reason for this?

On topic now, Recast had a similar PR a couple of years back: https://github.com/benjamn/recast/pull/285, where the ** operator was added with the same precedence as *, / and %. Not too sure about the semantics of these operations, so just putting this up for someone more well-versed to weigh in.

bnjmnt4n avatar Feb 06 '19 10:02 bnjmnt4n

@bnjmnt4n A while back I put in some effort to minimize/eliminate ast-types dependencies for recast.parse and recast.print (though of course recast.visit and recast.types still depend on ast-types). Moving to FastPath and its implementation of needsParens was part of that work. FastPath is a less ergonomic abstraction than NodePath, but it's faster for recast's needs because it keeps track of the current path using a mutable stack instead of lots of separate NodePath objects.

benjamn avatar Feb 06 '19 15:02 benjamn