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

Description

@yuit

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    In DiscussionNot yet reached consensusSuggestionAn idea for TypeScript

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions