Operator Priority :! and wait

In JavaScript, how to interpret the following statement:

cond1 && !await f() 

This is an excerpt from a line.

 if(cond1 && !await f()){ do_stuff(); } 

inside a production application. chrome seems to be okay with it, but on ios it causes an error reading

 unexpected identifier 'f'. Expected ')' to end an if condition. 

It seems that ios turns !await f() into (!await)(f()) instead of !(await f()) .

Now to my question: According to ECMA-262 , what is the correct interpretation of the above line?

ps: We fixed the code for ios by changing it to

 var f_result = await f(); if(cond1 && !f_result){ do_stuff(); } 
+5
source share
1 answer

This has nothing to do with operator priority. Since both are unary prefix operators, only one expression can be interpreted - all delete , void , typeof , + , - , ~ ! and await parsed for the same production purpose and can be arbitrarily nested. And yes, this is the correct syntax in ES2017.

+2
source

Source: https://habr.com/ru/post/1269553/


All Articles