-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Classes with static attributes and blocks are broken under --target=es2022
#2800
Comments
--target=es2022
Static fields are always lowered to avoid safari TDZ issue in bundle mode. So the problem is: when enabled lowering for On the other hand, referring class name in static block is ok only when the class name is declared via class A { static { console.log(A) } } // class A {}
var A = class { static { console.log(A) } } // undefined Note that this behavior only affects top level classes, which means a workaround when you put the class declaration in some scope (see it live): let A = /*@__PURE__*/ (() => class A {
static foo = 1 // will not be lowered
})() |
@hyrious Wow - I am very curious. Where can I learn more about the Safari TDZ issue? My understand was that TDZ is consistently specified behavior and therefore I'm surprised to hear it might be acting differently in one browser. Edit: Ok I looked into the backstory and think there might be a more general issue. |
We really need to be able to turn this off. Outside of producing pretty unreadable code (that's still visible when doing |
Looks like 0.18.4 no longer rewrites classes as described in this issue. I haven't tried it in my own project (since I rewrote it in a way that doesn't use Thank you for the fix (and for making the fantastic |
I haven't been able to fully track down this issue, but here's what I know.
esbuild
version: 0.16.14Input:
The specific classes, properties, and values aren't important.
When
esbuild test.js
is run directly, these classes are compiled as follows:This interpretation seems completely sensible, and functions as expected. The same results occur when run with
--bundle
.When
esbuild --target=esnext test.js
is run, the output is (effectively) the same as the input, as might be expected.When the
--bundle
and--target=esnext
options are combined, however, the output is the following (commentary my own):It appears that the behavior of rewriting static blocks for older browsers is behaving inconsistently with
--target=esnext
(or--target=2022
) — standalone static blocks are neither rewritten nor extracted, but when a static attribute is introduced, the blocks are only rewritten and not extracted.(Interestingly, this also seems to reveal an issue in the documentation — the
target
option is documented as defaulting toesnext
, but there's clearly a change in behavior when the value is explicitly provided.)The text was updated successfully, but these errors were encountered: