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
{{ message }}
Repository navigation
Decorator as static class member fails with runtime error #3326
After upgrading Vite from 4.3.9 (esbuild 0.17.19) to Vite 4.4.9 (esbuild 0.18.20), decorators that are static class members stop working when the decorated static method instantiates the class.
In this case, the class will be created as temporary variable (e.g. _Test), and will be decorated using the original class name (Test) before that variable will be defined (let Test = _Test).
Original test code (Test1 works as expected, Test2 fails with esbuild 0.18):
exportclassTest1{staticdeco(){}statictest(){}}__decorateClass([Test1.deco],Test1,"test",1);const_Test2=class{staticdeco(){}statictest(){returnnew_Test2();}};exportletTest2=_Test2;__decorateClass([Test2.deco],Test2,"test",1);// <============ works
esbuild 0.18.20
exportclassTest1{staticdeco(){}statictest(){}}__decorateClass([Test1.deco],Test1,"test",1);const_Test2=class_Test2{staticdeco(){}statictest(){returnnew_Test2();}};__decorateClass([Test2.deco],_Test2,"test",1);// <============= uses "Test2" instead of "_Test2"exportletTest2=_Test2;
Importing the module immediately fails with
ReferenceError: Cannot access 'Test2' before initialization
I am having this issue as well. It looks like it occurs in any class with static members (which cause an underscore prefix rename on the class). It seems the problem is just that the renamed class is not used in the call to __decorateClass.
Activity
dlmartens commentedon Aug 30, 2023
I am having this issue as well. It looks like it occurs in any class with static members (which cause an underscore prefix rename on the class). It seems the problem is just that the renamed class is not used in the call to
__decorateClass.Here is a basic example.
viceice commentedon Sep 7, 2023
Seeing same error while trying to transition from jest (ts-jest) to vitest. For us esbuild v0.17 and v0.19 are failing too. 😕
fix evanw#3230, fix evanw#3326, fix evanw#3394: update decorators