diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 0ccf23164cb..2932de8e99b 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10250,25 +10250,25 @@ namespace ts { // constructors of derived classes must contain at least one super call somewhere in their function body. let containingClassDecl = node.parent; if (getClassExtendsHeritageClauseElement(containingClassDecl)) { - let symbol = getSymbolOfNode(containingClassDecl); - let type = getDeclaredTypeOfSymbol(symbol); - let baseConstructorType = getBaseConstructorTypeOfClass(type); + let containingClassSymbol = getSymbolOfNode(containingClassDecl); + let containingClassInstanceType = getDeclaredTypeOfSymbol(containingClassSymbol); + let baseConstructorType = getBaseConstructorTypeOfClass(containingClassInstanceType); if (containsSuperCall(node.body)) { if (baseConstructorType === nullType) { - error(node, Diagnostics.A_constructor_cannot_contain_super_call_when_a_class_extends_null); + error(node, Diagnostics.A_constructor_cannot_contain_a_super_call_when_its_class_extends_null); } // The first statement in the body of a constructor must be 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. - let statements = (node.body).statements; let superCallShouldBeFirst = forEach((node.parent).members, isInstancePropertyWithInitializer) || forEach(node.parameters, p => p.flags & (NodeFlags.Public | NodeFlags.Private | NodeFlags.Protected)); if (superCallShouldBeFirst) { + let statements = (node.body).statements; if (!statements.length || statements[0].kind !== SyntaxKind.ExpressionStatement || !isSuperCallExpression((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); } diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 44f14ac0995..cdfe28eb781 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -613,6 +613,6 @@ namespace ts { Expected_corresponding_JSX_closing_tag_for_0: { code: 17002, category: DiagnosticCategory.Error, key: "Expected corresponding JSX closing tag for '{0}'." }, JSX_attribute_expected: { code: 17003, category: DiagnosticCategory.Error, key: "JSX attribute expected." }, Cannot_use_JSX_unless_the_jsx_flag_is_provided: { code: 17004, category: DiagnosticCategory.Error, key: "Cannot use JSX unless the '--jsx' flag is provided." }, - A_constructor_cannot_contain_super_call_when_a_class_extends_null: { code: 17005, category: DiagnosticCategory.Error, key: "A constructor cannot contain 'super' call when a class extends 'null'" }, + A_constructor_cannot_contain_a_super_call_when_its_class_extends_null: { code: 17005, category: DiagnosticCategory.Error, key: "A constructor cannot contain a 'super' call when its class extends 'null'" }, }; } \ No newline at end of file diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 1203c5ef61e..d0023ce6cfd 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1,4 +1,4 @@ -{ + { "Unterminated string literal.": { "category": "Error", "code": 1002 @@ -2446,7 +2446,7 @@ "category": "Error", "code": 17004 }, - "A constructor cannot contain 'super' call when a class extends 'null'": { + "A constructor cannot contain a 'super' call when its class extends 'null'": { "category": "Error", "code": 17005 } diff --git a/tests/baselines/reference/classExtendsNull.errors.txt b/tests/baselines/reference/classExtendsNull.errors.txt index cc5de5cda83..7bb44774826 100644 --- a/tests/baselines/reference/classExtendsNull.errors.txt +++ b/tests/baselines/reference/classExtendsNull.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/classExtendsNull.ts(2,5): error TS17005: A constructor cannot contain 'super' call when a class extends 'null' +tests/cases/compiler/classExtendsNull.ts(2,5): error TS17005: A constructor cannot contain a 'super' call when its class extends 'null' ==== tests/cases/compiler/classExtendsNull.ts (1 errors) ==== @@ -11,7 +11,7 @@ tests/cases/compiler/classExtendsNull.ts(2,5): error TS17005: A constructor cann ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ } ~~~~~ -!!! error TS17005: A constructor cannot contain 'super' call when a class extends 'null' +!!! error TS17005: A constructor cannot contain a 'super' call when its class extends 'null' } class D extends null {