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
{{ message }}
Repository navigation
Change evaluation order of decorator-injected initializers #54267
Per consensus at the May, 2023 TC39 meeting, we need to change the evaluation order of decorator-injected initializers for both accessor and non-accessor fields. More details on the issue can be found here: tc39/proposal-decorators#508.
In summary, given
functionminusTwo({ set }){return{set(v){set.call(this,v-2);},init(v){returnv-2;},};}functiontimesFour({ set }){return{set(v){set.call(this,v*4);},init(v){returnv*4;}};}classC{
@minusTwo @timesFour accessor x=5;}constobj=newC();console.log(obj.x);// (a)obj.x=5;console.log(obj.x);// (b)
Prior to this change, the value at (a) would be 18 (((5) * 4) - 2), while the value at (b) would be 12 (((5) - 2) * 4). This is because the setters wrap and are thus evaluated from the outside-in, while initializers do not wrap and are applied from the inside-out.
After this change, the values at both (a) and (b) would be twelve, as the initializers would be applied outside-in as well.
Activity
DanielRosenwasser commentedon May 16, 2023
We should discuss whether it makes sense to bring this in for 5.1, even if it's post-RC.
EisenbergEffect commentedon Jun 1, 2023
Thank you for the fast turn around on this!