-
Notifications
You must be signed in to change notification settings - Fork 378
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
Feature request: async/await support #814
Comments
Alternatively, instead of implementing it in ternjs directly, would it be feasible to "pre-transform" the AST before passing it to tern? I can imagine something like the following:
Of course these transformations are very different in behaviour, but should give the same result for type inference. |
I have a basic proof of concept working now with the transforms as described above, so the approach seems to be working. There are still some tricky cases such as arrow functions, but I should be able to figure something out. I'll share my code when I've cleaned it up. So it does seem like it's feasible to implement this completely outside of Tern, but the implementation would be cleaner if Tern could work with e.g. |
Initial proof of concept here: https://github.com/rkistner/tern-asyncawait. Tests are passing, but haven't actually used it yet. |
This was landed with #446 |
acornjs/acorn#446 only implements it in Acorn, not in Tern yet, so this should probably stay open for now? |
Oops, I thought this was in the Acorn repo. Reopening! |
+1 |
Any progress? |
Node 8 has been released 2017-05-30 and it supports async/await |
Tern has nothing to do with ESLint, getting async/await support here would require implementing it in Tern. |
Here is reference to It seems that I mixed two projects with name tern |
Would love to see this implimented |
Would love to see async/await support in Tern. Currently can't navigate to the definition of async functions which really slows me down in VIM. |
For anyone still following this issue, I got something mostly working a while back, using the following approach: To start with:
Create a Tern plugin with a postParse hook. The postParse hook walks the AST, and transforms async functions and await expressions into nodes that Tern supports: I transformed await statements (AwaitExpression) into a function call that returns the value of the Promise. This is of course completely impossible/invalid in actual JS, but works fine for type checking. Actually implementing this function call required some hacks, with a custom I transformed async functions (both FunctionDeclaration and ArrowFunctionExpression), by adding a fake return statement with the correct type to the end of the body. I also wrapped any ReturnStatement into one that returns a Promise, instead of the original value. These transformations all felt like a significant hack, that could be implemented better in Tern itself, but it did work quite well for me. While this plugin is still in use, nowadays I recommend TypeScript instead. While the type inference for plain JS isn't always as good as Tern, I found it good enough for personal development, and it keeps on improving over time. I there is enough interest, I can see if I can extract and publish the source for this plugin. |
I don't know about anyone else but I'd really appreciate a plugin that fixed this issue. I tried with your example code you posted earlier but I couldn't figure out how to get the combination of YCM/Tern to actually work with it. |
Update: I added the Also fun note, if you have a plugin named "foo" in your config file then you try to edit a file named ./foo.js, tern will try to load the file you're editing as a plugin. This is great fun to figure out. |
I realize that it is not standardized yet (currently stage 3), but support for async/await would be extremely useful for me. What would it involve to get this implemented?
The functionality I'm looking for would entail:
I'm willing to help with the implementation in my spare time. If you feel this should not be in the core library since it's not standardized yet, would it be feasible to implement this in some kind of "plugin", or would I have to fork ternjs? I understand that it is also not part of the acorn parser yet, but there already exists plugins an acorn plugin implementing it.
The text was updated successfully, but these errors were encountered: