mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-15 03:23:08 -06:00
Simplify giving error message and remove unnecessary error
This commit is contained in:
parent
c4ce6b85e0
commit
39c75fd438
@ -11471,25 +11471,8 @@ namespace ts {
|
||||
const containingClassSymbol = getSymbolOfNode(containingClassDecl);
|
||||
const containingClassInstanceType = <InterfaceType>getDeclaredTypeOfSymbol(containingClassSymbol);
|
||||
const baseConstructorType = getBaseConstructorTypeOfClass(containingClassInstanceType);
|
||||
const statements = (<Block>node.body).statements;
|
||||
let superCallStatement: ExpressionStatement;
|
||||
let isSuperCallFirstStatment: boolean;
|
||||
|
||||
for (const statement of statements) {
|
||||
if (statement.kind === SyntaxKind.ExpressionStatement && isSuperCallExpression((<ExpressionStatement>statement).expression)) {
|
||||
superCallStatement = <ExpressionStatement>statement;
|
||||
if (isSuperCallFirstStatment === undefined) {
|
||||
isSuperCallFirstStatment = true;
|
||||
}
|
||||
}
|
||||
else if (isSuperCallFirstStatment === undefined && !isPrologueDirective(statement)) {
|
||||
isSuperCallFirstStatment = false;
|
||||
}
|
||||
}
|
||||
|
||||
// The main different between looping through each statement in constructor and calling containsSuperCall is that,
|
||||
// containsSuperCall will consider "super" inside computed-property for inner class declaration
|
||||
if (superCallStatement || containsSuperCall(node.body)) {
|
||||
if (containsSuperCall(node.body)) {
|
||||
if (baseConstructorType === nullType) {
|
||||
error(node, Diagnostics.A_constructor_cannot_contain_a_super_call_when_its_class_extends_null);
|
||||
}
|
||||
@ -11506,12 +11489,19 @@ namespace ts {
|
||||
// Skip past any prologue directives to find the first statement
|
||||
// to ensure that it was a super call.
|
||||
if (superCallShouldBeFirst) {
|
||||
if (!isSuperCallFirstStatment) {
|
||||
error(superCallStatement, Diagnostics.A_super_call_must_be_the_first_statement_in_the_constructor_when_a_class_contains_initialized_properties_or_has_parameter_properties);
|
||||
const statements = (<Block>node.body).statements;
|
||||
let superCallStatement: ExpressionStatement;
|
||||
for (const statement of statements) {
|
||||
if (statement.kind === SyntaxKind.ExpressionStatement && isSuperCallExpression((<ExpressionStatement>statement).expression)) {
|
||||
superCallStatement = <ExpressionStatement>statement;
|
||||
break;
|
||||
}
|
||||
if (!isPrologueDirective(statement)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// In such a required super call, it is a compile-time error for argument expressions to reference this.
|
||||
markThisReferencesAsErrors(superCallStatement.expression);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user