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
With the implementation of Stage 3 Decorators in TS 5, using a getter decorator can result in the content of the constructor being duplicated in the emitted code, for example:
constructor(){this.computedVal;console.log("As will this");__runInitializers(this,_instanceExtraInitializers);this.computedVal;console.log("As will this");}
🔎 Search Terms
Constructor duplicate decorators getter
🕗 Version & Regression Information
Started seeing this when I updated a library from TS 5.0-beta to TS 5.0.2.
This changed between versions 5.0-beta and 5.0.2. Not applicable to prior versions.
functioncomputed(target,ctx: ClassGetterDecoratorContext){ctx.addInitializer(function(){console.log("INIT")})returntarget}classBla{// Things seem to work as expected if a field or accessor is also defined,// but additional getters/setters or methods continue to see the double emission// name: string = ""
@computedgetcomputedVal(){console.log("This will print twice")return3}constructor(){this.computedValconsole.log("As will this")}}newBla()
🙁 Actual behavior
Constructor logic is duplicated:
constructor(){this.computedVal;console.log("As will this");__runInitializers(this,_instanceExtraInitializers);this.computedVal;console.log("As will this");}
🙂 Expected behavior
Constructor logic should not be duplicated:
constructor(){__runInitializers(this,_instanceExtraInitializers);this.computedVal;console.log("As will this");}
The text was updated successfully, but these errors were encountered:
The underlying issue is that the logic to inject __runInitializers() into a constructor incorrectly called addRange/visitNodes twice when a super() wasn't present. This only occurred for getters, setters, and methods because __runInitializers() is injected into the constructor when there are no fields present, but is injected into the first field initializer when fields are present.
Bug Report
With the implementation of Stage 3 Decorators in TS 5, using a getter decorator can result in the content of the constructor being duplicated in the emitted code, for example:
🔎 Search Terms
Constructor duplicate decorators getter
🕗 Version & Regression Information
Started seeing this when I updated a library from TS 5.0-beta to TS 5.0.2.
This changed between versions
5.0-beta
and5.0.2
. Not applicable to prior versions.⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
Constructor logic is duplicated:
🙂 Expected behavior
Constructor logic should not be duplicated:
The text was updated successfully, but these errors were encountered: