Uh oh!
There was an error while loading. Please reload this page.
Allowed non-this, non-super code before super call in derived classes with property initializers - #29374
Conversation
Fixesmicrosoft#8277. It feels wrong to put a new `forEachChild` loop in the checker, though in the vast majority of user files this will be a very quick one. Is there a better way to check for a reference to `super` or `this`?
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
weswigham
commented
Jan 11, 2019
|
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
…boundaries
```ts
function () {
return this;
}
```
It was immediately going to `ts.forEachChild` so the statement itself wasn't being counted as a new `this` scope.
ajafff
left a comment
There was a problem hiding this comment.
This is getting very complex very fast. I wonder if there's an easier way using the control flow graph?
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
As per discussion in the issue, it would be ideal to consider any block that always ends up calling to super() the equivalent of a root-level super() statement. This would be valid:
```ts
foo = 1;
constructor() {
condition() ? super(1) : super(0);
this.foo;
}
```
...as it would compile to the equivalent of:
```ts
function () {
condition() ? super(1) : super(0);
this.foo = 1;
this.foo;
}
That change would a bit more intense and I'm very timid, so leaving it out of this PR. In the meantime the requirement is that the super() statement must itself be root-level.Uh oh!
There was an error while loading. Please reload this page.
RyanCavanaugh
commented
Jan 25, 2019
cc @ahejlsberg for review |
JoshuaKGoldberg
commented
Apr 2, 2019
Ping @ahejlsberg - is there anything that needs to be done here? It'd be nice to have this in 😄 |
JoshuaKGoldberg
commented
Jul 16, 2019
Correction: ping, @weswigham? |
pkoch
commented
Jan 14, 2022
@rbuckton Is there anything else that @JoshuaKGoldberg can do to move this forward? |
rbuckton
commented
Jan 14, 2022
@typescript-bot user test this inline |
typescript-bot
commented
Jan 14, 2022
rbuckton
commented
Jan 14, 2022
Nope, it looks ready to go actually, and just in time for 4.6 beta. |
JoshuaKGoldberg
commented
Jan 14, 2022
Fantastic, thanks so much for the reviews & merge @rbuckton! If any issues come out of this change I'm available to try to fix, if that's helpful. |
NaveedAhmadHematmal
commented
Jan 14, 2022
The longest-living PR I have ever seen. 😳 |
YES!!! Thank you!🎉 🎉 🎉 |
callumok2004
commented
Jan 22, 2022
🥳🎉🎉 |
iJungleboy
commented
Mar 7, 2022
Amazing work and perseverance. Awesome! |
EstopaceMA
commented
Mar 18, 2022
Man! Awesome. The perseverance! 🎉 |
vladboss61
commented
Jul 7, 2022
Does it mean that now super is going to be invoked the first time never mind where he is located in the constructor? |
…rosoft/TypeScript#29374 The minimum TypeScript dependency is lifted to 4.6.2
jfortier-haptiq
commented
Jul 28, 2022
Congrats, apparently the cake did it's job! 🎉 |
gbersac
commented
Jul 28, 2022
Guy you've made it reddit programmer humor front page! https://www.reddit.com/r/ProgrammerHumor/comments/waa0lz/if_youre_ever_frustrated_that_your_github_prs/ |
taylus
commented
Jul 28, 2022
grats on the PR |
upq
commented
Jul 28, 2022
Congrats !! Happy for you! |
Starts on #8277 by allowing the non-
this, non-supercode to be root-level statements in the constructor. This will now be allowed:It feels wrong to put a newforEachChildloop in the checker, though in the vast majority of user files this will be a very quick one. Is there a better way to check for a reference tosuperorthis?Edit 2/28/2020: I've
mostlyresolved the merge conflicts introduced by both#private fields &useDefineForClassFields, but I'm not confident my approach is still a valid one. I'd greatly appreciate it if someone could confirm I'm on the right track!Oh, and✔️gulp runtestspasses locally (on Windows). I'll try a Mac to see if there's some odd encoding/whitespace behavior with the failing test...Edit 3/11/2021: It seems this is fairly close to merging.
Edit 1/13/2022: I bought this PR a birthday cake for its third birthday. https://twitter.com/JoshuaKGoldberg/status/1481654056422567944