FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Allowed non-this, non-super code before super call in derived classes with property initializers by JoshuaKGoldberg · Pull Request #29374 · microsoft/TypeScript · GitHub

Allowed non-this, non-super code before super call in derived classes with property initializers - #29374

Merged
Ron Buckton (rbuckton) merged 61 commits into
microsoft:mainfrom
JoshuaKGoldberg:non-this-super-before-super
Jan 14, 2022
Merged

Allowed non-this, non-super code before super call in derived classes with property initializers#29374
Ron Buckton (rbuckton) merged 61 commits into
microsoft:mainfrom
JoshuaKGoldberg:non-this-super-before-super

Conversation

Josh Goldberg ✨ (JoshuaKGoldberg) commented Jan 11, 2019
edited
Loading

Copy link
Copy Markdown
Contributor

Starts on #8277 by allowing the non-this, non-super code to be root-level statements in the constructor. This will now be allowed:

class Base { }
class Derived extends Base {
    public prop = true;
    constructor(public paramProp = true) {
        console.log("Hello, world!");
        super();
    }
}

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?

Edit 2/28/2020: I've mostly resolved 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 runtests passes 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

Fixes microsoft#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`?
Comment thread src/compiler/checker.ts Outdated
Comment thread src/compiler/utilities.ts Outdated
Comment thread src/compiler/utilities.ts Outdated

Copy link
Copy Markdown
Member

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?

TransformFlags.Super | TransformFlags.ContainsSuper for super at least.

Comment thread src/compiler/utilities.ts Outdated
…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.

Klaus Meinhardt (ajafff) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This is getting very complex very fast. I wonder if there's an easier way using the control flow graph?

Comment thread src/compiler/utilities.ts Outdated
Comment thread src/compiler/checker.ts Outdated
Comment thread src/compiler/utilities.ts Outdated
Comment thread src/compiler/utilities.ts Outdated
Comment thread src/compiler/utilities.ts Outdated
Josh Goldberg added 3 commits January 15, 2019 14:40
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.
Comment thread src/compiler/utilities.ts Outdated

Copy link
Copy Markdown
Member

cc Anders Hejlsberg (@ahejlsberg) for review

Copy link
Copy Markdown
Contributor Author

Ping Anders Hejlsberg (@ahejlsberg) - is there anything that needs to be done here? It'd be nice to have this in 😄

Copy link
Copy Markdown
Contributor Author

Correction: ping, Wesley Wigham (@weswigham)?

Copy link
Copy Markdown

Ron Buckton (@rbuckton) Is there anything else that Josh Goldberg ✨ (@JoshuaKGoldberg) can do to move this forward?

Copy link
Copy Markdown
Contributor

TypeScript Bot (@typescript-bot) user test this inline

Copy link
Copy Markdown
Contributor

Heya Ron Buckton (@rbuckton), I'm starting to run the inline community code test suite on this PR at 1b3dd6d. Hold tight - I'll update this comment with the log link once the build has been queued.

Copy link
Copy Markdown
Contributor

Ron Buckton (@rbuckton) Is there anything else that Josh Goldberg ✨ (@JoshuaKGoldberg) can do to move this forward?

Nope, it looks ready to go actually, and just in time for 4.6 beta.

Ron Buckton (rbuckton) merged commit b7fee7f into microsoft:main Jan 14, 2022
Josh Goldberg ✨ (JoshuaKGoldberg) deleted the non-this-super-before-super branch January 14, 2022 14:31

Copy link
Copy Markdown
Contributor Author

Fantastic, thanks so much for the reviews & merge Ron Buckton (@rbuckton)!

If any issues come out of this change I'm available to try to fix, if that's helpful.

Copy link
Copy Markdown

The longest-living PR I have ever seen. 😳

Luke Scott (lukescott) commented Jan 20, 2022
edited
Loading

Copy link
Copy Markdown

YES!!! Thank you!🎉 🎉 🎉

Copy link
Copy Markdown

🥳🎉🎉

Copy link
Copy Markdown

Amazing work and perseverance. Awesome!

Copy link
Copy Markdown

Man! Awesome. The perseverance! 🎉

Copy link
Copy Markdown

Does it mean that now super is going to be invoked the first time never mind where he is located in the constructor?

Eemeli Aro (eemeli) added a commit to messageformat/messageformat that referenced this pull request Jul 16, 2022

Copy link
Copy Markdown

Congrats, apparently the cake did it's job! 🎉

Copy link
Copy Markdown

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

Copy link
Copy Markdown

grats on the PR

upq commented Jul 28, 2022

Copy link
Copy Markdown

Congrats !! Happy for you!
Might as well be the most famous PR yet ... from branding perspective I recommend you naming the PR
Suggestion: Des Supa

Microsoft (microsoft) locked as resolved and limited conversation to collaborators Jul 28, 2022
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.


Back | FazBrowse Home | New Git URL