Skip to content

Remove superCallShouldBeFirst error #37947

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 21, 2020

Conversation

sandersn
Copy link
Member

It seems redundant since TS gives an error on any use of this before super, and non-this uses before super should be fine.

Fixes #37371

It seems redundant since TS gives an error on any use of `this` before
super, and non-`this` uses before `super` should be fine.

Fixes #37371
@sandersn
Copy link
Member Author

#5833 (comment) from the original PR of the this error implies that it does make the blanket error redundant.

@rbuckton
Copy link
Contributor

Wasn't this error due to how our transform for properties works? If you allow any non-this statement before super in a class with property initializers then we could have issues:

// ts
class D {
    constructor(f: number) { }
}

class C extends D {
  x = 1;
  constructor(f: boolean) {
   if (f) { super(1); } else { super(2); }
  }
}

// es2015
"use strict";
class D {
    constructor(f) { }
}
class C extends D {
    constructor(f) {
        this.x = 1; // oops?!
        if (f) {
            super(1);
        }
        else {
            super(2);
        }
    }
}

@rbuckton
Copy link
Contributor

We would need to completely rewrite our class field emit transforms before we could remove this error.

@weswigham
Copy link
Member

We can remove this error when target is esnext though, right?

@sandersn
Copy link
Member Author

@weswigham esNext + useDefineForClassFields

@sandersn
Copy link
Member Author

All right, the change now just removes the error for esnext+useDefineForClassFields.

@sandersn
Copy link
Member Author

ping @weswigham @rbuckton to look at the reduced change.

@sandersn sandersn merged commit 6ea291a into master Apr 21, 2020
@sandersn sandersn deleted the remove-superCallShouldBeFirst-error branch April 21, 2020 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot compile when derived class has at least one #private field and constructor has statements before super()
4 participants