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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[parser] Expose somehing like program.extra.async to easily know if a module uses top-level await #16471

Open
1 task
nicolo-ribaudo opened this issue May 4, 2024 · 3 comments 路 May be fixed by #16480
Open
1 task

Comments

@nicolo-ribaudo
Copy link
Member

馃捇

  • Would you like to work on this feature?

What problem are you trying to solve?

I'm working on a project that uses @babel/parser to do some analysis, and I need to know if a module uses top-level await.

It's not trivial to detect, because you need to check also, for example, in computed keys inside of methods (doing something like what @babel/helper-environment-visitor does, but that requires a full @babel/traverse).

Describe the solution you'd like

Given that we already need to track this info (to know if await is allowed or an error), we might as well expose it.

Describe alternatives you've considered

/

Documentation, Adoption, Migration Strategy

No response

@liuxingbaoyu
Copy link
Member

I thought about something similar the other day, and this can also be used to avoid some traversals of the entire AST, such as transform-async-generator-functions. This is another way besides the order of plugins.
Perhaps we can put them in extra.usedFeatures.

@nicolo-ribaudo
Copy link
Member Author

I'm hesitant to use extra to affect how transforms work, because any plugin could inject a new async generator function.

@liuxingbaoyu
Copy link
Member

You are right! If we just want to avoid traversing Program, that works too. Because other plugins run after that.
Of course, I personally prefer to avoid it by plugin order.

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

Successfully merging a pull request may close this issue.

2 participants