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

Top-level await detection doesn't take into account dead code elimination #2853

Closed
fabiospampinato opened this issue Jan 20, 2023 · 2 comments

Comments

@fabiospampinato
Copy link

Trying to bundle the following code throws:

if ( false ) {
  await foo ();
}

But esbuild should realize that there's not actually any top-level await there, because the await is unreachable.

This detail not being supported makes it a bit more annoying to create a module that works in different environments but that top-level awaits in only one of them.

@fabiospampinato fabiospampinato changed the title Top-level await detection doesn't take into account tree-shaking Top-level await detection doesn't take into account dead code elimination Jan 20, 2023
@evanw
Copy link
Owner

evanw commented Jan 20, 2023

Interesting suggestion. I can't think of any negative consequences of doing this, so I think this sounds reasonable.

Edit: Well, I think it should probably still be respected for the purposes of making the file be considered an ES module. So that means no module or exports and also implying strict mode.

@evanw evanw closed this as completed in 5fe2125 Jan 20, 2023
@fabiospampinato
Copy link
Author

That was quick 😁 thank you!

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

No branches or pull requests

2 participants