Various bugs with class expressions and JavaScript decorators (code run twice, internal compiler crash) #58436
Labels
Bug
A bug in TypeScript
Crash
For flagging bugs which are compiler or service crashes or unclean exits, rather than bad output
Domain: Decorators
The issue relates to the decorator syntax
Fix Available
A PR has been opened for this issue
Milestone
π Search Terms
javascript decorators proposal class expressions crash debug failure error
π Version & Regression Information
β― Playground Link
No response
π» Code
Case 1: (playground link)
Case 2 (playground link):
This is case 1 with the decorator on the class expression removed.
Case 3 (playground link):
This is case 1 with the two instance elements removed.
π Actual behavior
Case 1:
When run, this prints the following:
That means:
TypeScript's behavior for decorators on class expressions diverges from TypeScript's behavior for class statements. The
expected
output was taken from TypeScript's transformation of the same code but as a class statement instead of a class expression, and appears to be correct.The code that TypeScript generates evaluates several initializers multiple times. Specifically, static field and static accessor initializers are run twice, which corresponds to duplicated calls to
__runInitializers(_classThis, _static_field_extraInitializers)
and__runInitializers(_classThis, _static_accessor_initializers)
in the generated code.Case 2:
This crashes the playground compiler with
Error: Debug Failure.
and a minified stack trace.Case 3:
This crashes the playground compiler with
Error: Debug Failure. False expression: Undeclared private name for property declaration.
and a minified stack trace.π Expected behavior
TypeScript should transform decorators into code that behaves the same whether or not the original class was an expression or a statement. The compiler should also not crash with debug assertion failures.
For context, I discovered these issues while expanding the coverage of my decorator test suite: https://github.com/evanw/decorator-tests. I intend to use these test cases when adding support for transforming decorators to esbuild.
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: