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
TL;DR: Should a decorated class referencing itself in a method refer to the decorated class or undecorated? Currently it does the latter - which feels broken, but admittedly that may just be due to quirky code patterns.
To be honest, despite having done my best to read the proposal and spec, I cannot be certain whether esbuild is behaving incorrectly in this matter. However, I could not be certain that esbuild is deliberate in its current behavior since I could not spot a relevant case in the tests (https://github.com/evanw/decorator-tests/blob/main/decorator-tests.ts). The only case(s) that seemed similar also seemed distinct enough to not quite be relevant (i.e. the complexities involved with things like accessor might mean it's irrelevant to my simpler situation).
Notably, if I change one line near the bottom to var _Foo = class _FooInner { (so as to not reuse the _Foo identifier for the class expression itself), then I get the result I had expected:
I think it should be the latter case which seems more expected if you "desugar" the decorator:
classA{f(){returnA}}constfoo=x=>classB{f(){returnnewx().f()}}// unlike `function A` which behaves like `var A` (with a bit different),// `class A` behaves like `let A = class A` which means it could be reassigned.A=foo(A)console.log(A)console.log(newA().f())
TL;DR: Should a decorated class referencing itself in a method refer to the decorated class or undecorated? Currently it does the latter - which feels broken, but admittedly that may just be due to quirky code patterns.
To be honest, despite having done my best to read the proposal and spec, I cannot be certain whether esbuild is behaving incorrectly in this matter. However, I could not be certain that esbuild is deliberate in its current behavior since I could not spot a relevant case in the tests (https://github.com/evanw/decorator-tests/blob/main/decorator-tests.ts). The only case(s) that seemed similar also seemed distinct enough to not quite be relevant (i.e. the complexities involved with things like
accessor
might mean it's irrelevant to my simpler situation).esbuild.github.io/try link
Running the built code via node (20.12.1 in case it matters) results in
Notably, if I change one line near the bottom to
var _Foo = class _FooInner {
(so as to not reuse the_Foo
identifier for the class expression itself), then I get the result I had expected:The text was updated successfully, but these errors were encountered: