Reason for strange ExponentiationExpression & UpdateExpression productions?

Bradford Smith bradfordcsmith at
Wed Jul 20 19:48:46 UTC 2016

Can anyone explain the reasoning behind the strange "leapfrogging" behavior
of the ExponentiationExpression
<> and
<> productions
in the current spec?

Simplified relevant productions in operator precedence order are:

ExponentiationExpression :
    UpdateExpression ** ExponentiationExpression

UnaryExpression :
    { delete | void | typeof | + | - | ~ | ! } UnaryExpression

    { ++ | -- } UnaryExpression
    LeftHandSideExpression { ++ | -- }

Things that seem weird about this are:
1. '-x ** y' is a syntax error, because UnaryExpression isn't allowed
before **
    You must write it as '(-x) ** y'
    I would expect the production right hand side to be
        UnaryExpression ** ExponentiationExpression
    That avoids this strange syntax error and is consistent with the
pattern followed by productions for lower-precedence operators.

2. Having UnaryExpression in the right hand side of UpdateExpression
confuses precedence by going 'backward' to a lower-precedence non-terminal,
and the only production of UnaryExpression that generates a valid argument
for '++'/'--' is UnaryExpression => UpdateExpression =>
LeftHandSideExpression anyway.

I've just finished implementing these rules in the closure-compiler, where
I had to implement logic to deal with this strange behavior. Is it at all
possible that these are simply typos in the spec?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list