overloading `async` as identifier and invoking as a method is not supported
if you do this:
function (async) {
async();
}
i.e. if you overload async as an identifier, and then call it as a function (with or without arguments) the parser will not understand this line and will strip it, removing the invocation
I don't know how to fix this without some serious rewriting of the parser, which I can't be arsed to do for such a sadistic case.
function (async) {
async = 1; // this will work
async[1] = 2; // this will work
async(); // this line will be stripped
async(a,b); // this will end up as: a,b
}
The issue can be seen in JSParser, line ~4075 inside the Async case.
You end up in here because async() is an expression, but the parser (quite reasonably) expects you do be either doing async () => { } or async function() { }. The 2nd case is easily handled because of the unique presence of function, however diffrentiating between the former is not currently easy - at least I can't see how.
Marking as wontfix because its such a mad case, but someone is welcome to try
@trullock I haven't looked at the parser code, but maybe some logic like this could work?
- Try to parse the sequence starting with
(as an argument list; if that fails then it can't beasync () =>. - If it succeeds then check to see if the next token is
=>; if so then this is a lambda named async.
@madelson perhaps take a look at the code
Another case that's a little different than the examples above:
function foo(out, async) {
return async
? out.replace('x', 'y')
: out.replace('w', 'y');
}
test.js(3,17-18): run-time error JS1195: Expected expression: .
test.js(4,12-13): run-time error JS1195: Expected expression: :
function foo(){return async()=>.replace("x","y")}
Thanks for the example
As per the readme and above, I've not got the time to fix this.
PRs welcome