Address PR: report error on super call instead of entire constructor node

This commit is contained in:
Kanchalai Tanglertsampan
2016-02-11 10:11:39 -08:00
parent dc8e0ccd3d
commit 61e954bbc6
3 changed files with 14 additions and 23 deletions
+3 -3
View File
@@ -11886,10 +11886,10 @@ namespace ts {
const containingClassDecl = <ClassDeclaration>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
@@ -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 {
@@ -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;
}
}