-
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
Decorators cause output to differ from TSC #2629
Labels
Comments
I'm also experiencing this problem (in my case, when running unit tests in Vitest). If for whatever reason it's not possible to do what tsc does, I suppose the anonymous class could also be given a name, like so: var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __decorateClass = (decorators, target, key, kind) => {
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
for (var i = decorators.length - 1, decorator; i >= 0; i--)
if (decorator = decorators[i])
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
if (kind && result)
__defProp(target, key, result);
return result;
};
const someDecorator = () => () => {
};
const _Foo = class __Foo {
static message = "Hello world!";
static msgLength = __Foo.message.length;
foo() {
}
};
let Foo = _Foo;
__decorateClass([
someDecorator()
], Foo.prototype, "foo", 1);
export { Foo }; |
Same here, anything less than ES2022 fixes it. In my case Angular Dependency Injection was failing due to missing injection tokens because of this. |
Note to self: playground link for this issue |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When using
esbuild
withtarget: "ES2022"
, having decorators in classes causes the output to differ fromtsc
in a way that breaks self-referential static members.Input file
tsc
outputesbuild
outputRunning the esbuild version crashes with the error
ReferenceError: Cannot access '_Foo' before initialization
, pointing to the linestatic msgLength = _Foo.message.length;
This only happens when the target is ES2022 (or later) AND the the class has at least one decorator. If either of those conditions is not met, then the resulting code is fine.
The text was updated successfully, but these errors were encountered: