esbuild icon indicating copy to clipboard operation
esbuild copied to clipboard

top-level-var will silent circular dependency TDZ error

Open hardfist opened this issue 2 years ago • 3 comments

  • Describe what esbuild is doing incorrectly and what it should be doing instead. doing: esbuild's top-level-var will silence circular dependency tdz should be doing: support not enable top-level-var or disable top-level-var by default

  • Provide a way to reproduce the issue. The best way to do this is to demonstrate the issue on the playground (https://esbuild.github.io/try/) and paste the URL here. A link to a minimal code sample with instructions for how to reproduce the issue may also work. Issues without a way to reproduce them may be closed. https://github.com/hardfist/circular-dependency-cases/pull/1 lots of edge cases here

hardfist avatar Jan 04 '24 14:01 hardfist

I read https://esbuild.github.io/faq/#top-level-var and know the design reason, but it conflicts with other bundler's default behavior which may make code runs successfully on esbuild but fails on other bundler

hardfist avatar Jan 04 '24 14:01 hardfist

An alternative could be to have esbuild generate extra code to re-create the TDZ checks at run-time. I suspect that would be a very unpopular change, however, due to the code size, performance, and aesthetic impacts it would have.

evanw avatar Jan 04 '24 18:01 evanw

You may be interested to know that at the September 2023 TC39 meeting there was a discussion of the possibility of removing TDZ from the JS spec.

The slides in that discussion note that Babel has an option to emit TDZ checks, and that this option is deliberately disabled by default, in defiance of the specification, for the same reasons given above.

bakkot avatar Jan 05 '24 04:01 bakkot