From 61e954bbc6a18ae21609d93221672b34d238ce9a Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Thu, 11 Feb 2016 10:11:39 -0800 Subject: [PATCH] Address PR: report error on super call instead of entire constructor node --- src/compiler/checker.ts | 6 +++--- .../reference/classExtendsNull.errors.txt | 11 ++++------ .../superCallBeforeThisAccessing4.errors.txt | 20 +++++++------------ 3 files changed, 14 insertions(+), 23 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 4a824e3bbb4..67f200ceeb7 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -11886,10 +11886,10 @@ namespace ts { const containingClassDecl = node.parent; if (getClassExtendsHeritageClauseElement(containingClassDecl)) { const classExtendsNull = classDeclarationExtendsNull(containingClassDecl); - - if (getSuperCallInConstructor(node)) { + const superCall = getSuperCallInConstructor(node); + if (superCall) { if (classExtendsNull) { - error(node, Diagnostics.A_constructor_cannot_contain_a_super_call_when_its_class_extends_null); + error(superCall, Diagnostics.A_constructor_cannot_contain_a_super_call_when_its_class_extends_null); } // The first statement in the body of a constructor (excluding prologue directives) must be a super call diff --git a/tests/baselines/reference/classExtendsNull.errors.txt b/tests/baselines/reference/classExtendsNull.errors.txt index 7bb44774826..905c90c42fd 100644 --- a/tests/baselines/reference/classExtendsNull.errors.txt +++ b/tests/baselines/reference/classExtendsNull.errors.txt @@ -1,17 +1,14 @@ -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(3,9): error TS17005: A constructor cannot contain a 'super' call when its class extends 'null' ==== tests/cases/compiler/classExtendsNull.ts (1 errors) ==== class C extends null { constructor() { - ~~~~~~~~~~~~~~~ super(); - ~~~~~~~~~~~~~~~~ - return Object.create(null); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - } - ~~~~~ + ~~~~~~~ !!! error TS17005: A constructor cannot contain a 'super' call when its class extends 'null' + return Object.create(null); + } } class D extends null { diff --git a/tests/baselines/reference/superCallBeforeThisAccessing4.errors.txt b/tests/baselines/reference/superCallBeforeThisAccessing4.errors.txt index ca419b30858..91c3e7763f6 100644 --- a/tests/baselines/reference/superCallBeforeThisAccessing4.errors.txt +++ b/tests/baselines/reference/superCallBeforeThisAccessing4.errors.txt @@ -1,30 +1,24 @@ -tests/cases/conformance/es6/classDeclaration/superCallBeforeThisAccessing4.ts(3,5): error TS17005: A constructor cannot contain a 'super' call when its class extends 'null' -tests/cases/conformance/es6/classDeclaration/superCallBeforeThisAccessing4.ts(11,5): error TS17005: A constructor cannot contain a 'super' call when its class extends 'null' +tests/cases/conformance/es6/classDeclaration/superCallBeforeThisAccessing4.ts(5,9): error TS17005: A constructor cannot contain a 'super' call when its class extends 'null' +tests/cases/conformance/es6/classDeclaration/superCallBeforeThisAccessing4.ts(12,9): error TS17005: A constructor cannot contain a 'super' call when its class extends 'null' ==== tests/cases/conformance/es6/classDeclaration/superCallBeforeThisAccessing4.ts (2 errors) ==== class D extends null { private _t; constructor() { - ~~~~~~~~~~~~~~~ this._t; - ~~~~~~~~~~~~~~~~ super(); - ~~~~~~~~~~~~~~~~ - } - ~~~~~ + ~~~~~~~ !!! error TS17005: A constructor cannot contain a 'super' call when its class extends 'null' + } } class E extends null { private _t; constructor() { - ~~~~~~~~~~~~~~~ super(); - ~~~~~~~~~~~~~~~~ - this._t; - ~~~~~~~~~~~~~~~~ - } - ~~~~~ + ~~~~~~~ !!! error TS17005: A constructor cannot contain a 'super' call when its class extends 'null' + this._t; + } } \ No newline at end of file