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

Expose wether a module has TLA or not as .extra.async #16480

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

nicolo-ribaudo
Copy link
Member

@nicolo-ribaudo nicolo-ribaudo commented May 7, 2024

Q                       A
Fixed Issues? Fixes #16471
Patch: Bug Fix?
Major: Breaking Change?
Minor: New Feature? Yes
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

The parser already has this info, and having to detect it by yourself is error prone (due to computed keys and decorators).

We can also use this to warn in the CJS transform when there is top-level await (in a follow-up).

@nicolo-ribaudo nicolo-ribaudo added PR: New Feature 🚀 A type of pull request used for our changelog categories pkg: parser labels May 7, 2024
@babel-bot
Copy link
Collaborator

babel-bot commented May 7, 2024

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/56855

@liuxingbaoyu
Copy link
Member

Would it be better to just use topLevelAwait as the name?
Can we put hasTopLevelAwait in BaseParser together with sawUnambiguousESM, which would save a place, since 1 << 11 is already there :)

@nicolo-ribaudo
Copy link
Member Author

Renamed to topLevelAwait. I prefer to keep this in .state.flags, because currently we have still 20 bits of space that are being "wasted" there :) If anything, I would move sawUnambiguousESM to there.

Copy link
Contributor

@JLHwung JLHwung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test case for module expressions if there aren't such test? The current implementation should already work.

@nicolo-ribaudo nicolo-ribaudo added this to the v7.25.0 milestone May 14, 2024
@nicolo-ribaudo nicolo-ribaudo added the PR: Ready to be Merged A pull request with already two approvals, but waiting for the next minor release label May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: parser PR: New Feature 🚀 A type of pull request used for our changelog categories PR: Ready to be Merged A pull request with already two approvals, but waiting for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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