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

Disable top-level await with a compat flag #3081

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jasnell
Copy link
Member

@jasnell jasnell commented Nov 8, 2024

Currently, the top level scope of a Worker script and modules that are imported may use top level await. However, because we restrict the use of i/o in the top level scope, the only thing that can be awaited at the top level scope is a dynamic import, which we require to be resolved synchronously. It is a bit nonsensical to support synchronously resolved dynamic imports at the top level when we can just use static imports more effectively. Additionally, the ecosystem and runtimes are moving to a state where top level await in modules is being strongly discouraged. This compat flag. This compatibility flag will make it impossible to use top level await.

(made the change with lots of distractions so keeping as a draft until I can do a second pass to make sure nothing was missed)

Currently, the top level scope of a Worker script and modules
that are imported may use top level await. However, because we
restrict the use of i/o in the top level scope, the only thing
that can be awaited at the top level scope is a dynamic import,
which we require to be resolved synchronously. It is a bit
nonsensical to support synchronously resolved dynamic imports
at the top level when we can just use static imports more
effectively. Additionally, the ecosystem and runtimes are moving
to a state where top level await in modules is being strongly
discouraged. This compat flag. This compatibility flag will
make it impossible to use top level await.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant