Skip to content

Relax the rule that ‘super’ call must be the first statement #945

Closed
@jbaron

Description

@jbaron

Right now the compiler always checks if a super call is made, it is indeed the first statement in the constructor. This is even true if the statements before the super call don’t access anything of the object just being constructed.

It would be nice to not allow access to object variables and methods but allow for other kind of statements. For example the following gives an warning:

constructor(name) {
    var filePath = someGlobalFunction(name); 
    super(filePath);
}

while the following is ok:

constructor(name) {
    super(someGlobalFunction(name));
}

Of course the sequence of commands in the above two example is the same (and one might argue that the second example is the less maintainable/debuggable code). So would be great if the first example wouldn't throw a compiler warning.

I guess the tricky part is to determine which statements are ok to be used before the super call. But I would assume if the statements don’t include this or super keywords, they should be ok.

Metadata

Metadata

Assignees

No one assigned

    Labels

    By DesignDeprecated - use "Working as Intended" or "Design Limitation" instead

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions