You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When bundling is enabled, class definitions are rewritten as variable assignment + anonymous class, and that might create some issues with static initializers.
In this case the static initializer works without any issues. On the other hand, when bundling (e.g. esbuild --format="esm" --bundle testme.js) the class definition gets rewritten this way:
In this second case, the static initializer fails as MyTest is not defined when running the static initializer.
I think that preserving the class name in the variable assignment should be "ok" (there doesn't seem to be any side effect), and this seems to work (OtherTest is defined, MyTest is not):
varOtherTest=classMyTest{static{MyTest.prototype.foo='bar'}}// ... here `MyTest` is not defined...export{OtherTest}
But I'm not 100% sure whether this would be a good solution or there might be some alternatives...
Note, yes, I know we can use this to refer to the class in the static initializer, but I don't have control over the library's source, unfortunately!
The text was updated successfully, but these errors were encountered:
When bundling is enabled, class definitions are rewritten as variable assignment + anonymous class, and that might create some issues with static initializers.
For example, given this code in
testme.js
:When not bundling (e.g.
esbuild --format="esm" testme.js
, the code gets transpiled as follows:In this case the static initializer works without any issues. On the other hand, when bundling (e.g.
esbuild --format="esm" --bundle testme.js
) the class definition gets rewritten this way:In this second case, the static initializer fails as
MyTest
is not defined when running the static initializer.I think that preserving the class name in the variable assignment should be "ok" (there doesn't seem to be any side effect), and this seems to work (
OtherTest
is defined,MyTest
is not):But I'm not 100% sure whether this would be a good solution or there might be some alternatives...
Note, yes, I know we can use
this
to refer to the class in the static initializer, but I don't have control over the library's source, unfortunately!The text was updated successfully, but these errors were encountered: