Reason for strange ExponentiationExpression & UpdateExpression productions?

Allen Wirfs-Brock allen at
Fri Jul 22 18:14:09 UTC 2016

> On Jul 22, 2016, at 10:04 AM, Bradford Smith <bradfordcsmith at> wrote:
> A brief search didn't turn up any test cases that would enlighten me regarding why the rules for UpdateExpression are:
> UpdateExpression :
>     { ++ | -- } UnaryExpression
>     LeftHandSideExpression { ++ | -- }
> You can't increment or decrement anything that isn't a LeftHandSideExpression, so why does the syntax rule allow UnaryExpression as an argument for update in the prefix case?

It’s basically preserve legal syntax that extends all the way back to the ES1 specification:,%201st%20edition,%20June%201997.pdf <,%201st%20edition,%20June%201997.pdf> 

that syntax means that something like:

if (false) ++ -42;

Is syntactically valid.  A program containing such a line will load and execute without error.

Changing the grammar (or static semantics rules) to make that illegal would be a ”breaking change” that might cause some valid existing scripts to suddenly fail to load.

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

More information about the es-discuss mailing list