mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Address PR: report error on super call instead of entire constructor node
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user