Reason for strange ExponentiationExpression & UpdateExpression productions?
Allen Wirfs-Brock
allen at wirfs-brock.com
Fri Jul 22 18:14:09 UTC 2016
> On Jul 22, 2016, at 10:04 AM, Bradford Smith <bradfordcsmith at google.com> 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: http://ecma-international.org/publications/files/ECMA-ST-ARCH/ECMA-262,%201st%20edition,%20June%201997.pdf <http://ecma-international.org/publications/files/ECMA-ST-ARCH/ECMA-262,%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.
Allen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160722/6889be27/attachment-0001.html>
More information about the es-discuss
mailing list