Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

overloading async as identifier and invoking as a method is not supported #130

Open
trullock opened this issue Aug 21, 2020 · 4 comments
Open

Comments

@trullock
Copy link
Owner

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

@madelson
Copy link

madelson commented Nov 23, 2020

@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 be async () => .
  • If it succeeds then check to see if the next token is =>; if so then this is a lambda named async.

@trullock
Copy link
Owner Author

@madelson perhaps take a look at the code

trullock added a commit that referenced this issue Dec 30, 2020
@drwestco
Copy link

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")}

@trullock
Copy link
Owner Author

trullock commented Mar 15, 2021

Thanks for the example

As per the readme and above, I've not got the time to fix this.

PRs welcome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants