bug: Element decorator does not work when targeting ES2022 and setting useDefineForClassFields to true #4528
Closed
3 tasks done
Labels
Bug: Validated
This PR or Issue is verified to be a bug within Stencil
Prerequisites
Stencil Version
4.0.1
Current Behavior
When targeting ES2022 and having useDefineForClassFields set to truthy, Stencil generates an additional class field for properties annotated with Element.
This results in both a class field and a getter for the property.
Stencil should only generate the getter.
This was already tackled for State and Prop decorated properties but not for Element: #3614.
Expected Behavior
Stencil should handle the Element decorator in the same way than the other decorators such as State and Prop which are listed here: https://github.com/ionic-team/stencil/blob/main/src/compiler/transformers/decorators-to-static/decorators-constants.ts#L17.
There shouldn't be an additional class field being generated next to the getter.
System Info
Steps to Reproduce
To reproduce the bug, set the Typescript target to ES2022 and set the useDefineForClassFields setting to true.
The problem is actually pretty much the same than what was already tacked in this Pull Request: #3614.
But for some reason, it doesn't consider the Element decorator. When making use of the Element decorator in a Stencil component while having the mentioned TypeScript settings, Stencil generates both a class field for the Element and a getter. The Browser only evaluates the class field, so that the annotated property is always undefined during runtime.
It starts to work fine when the list of decorators to rewrite is extended with Element. I mean this constant here: https://github.com/ionic-team/stencil/blob/main/src/compiler/transformers/decorators-to-static/decorators-constants.ts#L17.
When using the provided reproduction repo:
Build the repo using npm run build.
Inspect the generated code in app-home.entry.js. It contains both a class field for the annotated property and a getter.
Code Reproduction URL
https://github.com/henning96/stencil-bug-element
Additional Information
No response
The text was updated successfully, but these errors were encountered: