From 39c75fd438ba22371be0072effa9fe89731938ce Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Tue, 26 Jan 2016 15:34:53 -0800 Subject: [PATCH] Simplify giving error message and remove unnecessary error --- src/compiler/checker.ts | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 927e00faf8c..e52982576b6 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -11471,25 +11471,8 @@ namespace ts { const containingClassSymbol = getSymbolOfNode(containingClassDecl); const containingClassInstanceType = getDeclaredTypeOfSymbol(containingClassSymbol); const baseConstructorType = getBaseConstructorTypeOfClass(containingClassInstanceType); - const statements = (node.body).statements; - let superCallStatement: ExpressionStatement; - let isSuperCallFirstStatment: boolean; - for (const statement of statements) { - if (statement.kind === SyntaxKind.ExpressionStatement && isSuperCallExpression((statement).expression)) { - superCallStatement = 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 = (node.body).statements; + let superCallStatement: ExpressionStatement; + for (const statement of statements) { + if (statement.kind === SyntaxKind.ExpressionStatement && isSuperCallExpression((statement).expression)) { + superCallStatement = 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); } } }