This commit is contained in:
shyyko.serhiy@gmail.com
2015-07-17 20:54:14 +03:00
parent 07af6ca414
commit a756b561c5

View File

@@ -10260,7 +10260,8 @@ namespace ts {
if (getClassExtendsHeritageClauseElement(<ClassDeclaration>node.parent)) {
if (containsSuperCall(node.body)) {
// The first statement in the body of a constructor must be a super call if both of the following are true:
// The first statement in the body of a constructor must be a super call(or prologue directives followed by a super call)
// if both of the following are true:
// - The containing class is a derived class.
// - The constructor declares parameter properties
// or the containing class declares instance member variables with initializers.
@@ -10270,12 +10271,22 @@ namespace ts {
if (superCallShouldBeFirst) {
let statements = (<Block>node.body).statements;
if (!statements.length || statements[0].kind !== SyntaxKind.ExpressionStatement || !isSuperCallExpression((<ExpressionStatement>statements[0]).expression)) {
error(node, Diagnostics.A_super_call_must_be_the_first_statement_in_the_constructor_when_a_class_contains_initialized_properties_or_has_parameter_properties);
let superCallStatement: ExpressionStatement;
for (let i = 0; i < statements.length; i++) {
let statement = statements[i];
if (statement.kind === SyntaxKind.ExpressionStatement && isSuperCallExpression((<ExpressionStatement>statement).expression)) {
superCallStatement = <ExpressionStatement>statement;
break;
}
if (!isPrologueDirective(statement)) {
break;
}
}
else {
if (!superCallStatement) {
error(node, Diagnostics.A_super_call_must_be_the_first_statement_in_the_constructor_when_a_class_contains_initialized_properties_or_has_parameter_properties);
} else {
// In such a required super call, it is a compile-time error for argument expressions to reference this.
markThisReferencesAsErrors((<ExpressionStatement>statements[0]).expression);
markThisReferencesAsErrors(superCallStatement.expression);
}
}
}