Skip to content

Allow super call to not be the first statement when the class declaration contains property declaration with initialize or parameter property declaration #6908

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

Closed
yuit opened this issue Feb 4, 2016 · 1 comment
Labels
In Discussion Not yet reached consensus Suggestion An idea for TypeScript

Comments

@yuit
Copy link
Contributor

yuit commented Feb 4, 2016

Currently when class-declaration has property declaration with initialize and parameter property declaration, super call must be the first statement. So the following case is not valid

class B {}
class C extends B{
   blah = 2;
   constructor() {
       if (true) { super (); }
   }
}
class B {}
class C extends B{
   blah = 2;
   constructor() {
       let x = super();
   }
}

We should allow above cases as, @RyanCavanaugh points out in this comment for possible solutions.

Quoted from the comment:

  • If super(...) is in an expression statement whose parent is a control flow statement (i.g. if (true) super()), rewrite it as a block containing a super call and its initializers
  • If super(...) is in any other expression position, emit (super(...), this.prop1 = value1, this.prop2 = value2, ..., this)
@yuit yuit added the Suggestion An idea for TypeScript label Feb 4, 2016
@RyanCavanaugh RyanCavanaugh added the In Discussion Not yet reached consensus label Feb 4, 2016
@RyanCavanaugh
Copy link
Member

Closing due to lack of interest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
In Discussion Not yet reached consensus Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

2 participants