mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-10 01:43:59 -05:00
fixed issue #3859
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user