Closed ludinov closed 1 year ago
I believe that useDefineForClassFields was turned on by strong reasons, but right now it breaks assignments order in compiled bundle.
class Test { constructor(private a: string) {} b = this.a + "!" }
compiles into
class f{constructor(t){n(this,"b",this.a+"!");this.a=t}}
So property b becomes undefined!
b
undefined!
probably it should compile into something like this:
class f{constructor(t){n(this,"b",void 0);this.a=t;this.b=this.a+"!"}}
swc itself looks like handle it properly: https://play.swc.rs/?version=1.3.61&code=H4sIAAAAAAAAA0vOSSwuVghJLS5RqOZSAILk%2FLzikqLS5JL8Io2CosyyxJJUhURNhepasGySgq1CSUZmsV6igraCkqKSNVctAGoH4EtCAAAA&config=H4sIAAAAAAAAA1VPSQ7DIAy85xXI5x6iHPuHPAJRJyJiE3akoih%2FLxBC25s9i2d8DELARgqe4shjXoKMhLHvGaHkWL4zApwCkoo6MDxulqlQHHesyHkRwDKuyMWENI3T2AxgvCfM8CINYcOsdnpJv5HK2xCR6F9YpNKtpvuvxKGlgvWvvZLtlVK3NMjXrHcbwVd5J%2FbroGm%2B7fWZ8wOibzeCGwEAAA%3D%3D
actually it is vite issue : https://github.com/vitejs/vite-plugin-react-swc/issues/117
I believe that useDefineForClassFields was turned on by strong reasons, but right now it breaks assignments order in compiled bundle.
compiles into
So property
b
becomesundefined!
probably it should compile into something like this:
swc itself looks like handle it properly: https://play.swc.rs/?version=1.3.61&code=H4sIAAAAAAAAA0vOSSwuVghJLS5RqOZSAILk%2FLzikqLS5JL8Io2CosyyxJJUhURNhepasGySgq1CSUZmsV6igraCkqKSNVctAGoH4EtCAAAA&config=H4sIAAAAAAAAA1VPSQ7DIAy85xXI5x6iHPuHPAJRJyJiE3akoih%2FLxBC25s9i2d8DELARgqe4shjXoKMhLHvGaHkWL4zApwCkoo6MDxulqlQHHesyHkRwDKuyMWENI3T2AxgvCfM8CINYcOsdnpJv5HK2xCR6F9YpNKtpvuvxKGlgvWvvZLtlVK3NMjXrHcbwVd5J%2FbroGm%2B7fWZ8wOibzeCGwEAAA%3D%3D