From 0684b841e3ee20ce3e68194cba5baa9d085d86b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Wed, 3 Apr 2024 10:29:51 +0200 Subject: [PATCH 1/3] Shorten error spans for errors reported on constructor declarations --- src/compiler/utilities.ts | 6 + tests/baselines/reference/bases.errors.txt | 6 +- .../reference/classUpdateTests.errors.txt | 2 +- ...ssWithTwoConstructorDefinitions.errors.txt | 8 +- .../constructorOverloads1.errors.txt | 12 +- .../constructorOverloads3.errors.txt | 2 +- .../constructorOverloads8.errors.txt | 4 +- ...lassConstructorWithoutSuperCall.errors.txt | 17 +-- ...derivedClassParameterProperties.errors.txt | 16 +-- .../derivedClassSuperProperties.errors.txt | 112 ++++-------------- .../illegalSuperCallsInConstructor.errors.txt | 17 +-- .../parserConstructorDeclaration12.errors.txt | 16 +-- .../reference/privateNameBadSuper.errors.txt | 7 +- .../reference/staticPropSuper.errors.txt | 18 +-- .../strictModeInConstructor.errors.txt | 9 +- ...superCallInsideClassDeclaration.errors.txt | 11 +- .../superCallInsideClassExpression.errors.txt | 11 +- .../superInConstructorParam1.errors.txt | 5 +- .../reference/superNewCall1.errors.txt | 6 +- ...ggedTemplatesWithTypeArguments2.errors.txt | 6 +- 20 files changed, 84 insertions(+), 207 deletions(-) diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index ddcb5c258dd37..956b9670c0749 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -2268,6 +2268,12 @@ export function getErrorSpanForNode(sourceFile: SourceFile, node: Node): TextSpa const pos = skipTrivia(sourceFile.text, (node as JSDocSatisfiesTag).tagName.pos); return getSpanOfTokenAtPosition(sourceFile, pos); } + case SyntaxKind.Constructor: { + const constructorDeclaration = node as ConstructorDeclaration; + const start = skipTrivia(sourceFile.text, constructorDeclaration.pos); + const end = constructorDeclaration.body ? constructorDeclaration.body.pos : constructorDeclaration.end; + return createTextSpanFromBounds(start, end); + } } if (errorNode === undefined) { diff --git a/tests/baselines/reference/bases.errors.txt b/tests/baselines/reference/bases.errors.txt index 15fa22555f7a1..236d9eb0fd042 100644 --- a/tests/baselines/reference/bases.errors.txt +++ b/tests/baselines/reference/bases.errors.txt @@ -35,9 +35,9 @@ bases.ts(18,9): error TS2339: Property 'y' does not exist on type 'C'. !!! error TS2420: Property 'x' is missing in type 'C' but required in type 'I'. !!! related TS2728 bases.ts:2:5: 'x' is declared here. constructor() { - ~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~ +!!! error TS2377: Constructors for derived classes must contain a 'super' call. this.x: any; - ~~~~~~~~~~~~~~~~~~~~ ~~~~ !!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. ~ @@ -47,8 +47,6 @@ bases.ts(18,9): error TS2339: Property 'y' does not exist on type 'C'. ~~~ !!! error TS2693: 'any' only refers to a type, but is being used as a value here. } - ~~~~~ -!!! error TS2377: Constructors for derived classes must contain a 'super' call. } new C().x; diff --git a/tests/baselines/reference/classUpdateTests.errors.txt b/tests/baselines/reference/classUpdateTests.errors.txt index b5196c0a72ece..17be50c8590c4 100644 --- a/tests/baselines/reference/classUpdateTests.errors.txt +++ b/tests/baselines/reference/classUpdateTests.errors.txt @@ -53,7 +53,7 @@ classUpdateTests.ts(113,1): error TS1128: Declaration or statement expected. class F extends E { constructor() {} // ERROR - super call required - ~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~ !!! error TS2377: Constructors for derived classes must contain a 'super' call. } diff --git a/tests/baselines/reference/classWithTwoConstructorDefinitions.errors.txt b/tests/baselines/reference/classWithTwoConstructorDefinitions.errors.txt index fed9eca4ba0c4..9e30d28d91741 100644 --- a/tests/baselines/reference/classWithTwoConstructorDefinitions.errors.txt +++ b/tests/baselines/reference/classWithTwoConstructorDefinitions.errors.txt @@ -7,18 +7,18 @@ classWithTwoConstructorDefinitions.ts(8,5): error TS2392: Multiple constructor i ==== classWithTwoConstructorDefinitions.ts (4 errors) ==== class C { constructor() { } // error - ~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~ !!! error TS2392: Multiple constructor implementations are not allowed. constructor(x) { } // error - ~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~ !!! error TS2392: Multiple constructor implementations are not allowed. } class D { constructor(x: T) { } // error - ~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~ !!! error TS2392: Multiple constructor implementations are not allowed. constructor(x: T, y: T) { } // error - ~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2392: Multiple constructor implementations are not allowed. } \ No newline at end of file diff --git a/tests/baselines/reference/constructorOverloads1.errors.txt b/tests/baselines/reference/constructorOverloads1.errors.txt index 6e4e62c845a88..ee94098d2eac4 100644 --- a/tests/baselines/reference/constructorOverloads1.errors.txt +++ b/tests/baselines/reference/constructorOverloads1.errors.txt @@ -23,19 +23,15 @@ constructorOverloads1.ts(17,18): error TS2769: No overload matches this call. ~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2392: Multiple constructor implementations are not allowed. constructor(x: any) { - ~~~~~~~~~~~~~~~~~~~~~ - + ~~~~~~~~~~~~~~~~~~~ +!!! error TS2392: Multiple constructor implementations are not allowed. } - ~~~~~ -!!! error TS2392: Multiple constructor implementations are not allowed. constructor(x: any) { - ~~~~~~~~~~~~~~~~~~~~~ - + ~~~~~~~~~~~~~~~~~~~ +!!! error TS2392: Multiple constructor implementations are not allowed. } - ~~~~~ -!!! error TS2392: Multiple constructor implementations are not allowed. bar1() { /*WScript.Echo("bar1");*/ } bar2() { /*WScript.Echo("bar1");*/ } } diff --git a/tests/baselines/reference/constructorOverloads3.errors.txt b/tests/baselines/reference/constructorOverloads3.errors.txt index 87bf615d33909..9b14a24c7e3ef 100644 --- a/tests/baselines/reference/constructorOverloads3.errors.txt +++ b/tests/baselines/reference/constructorOverloads3.errors.txt @@ -14,7 +14,7 @@ constructorOverloads3.ts(12,5): error TS2377: Constructors for derived classes m constructor(n: number); constructor(a: any); constructor(x: any, y?: any) { } - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2377: Constructors for derived classes must contain a 'super' call. bar1() { /*WScript.Echo("Yo");*/} } diff --git a/tests/baselines/reference/constructorOverloads8.errors.txt b/tests/baselines/reference/constructorOverloads8.errors.txt index 6ba44fea941cc..bc5ef93039f35 100644 --- a/tests/baselines/reference/constructorOverloads8.errors.txt +++ b/tests/baselines/reference/constructorOverloads8.errors.txt @@ -5,10 +5,10 @@ constructorOverloads8.ts(3,5): error TS2392: Multiple constructor implementation ==== constructorOverloads8.ts (2 errors) ==== class C { constructor(x) { } - ~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~ !!! error TS2392: Multiple constructor implementations are not allowed. constructor(y, x) { } // illegal, 2 constructor implementations - ~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~ !!! error TS2392: Multiple constructor implementations are not allowed. } diff --git a/tests/baselines/reference/derivedClassConstructorWithoutSuperCall.errors.txt b/tests/baselines/reference/derivedClassConstructorWithoutSuperCall.errors.txt index b4768cf8fb9bd..c36e7a86fc377 100644 --- a/tests/baselines/reference/derivedClassConstructorWithoutSuperCall.errors.txt +++ b/tests/baselines/reference/derivedClassConstructorWithoutSuperCall.errors.txt @@ -14,10 +14,9 @@ derivedClassConstructorWithoutSuperCall.ts(24,31): error TS2337: Super calls are class Derived extends Base { constructor() { // error - ~~~~~~~~~~~~~~~~~~~~~~~~ - } - ~~~~~ + ~~~~~~~~~~~~~ !!! error TS2377: Constructors for derived classes must contain a 'super' call. + } } class Base2 { @@ -26,26 +25,22 @@ derivedClassConstructorWithoutSuperCall.ts(24,31): error TS2337: Super calls are class Derived2 extends Base2 { constructor() { // error for no super call (nested scopes don't count) - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~ +!!! error TS2377: Constructors for derived classes must contain a 'super' call. var r2 = () => super(); // error for misplaced super call (nested function) - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~ !!! error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors. } - ~~~~~ -!!! error TS2377: Constructors for derived classes must contain a 'super' call. } class Derived3 extends Base2 { constructor() { // error - ~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~ +!!! error TS2377: Constructors for derived classes must contain a 'super' call. var r = function () { super() } // error - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~ !!! error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors. } - ~~~~~ -!!! error TS2377: Constructors for derived classes must contain a 'super' call. } class Derived4 extends Base2 { diff --git a/tests/baselines/reference/derivedClassParameterProperties.errors.txt b/tests/baselines/reference/derivedClassParameterProperties.errors.txt index a1567a94820f2..676445b55752f 100644 --- a/tests/baselines/reference/derivedClassParameterProperties.errors.txt +++ b/tests/baselines/reference/derivedClassParameterProperties.errors.txt @@ -66,20 +66,16 @@ derivedClassParameterProperties.ts(81,9): error TS17009: 'super' must be called a = 1; b: number; constructor(y: string) { - ~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. this.a = 3; - ~~~~~~~~~~~~~~~~~~~ ~~~~ !!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. this.b = 3; - ~~~~~~~~~~~~~~~~~~~ ~~~~ !!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. super(); - ~~~~~~~~~~~~~~~~ } - ~~~~~ -!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. } class Derived8 extends Base { @@ -99,20 +95,16 @@ derivedClassParameterProperties.ts(81,9): error TS17009: 'super' must be called a = 1; b: number; constructor(y: string) { - ~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. this.a = 3; - ~~~~~~~~~~~~~~~~~~~ ~~~~ !!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. this.b = 3; - ~~~~~~~~~~~~~~~~~~~ ~~~~ !!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. super(); - ~~~~~~~~~~~~~~~~ } - ~~~~~ -!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. } class Derived10 extends Base2 { diff --git a/tests/baselines/reference/derivedClassSuperProperties.errors.txt b/tests/baselines/reference/derivedClassSuperProperties.errors.txt index 66a260f0de2db..bac48cb54cd56 100644 --- a/tests/baselines/reference/derivedClassSuperProperties.errors.txt +++ b/tests/baselines/reference/derivedClassSuperProperties.errors.txt @@ -58,69 +58,57 @@ derivedClassSuperProperties.ts(397,21): error TS2401: A 'super' call must be a r class Derived1 extends Base { prop = true; constructor() { - ~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~ +!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. super.receivesAnything(); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~ !!! error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class. super(); - ~~~~~~~~~~~~~~~~ } - ~~~~~ -!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. } class Derived2 extends Base { prop = true; constructor() { - ~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~ +!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. super.receivesAnything(this); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~ !!! error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class. ~~~~ !!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. super(); - ~~~~~~~~~~~~~~~~ } - ~~~~~ -!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. } class Derived3 extends Base { prop = true; constructor() { - ~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~ +!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. super.receivesAnything(); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~ !!! error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class. super(this); - ~~~~~~~~~~~~~~~~~~~~ ~~~~ !!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. } - ~~~~~ -!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. } class Derived4 extends Base { prop = true; constructor() { - ~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~ +!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. super.receivesAnything(this); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~ !!! error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class. ~~~~ !!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. super(this); - ~~~~~~~~~~~~~~~~~~~~ ~~~~ !!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. } - ~~~~~ -!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. } class Derived5 extends Base { @@ -178,43 +166,31 @@ derivedClassSuperProperties.ts(397,21): error TS2401: A 'super' call must be a r class DerivedWithDecoratorOnClass extends Base { prop = true; constructor() { - ~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~ +!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. @decorate(this) - ~~~~~~~~~~~~~~~~~~~~~~~ ~~~~ !!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. class InnerClass { } - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - super(); - ~~~~~~~~~~~~~~~~ } - ~~~~~ -!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. } class DerivedWithDecoratorOnClassMethod extends Base { prop = true; constructor() { - ~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~ +!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. class InnerClass { - ~~~~~~~~~~~~~~~~~~~~~~~~~~ @decorate(this) - ~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~ !!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. innerMethod() { } - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ } - ~~~~~~~~~ - super(); - ~~~~~~~~~~~~~~~~ } - ~~~~~ -!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. } class DerivedWithDecoratorOnClassProperty extends Base { @@ -271,16 +247,13 @@ derivedClassSuperProperties.ts(397,21): error TS2401: A 'super' call must be a r class DerivedWithParenthesisAfterStatement extends Base { prop = true; constructor() { - ~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~ +!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. this.prop; - ~~~~~~~~~~~~~~~~~~ ~~~~ !!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. (super()); - ~~~~~~~~~~~~~~~~~~ } - ~~~~~ -!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. } class DerivedWithParenthesisBeforeStatement extends Base { @@ -311,36 +284,23 @@ derivedClassSuperProperties.ts(397,21): error TS2401: A 'super' call must be a r class DerivedWithClassDeclarationExtendingMember extends Base { memberClass = class { }; constructor() { - ~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~ +!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. class InnerClass extends this.memberClass { - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~ !!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. private method() { - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ return this; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ } - ~~~~~~~~~~~~~ private property = 7; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ constructor() { - ~~~~~~~~~~~~~~~~~~~~~~~~~~~ super(); - ~~~~~~~~~~~~~~~~~~~~~~~~ this.property; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ this.method(); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ } - ~~~~~~~~~~~~~ } - ~~~~~~~~~ super(); - ~~~~~~~~~~~~~~~~ } - ~~~~~ -!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. } class DerivedWithClassExpression extends Base { @@ -363,16 +323,13 @@ derivedClassSuperProperties.ts(397,21): error TS2401: A 'super' call must be a r class DerivedWithClassExpressionExtendingMember extends Base { memberClass = class { }; constructor() { - ~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~ +!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. console.log(class extends this.memberClass { }); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~ !!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. super(); - ~~~~~~~~~~~~~~~~ } - ~~~~~ -!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. } class DerivedWithDerivedClassExpression extends Base { @@ -421,34 +378,23 @@ derivedClassSuperProperties.ts(397,21): error TS2401: A 'super' call must be a r class DerivedWithObjectAccessorsUsingThisInKeys extends Base { propName = "prop"; constructor() { - ~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~ +!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. const obj = { - ~~~~~~~~~~~~~~~~~~~~~ _prop: "prop", - ~~~~~~~~~~~~~~~~~~~~~~~~~~ get [this.propName]() { - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~ !!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. return true; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ }, - ~~~~~~~~~~~~~~ set [this.propName](param) { - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~ !!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. this._prop = param; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ } - ~~~~~~~~~~~~~ }; - ~~~~~~~~~~ super(); - ~~~~~~~~~~~~~~~~ } - ~~~~~ -!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. } class DerivedWithObjectAccessorsUsingThisInBodies extends Base { @@ -470,39 +416,29 @@ derivedClassSuperProperties.ts(397,21): error TS2401: A 'super' call must be a r class DerivedWithObjectComputedPropertyBody extends Base { propName = "prop"; constructor() { - ~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~ +!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. const obj = { - ~~~~~~~~~~~~~~~~~~~~~ prop: this.propName, - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~ !!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. }; - ~~~~~~~~~~ super(); - ~~~~~~~~~~~~~~~~ } - ~~~~~ -!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. } class DerivedWithObjectComputedPropertyName extends Base { propName = "prop"; constructor() { - ~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~ +!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. const obj = { - ~~~~~~~~~~~~~~~~~~~~~ [this.propName]: true, - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~ !!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. }; - ~~~~~~~~~~ super(); - ~~~~~~~~~~~~~~~~ } - ~~~~~ -!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. } class DerivedWithObjectMethod extends Base { diff --git a/tests/baselines/reference/illegalSuperCallsInConstructor.errors.txt b/tests/baselines/reference/illegalSuperCallsInConstructor.errors.txt index 61893ce4aae6b..f076a820ef923 100644 --- a/tests/baselines/reference/illegalSuperCallsInConstructor.errors.txt +++ b/tests/baselines/reference/illegalSuperCallsInConstructor.errors.txt @@ -13,42 +13,29 @@ illegalSuperCallsInConstructor.ts(16,17): error TS2337: Super calls are not perm class Derived extends Base { constructor() { - ~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~ +!!! error TS2377: Constructors for derived classes must contain a 'super' call. var r2 = () => super(); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~ !!! error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors. var r3 = () => { super(); } - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~ !!! error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors. var r4 = function () { super(); } - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~ !!! error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors. var r5 = { - ~~~~~~~~~~~~~~~~~~ get foo() { - ~~~~~~~~~~~~~~~~~~~~~~~ super(); - ~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~ !!! error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors. return 1; - ~~~~~~~~~~~~~~~~~~~~~~~~~ }, - ~~~~~~~~~~~~~~ set foo(v: number) { - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ super(); - ~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~ !!! error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors. } - ~~~~~~~~~~~~~ } - ~~~~~~~~~ } - ~~~~~ -!!! error TS2377: Constructors for derived classes must contain a 'super' call. } \ No newline at end of file diff --git a/tests/baselines/reference/parserConstructorDeclaration12.errors.txt b/tests/baselines/reference/parserConstructorDeclaration12.errors.txt index e54de48d630cc..6dcdb24fe052f 100644 --- a/tests/baselines/reference/parserConstructorDeclaration12.errors.txt +++ b/tests/baselines/reference/parserConstructorDeclaration12.errors.txt @@ -27,56 +27,56 @@ parserConstructorDeclaration12.ts(9,16): error TS1092: Type parameters cannot ap ==== parserConstructorDeclaration12.ts (24 errors) ==== class C { constructor<>() { } - ~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~ !!! error TS2392: Multiple constructor implementations are not allowed. ~~ !!! error TS1098: Type parameter list cannot be empty. !!! error TS1092: Type parameters cannot appear on a constructor declaration. constructor<> () { } - ~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~ !!! error TS2392: Multiple constructor implementations are not allowed. ~~ !!! error TS1098: Type parameter list cannot be empty. !!! error TS1092: Type parameters cannot appear on a constructor declaration. constructor <>() { } - ~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~ !!! error TS2392: Multiple constructor implementations are not allowed. ~~ !!! error TS1098: Type parameter list cannot be empty. !!! error TS1092: Type parameters cannot appear on a constructor declaration. constructor <> () { } - ~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~ !!! error TS2392: Multiple constructor implementations are not allowed. ~~ !!! error TS1098: Type parameter list cannot be empty. !!! error TS1092: Type parameters cannot appear on a constructor declaration. constructor< >() { } - ~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~ !!! error TS2392: Multiple constructor implementations are not allowed. ~~~ !!! error TS1098: Type parameter list cannot be empty. !!! error TS1092: Type parameters cannot appear on a constructor declaration. constructor< > () { } - ~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~ !!! error TS2392: Multiple constructor implementations are not allowed. ~~~ !!! error TS1098: Type parameter list cannot be empty. !!! error TS1092: Type parameters cannot appear on a constructor declaration. constructor < >() { } - ~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~ !!! error TS2392: Multiple constructor implementations are not allowed. ~~~ !!! error TS1098: Type parameter list cannot be empty. !!! error TS1092: Type parameters cannot appear on a constructor declaration. constructor < > () { } - ~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~ !!! error TS2392: Multiple constructor implementations are not allowed. ~~~ !!! error TS1098: Type parameter list cannot be empty. diff --git a/tests/baselines/reference/privateNameBadSuper.errors.txt b/tests/baselines/reference/privateNameBadSuper.errors.txt index 93b1af7a084bd..7c76ed949f254 100644 --- a/tests/baselines/reference/privateNameBadSuper.errors.txt +++ b/tests/baselines/reference/privateNameBadSuper.errors.txt @@ -7,14 +7,11 @@ privateNameBadSuper.ts(5,5): error TS17009: 'super' must be called before access class A extends B { #x; constructor() { - ~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~ +!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. this; - ~~~~~~~~~ ~~~~ !!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. super(); - ~~~~~~~~~~~~ } - ~~~ -!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. } \ No newline at end of file diff --git a/tests/baselines/reference/staticPropSuper.errors.txt b/tests/baselines/reference/staticPropSuper.errors.txt index c6a587af01eac..2ede952c5f7d9 100644 --- a/tests/baselines/reference/staticPropSuper.errors.txt +++ b/tests/baselines/reference/staticPropSuper.errors.txt @@ -20,34 +20,28 @@ staticPropSuper.ts(32,5): error TS2377: Constructors for derived classes must co public p: number = 10; constructor() { - ~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~ +!!! error TS2377: Constructors for derived classes must contain a 'super' call. var x = 1; // should error - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ } - ~~~~~ -!!! error TS2377: Constructors for derived classes must contain a 'super' call. } class D extends A { private p: number = 11; constructor() { - ~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~ +!!! error TS2377: Constructors for derived classes must contain a 'super' call. var x = 1; // should error - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ } - ~~~~~ -!!! error TS2377: Constructors for derived classes must contain a 'super' call. } class E extends A { p: number = 12; constructor() { - ~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~ +!!! error TS2377: Constructors for derived classes must contain a 'super' call. var x = 1; // should error - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ } - ~~~~~ -!!! error TS2377: Constructors for derived classes must contain a 'super' call. } \ No newline at end of file diff --git a/tests/baselines/reference/strictModeInConstructor.errors.txt b/tests/baselines/reference/strictModeInConstructor.errors.txt index e65ab0b2403f4..fa9fba9332666 100644 --- a/tests/baselines/reference/strictModeInConstructor.errors.txt +++ b/tests/baselines/reference/strictModeInConstructor.errors.txt @@ -30,20 +30,15 @@ strictModeInConstructor.ts(29,17): error TS17009: 'super' must be called before public s: number = 9; constructor () { - ~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~ +!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. var x = 1; // No error - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var y = this.s; // Error - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~ !!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. super(); - ~~~~~~~~~~~~~~~~ "use strict"; - ~~~~~~~~~~~~~~~~~~~~~ } - ~~~~~ -!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. } class Bs extends A { diff --git a/tests/baselines/reference/superCallInsideClassDeclaration.errors.txt b/tests/baselines/reference/superCallInsideClassDeclaration.errors.txt index 4c1abf0f43427..55034c56dc770 100644 --- a/tests/baselines/reference/superCallInsideClassDeclaration.errors.txt +++ b/tests/baselines/reference/superCallInsideClassDeclaration.errors.txt @@ -10,20 +10,13 @@ superCallInsideClassDeclaration.ts(8,5): error TS2377: Constructors for derived class B extends A { constructor() { - ~~~~~~~~~~~~~~~ - + ~~~~~~~~~~~~~ +!!! error TS2377: Constructors for derived classes must contain a 'super' call. class D extends C { - ~~~~~~~~~~~~~~~~~~~~~~~~~~~ constructor() { - ~~~~~~~~~~~~~~~~~~~~~~~~~~~ super(); - ~~~~~~~~~~~~~~~~~~~~~~~~ } - ~~~~~~~~~~~~~ } - ~~~~~~~~~ } - ~~~~~ -!!! error TS2377: Constructors for derived classes must contain a 'super' call. } \ No newline at end of file diff --git a/tests/baselines/reference/superCallInsideClassExpression.errors.txt b/tests/baselines/reference/superCallInsideClassExpression.errors.txt index 07461228ac72a..ae97af2301b5f 100644 --- a/tests/baselines/reference/superCallInsideClassExpression.errors.txt +++ b/tests/baselines/reference/superCallInsideClassExpression.errors.txt @@ -10,20 +10,13 @@ superCallInsideClassExpression.ts(8,5): error TS2377: Constructors for derived c class B extends A { constructor() { - ~~~~~~~~~~~~~~~ - + ~~~~~~~~~~~~~ +!!! error TS2377: Constructors for derived classes must contain a 'super' call. var D = class extends C { - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ constructor() { - ~~~~~~~~~~~~~~~~~~~~~~~~~~~ super(); - ~~~~~~~~~~~~~~~~~~~~~~~~ } - ~~~~~~~~~~~~~ } - ~~~~~~~~~ } - ~~~~~ -!!! error TS2377: Constructors for derived classes must contain a 'super' call. } \ No newline at end of file diff --git a/tests/baselines/reference/superInConstructorParam1.errors.txt b/tests/baselines/reference/superInConstructorParam1.errors.txt index 9788087d35299..ef5896fde7ecb 100644 --- a/tests/baselines/reference/superInConstructorParam1.errors.txt +++ b/tests/baselines/reference/superInConstructorParam1.errors.txt @@ -12,12 +12,11 @@ superInConstructorParam1.ts(8,19): error TS17011: 'super' must be called before class C extends B { constructor(a = super.foo()) { - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2377: Constructors for derived classes must contain a 'super' call. ~~~~~ !!! error TS2336: 'super' cannot be referenced in constructor arguments. ~~~~~ !!! error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class. } - ~~~ -!!! error TS2377: Constructors for derived classes must contain a 'super' call. } \ No newline at end of file diff --git a/tests/baselines/reference/superNewCall1.errors.txt b/tests/baselines/reference/superNewCall1.errors.txt index f7e882c42d4a6..404d3d7766c2d 100644 --- a/tests/baselines/reference/superNewCall1.errors.txt +++ b/tests/baselines/reference/superNewCall1.errors.txt @@ -13,15 +13,13 @@ superNewCall1.ts(9,13): error TS17011: 'super' must be called before accessing a class B extends A { constructor() { - ~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~ +!!! error TS2377: Constructors for derived classes must contain a 'super' call. new super(value => String(value)); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~ !!! error TS2351: This expression is not constructable. !!! error TS2351: Type 'A' has no construct signatures. ~~~~~ !!! error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class. } - ~~~~~ -!!! error TS2377: Constructors for derived classes must contain a 'super' call. } \ No newline at end of file diff --git a/tests/baselines/reference/taggedTemplatesWithTypeArguments2.errors.txt b/tests/baselines/reference/taggedTemplatesWithTypeArguments2.errors.txt index 351c108a20c88..b48a2861753ba 100644 --- a/tests/baselines/reference/taggedTemplatesWithTypeArguments2.errors.txt +++ b/tests/baselines/reference/taggedTemplatesWithTypeArguments2.errors.txt @@ -49,9 +49,9 @@ taggedTemplatesWithTypeArguments2.ts(36,34): error TS1034: 'super' must be follo class SomeDerived extends SomeBase { constructor() { - ~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~ +!!! error TS2377: Constructors for derived classes must contain a 'super' call. super `hello world`; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~ !!! error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class. ~~~~~~~~~~~~~~~~~~~ @@ -59,6 +59,4 @@ taggedTemplatesWithTypeArguments2.ts(36,34): error TS1034: 'super' must be follo ~~~~~~~~~~~~~ !!! error TS1034: 'super' must be followed by an argument list or member access. } - ~~~~~ -!!! error TS2377: Constructors for derived classes must contain a 'super' call. } \ No newline at end of file From d39f029513ceccfe0551593e1dea4524dc317928 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Wed, 3 Apr 2024 20:53:59 +0200 Subject: [PATCH 2/3] avoid highlighting constructor parameters --- src/compiler/utilities.ts | 6 ++++- .../reference/ClassDeclaration10.errors.txt | 2 +- .../reference/ClassDeclaration11.errors.txt | 2 +- .../reference/ClassDeclaration14.errors.txt | 2 +- .../reference/ClassDeclaration8.errors.txt | 2 +- tests/baselines/reference/bases.errors.txt | 2 +- ...nstructorOverloadsAccessibility.errors.txt | 6 ++--- .../reference/classUpdateTests.errors.txt | 2 +- ...ssWithTwoConstructorDefinitions.errors.txt | 8 +++---- .../constructorOverloads1.errors.txt | 8 +++---- .../constructorOverloads3.errors.txt | 2 +- .../constructorOverloads8.errors.txt | 4 ++-- ...torWithIncompleteTypeAnnotation.errors.txt | 2 +- ...uctorsWithSpecializedSignatures.errors.txt | 4 ++-- ...lassConstructorWithoutSuperCall.errors.txt | 6 ++--- ...derivedClassParameterProperties.errors.txt | 4 ++-- .../derivedClassSuperProperties.errors.txt | 24 +++++++++---------- .../reference/externModule.errors.txt | 2 +- .../illegalSuperCallsInConstructor.errors.txt | 2 +- ...lationConstructorOverloadSyntax.errors.txt | 2 +- ...parameterPropertyInConstructor2.errors.txt | 2 +- .../parserClassDeclaration10.errors.txt | 2 +- .../parserClassDeclaration11.errors.txt | 2 +- .../parserClassDeclaration12.errors.txt | 2 +- .../parserClassDeclaration14.errors.txt | 2 +- .../parserClassDeclaration8.errors.txt | 2 +- .../parserConstructorDeclaration12.errors.txt | 16 ++++++------- .../parserConstructorDeclaration8.errors.txt | 2 +- .../parserParameterList17.errors.txt | 2 +- .../reference/privateNameBadSuper.errors.txt | 2 +- .../reference/staticPropSuper.errors.txt | 6 ++--- .../strictModeInConstructor.errors.txt | 2 +- ...superCallInsideClassDeclaration.errors.txt | 2 +- .../superCallInsideClassExpression.errors.txt | 2 +- .../superInConstructorParam1.errors.txt | 2 +- .../reference/superNewCall1.errors.txt | 2 +- ...ggedTemplatesWithTypeArguments2.errors.txt | 2 +- 37 files changed, 74 insertions(+), 70 deletions(-) diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 956b9670c0749..40c746a4b5903 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -2271,7 +2271,11 @@ export function getErrorSpanForNode(sourceFile: SourceFile, node: Node): TextSpa case SyntaxKind.Constructor: { const constructorDeclaration = node as ConstructorDeclaration; const start = skipTrivia(sourceFile.text, constructorDeclaration.pos); - const end = constructorDeclaration.body ? constructorDeclaration.body.pos : constructorDeclaration.end; + const scanner = createScanner(sourceFile.languageVersion, /*skipTrivia*/ true, sourceFile.languageVariant, sourceFile.text, /*onError*/ undefined, start); + while (scanner.scan() !== SyntaxKind.ConstructorKeyword) { + // empty + } + const end = scanner.getTokenEnd(); return createTextSpanFromBounds(start, end); } } diff --git a/tests/baselines/reference/ClassDeclaration10.errors.txt b/tests/baselines/reference/ClassDeclaration10.errors.txt index ebc91c539e4af..075caf1c37cd9 100644 --- a/tests/baselines/reference/ClassDeclaration10.errors.txt +++ b/tests/baselines/reference/ClassDeclaration10.errors.txt @@ -5,7 +5,7 @@ ClassDeclaration10.ts(3,4): error TS2391: Function implementation is missing or ==== ClassDeclaration10.ts (2 errors) ==== class C { constructor(); - ~~~~~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS2390: Constructor implementation is missing. foo(); ~~~ diff --git a/tests/baselines/reference/ClassDeclaration11.errors.txt b/tests/baselines/reference/ClassDeclaration11.errors.txt index eacd2e9232ac6..a87f145f251e2 100644 --- a/tests/baselines/reference/ClassDeclaration11.errors.txt +++ b/tests/baselines/reference/ClassDeclaration11.errors.txt @@ -4,7 +4,7 @@ ClassDeclaration11.ts(2,4): error TS2390: Constructor implementation is missing. ==== ClassDeclaration11.ts (1 errors) ==== class C { constructor(); - ~~~~~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS2390: Constructor implementation is missing. foo() { } } \ No newline at end of file diff --git a/tests/baselines/reference/ClassDeclaration14.errors.txt b/tests/baselines/reference/ClassDeclaration14.errors.txt index 1a7020aa80172..33343f68462c9 100644 --- a/tests/baselines/reference/ClassDeclaration14.errors.txt +++ b/tests/baselines/reference/ClassDeclaration14.errors.txt @@ -8,6 +8,6 @@ ClassDeclaration14.ts(3,4): error TS2390: Constructor implementation is missing. ~~~ !!! error TS2391: Function implementation is missing or not immediately following the declaration. constructor(); - ~~~~~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS2390: Constructor implementation is missing. } \ No newline at end of file diff --git a/tests/baselines/reference/ClassDeclaration8.errors.txt b/tests/baselines/reference/ClassDeclaration8.errors.txt index 020e404630486..9e36ff75e6970 100644 --- a/tests/baselines/reference/ClassDeclaration8.errors.txt +++ b/tests/baselines/reference/ClassDeclaration8.errors.txt @@ -4,6 +4,6 @@ ClassDeclaration8.ts(2,3): error TS2390: Constructor implementation is missing. ==== ClassDeclaration8.ts (1 errors) ==== class C { constructor(); - ~~~~~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS2390: Constructor implementation is missing. } \ No newline at end of file diff --git a/tests/baselines/reference/bases.errors.txt b/tests/baselines/reference/bases.errors.txt index 236d9eb0fd042..db6a52a66e0da 100644 --- a/tests/baselines/reference/bases.errors.txt +++ b/tests/baselines/reference/bases.errors.txt @@ -35,7 +35,7 @@ bases.ts(18,9): error TS2339: Property 'y' does not exist on type 'C'. !!! error TS2420: Property 'x' is missing in type 'C' but required in type 'I'. !!! related TS2728 bases.ts:2:5: 'x' is declared here. constructor() { - ~~~~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS2377: Constructors for derived classes must contain a 'super' call. this.x: any; ~~~~ diff --git a/tests/baselines/reference/classConstructorOverloadsAccessibility.errors.txt b/tests/baselines/reference/classConstructorOverloadsAccessibility.errors.txt index 9babc77eb3e25..e939262b027ef 100644 --- a/tests/baselines/reference/classConstructorOverloadsAccessibility.errors.txt +++ b/tests/baselines/reference/classConstructorOverloadsAccessibility.errors.txt @@ -6,10 +6,10 @@ classConstructorOverloadsAccessibility.ts(11,2): error TS2385: Overload signatur ==== classConstructorOverloadsAccessibility.ts (3 errors) ==== class A { public constructor(a: boolean) // error - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~ !!! error TS2385: Overload signatures must all be public, private or protected. protected constructor(a: number) // error - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~~~~ !!! error TS2385: Overload signatures must all be public, private or protected. private constructor(a: string) private constructor() { @@ -19,7 +19,7 @@ classConstructorOverloadsAccessibility.ts(11,2): error TS2385: Overload signatur class B { protected constructor(a: number) // error - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~~~~ !!! error TS2385: Overload signatures must all be public, private or protected. constructor(a: string) constructor() { diff --git a/tests/baselines/reference/classUpdateTests.errors.txt b/tests/baselines/reference/classUpdateTests.errors.txt index 17be50c8590c4..dc7623218a2f5 100644 --- a/tests/baselines/reference/classUpdateTests.errors.txt +++ b/tests/baselines/reference/classUpdateTests.errors.txt @@ -53,7 +53,7 @@ classUpdateTests.ts(113,1): error TS1128: Declaration or statement expected. class F extends E { constructor() {} // ERROR - super call required - ~~~~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS2377: Constructors for derived classes must contain a 'super' call. } diff --git a/tests/baselines/reference/classWithTwoConstructorDefinitions.errors.txt b/tests/baselines/reference/classWithTwoConstructorDefinitions.errors.txt index 9e30d28d91741..fb2d0cb109c9b 100644 --- a/tests/baselines/reference/classWithTwoConstructorDefinitions.errors.txt +++ b/tests/baselines/reference/classWithTwoConstructorDefinitions.errors.txt @@ -7,18 +7,18 @@ classWithTwoConstructorDefinitions.ts(8,5): error TS2392: Multiple constructor i ==== classWithTwoConstructorDefinitions.ts (4 errors) ==== class C { constructor() { } // error - ~~~~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS2392: Multiple constructor implementations are not allowed. constructor(x) { } // error - ~~~~~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS2392: Multiple constructor implementations are not allowed. } class D { constructor(x: T) { } // error - ~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS2392: Multiple constructor implementations are not allowed. constructor(x: T, y: T) { } // error - ~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS2392: Multiple constructor implementations are not allowed. } \ No newline at end of file diff --git a/tests/baselines/reference/constructorOverloads1.errors.txt b/tests/baselines/reference/constructorOverloads1.errors.txt index ee94098d2eac4..2fee0e1ee2d6f 100644 --- a/tests/baselines/reference/constructorOverloads1.errors.txt +++ b/tests/baselines/reference/constructorOverloads1.errors.txt @@ -17,18 +17,18 @@ constructorOverloads1.ts(17,18): error TS2769: No overload matches this call. ==== constructorOverloads1.ts (6 errors) ==== class Foo { constructor(s: string); - ~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS2392: Multiple constructor implementations are not allowed. constructor(n: number); - ~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS2392: Multiple constructor implementations are not allowed. constructor(x: any) { - ~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS2392: Multiple constructor implementations are not allowed. } constructor(x: any) { - ~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS2392: Multiple constructor implementations are not allowed. } diff --git a/tests/baselines/reference/constructorOverloads3.errors.txt b/tests/baselines/reference/constructorOverloads3.errors.txt index 9b14a24c7e3ef..f9318331ce86c 100644 --- a/tests/baselines/reference/constructorOverloads3.errors.txt +++ b/tests/baselines/reference/constructorOverloads3.errors.txt @@ -14,7 +14,7 @@ constructorOverloads3.ts(12,5): error TS2377: Constructors for derived classes m constructor(n: number); constructor(a: any); constructor(x: any, y?: any) { } - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS2377: Constructors for derived classes must contain a 'super' call. bar1() { /*WScript.Echo("Yo");*/} } diff --git a/tests/baselines/reference/constructorOverloads8.errors.txt b/tests/baselines/reference/constructorOverloads8.errors.txt index bc5ef93039f35..cef0dee609379 100644 --- a/tests/baselines/reference/constructorOverloads8.errors.txt +++ b/tests/baselines/reference/constructorOverloads8.errors.txt @@ -5,10 +5,10 @@ constructorOverloads8.ts(3,5): error TS2392: Multiple constructor implementation ==== constructorOverloads8.ts (2 errors) ==== class C { constructor(x) { } - ~~~~~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS2392: Multiple constructor implementations are not allowed. constructor(y, x) { } // illegal, 2 constructor implementations - ~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS2392: Multiple constructor implementations are not allowed. } diff --git a/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.errors.txt b/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.errors.txt index 38f87bccc06d1..fcdb9edc337d7 100644 --- a/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.errors.txt +++ b/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.errors.txt @@ -476,7 +476,7 @@ constructorWithIncompleteTypeAnnotation.ts(261,1): error TS1128: Declaration or private otherValue = 42; constructor(private value: number, public name: string) : } - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS2390: Constructor implementation is missing. ~~~~~~~~~~~~~~~~~~~~~ !!! error TS2369: A parameter property is only allowed in a constructor implementation. diff --git a/tests/baselines/reference/constructorsWithSpecializedSignatures.errors.txt b/tests/baselines/reference/constructorsWithSpecializedSignatures.errors.txt index a712cab4561c9..52fe872f678ce 100644 --- a/tests/baselines/reference/constructorsWithSpecializedSignatures.errors.txt +++ b/tests/baselines/reference/constructorsWithSpecializedSignatures.errors.txt @@ -21,7 +21,7 @@ constructorsWithSpecializedSignatures.ts(26,5): error TS2394: This overload sign class D { constructor(x: "hi"); constructor(x: "foo"); - ~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS2394: This overload signature is not compatible with its implementation signature. !!! related TS2750 constructorsWithSpecializedSignatures.ts:20:5: The implementation signature is declared here. constructor(x: number); @@ -32,7 +32,7 @@ constructorsWithSpecializedSignatures.ts(26,5): error TS2394: This overload sign class D2 { constructor(x: "hi"); constructor(x: "foo"); - ~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS2394: This overload signature is not compatible with its implementation signature. !!! related TS2750 constructorsWithSpecializedSignatures.ts:28:5: The implementation signature is declared here. constructor(x: string); diff --git a/tests/baselines/reference/derivedClassConstructorWithoutSuperCall.errors.txt b/tests/baselines/reference/derivedClassConstructorWithoutSuperCall.errors.txt index c36e7a86fc377..6a22220c8dcc1 100644 --- a/tests/baselines/reference/derivedClassConstructorWithoutSuperCall.errors.txt +++ b/tests/baselines/reference/derivedClassConstructorWithoutSuperCall.errors.txt @@ -14,7 +14,7 @@ derivedClassConstructorWithoutSuperCall.ts(24,31): error TS2337: Super calls are class Derived extends Base { constructor() { // error - ~~~~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS2377: Constructors for derived classes must contain a 'super' call. } } @@ -25,7 +25,7 @@ derivedClassConstructorWithoutSuperCall.ts(24,31): error TS2337: Super calls are class Derived2 extends Base2 { constructor() { // error for no super call (nested scopes don't count) - ~~~~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS2377: Constructors for derived classes must contain a 'super' call. var r2 = () => super(); // error for misplaced super call (nested function) ~~~~~ @@ -35,7 +35,7 @@ derivedClassConstructorWithoutSuperCall.ts(24,31): error TS2337: Super calls are class Derived3 extends Base2 { constructor() { // error - ~~~~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS2377: Constructors for derived classes must contain a 'super' call. var r = function () { super() } // error ~~~~~ diff --git a/tests/baselines/reference/derivedClassParameterProperties.errors.txt b/tests/baselines/reference/derivedClassParameterProperties.errors.txt index 676445b55752f..1e6003d931fb1 100644 --- a/tests/baselines/reference/derivedClassParameterProperties.errors.txt +++ b/tests/baselines/reference/derivedClassParameterProperties.errors.txt @@ -66,7 +66,7 @@ derivedClassParameterProperties.ts(81,9): error TS17009: 'super' must be called a = 1; b: number; constructor(y: string) { - ~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. this.a = 3; ~~~~ @@ -95,7 +95,7 @@ derivedClassParameterProperties.ts(81,9): error TS17009: 'super' must be called a = 1; b: number; constructor(y: string) { - ~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. this.a = 3; ~~~~ diff --git a/tests/baselines/reference/derivedClassSuperProperties.errors.txt b/tests/baselines/reference/derivedClassSuperProperties.errors.txt index bac48cb54cd56..4a43554ff1ab1 100644 --- a/tests/baselines/reference/derivedClassSuperProperties.errors.txt +++ b/tests/baselines/reference/derivedClassSuperProperties.errors.txt @@ -58,7 +58,7 @@ derivedClassSuperProperties.ts(397,21): error TS2401: A 'super' call must be a r class Derived1 extends Base { prop = true; constructor() { - ~~~~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. super.receivesAnything(); ~~~~~ @@ -70,7 +70,7 @@ derivedClassSuperProperties.ts(397,21): error TS2401: A 'super' call must be a r class Derived2 extends Base { prop = true; constructor() { - ~~~~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. super.receivesAnything(this); ~~~~~ @@ -84,7 +84,7 @@ derivedClassSuperProperties.ts(397,21): error TS2401: A 'super' call must be a r class Derived3 extends Base { prop = true; constructor() { - ~~~~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. super.receivesAnything(); ~~~~~ @@ -98,7 +98,7 @@ derivedClassSuperProperties.ts(397,21): error TS2401: A 'super' call must be a r class Derived4 extends Base { prop = true; constructor() { - ~~~~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. super.receivesAnything(this); ~~~~~ @@ -166,7 +166,7 @@ derivedClassSuperProperties.ts(397,21): error TS2401: A 'super' call must be a r class DerivedWithDecoratorOnClass extends Base { prop = true; constructor() { - ~~~~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. @decorate(this) ~~~~ @@ -180,7 +180,7 @@ derivedClassSuperProperties.ts(397,21): error TS2401: A 'super' call must be a r class DerivedWithDecoratorOnClassMethod extends Base { prop = true; constructor() { - ~~~~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. class InnerClass { @decorate(this) @@ -247,7 +247,7 @@ derivedClassSuperProperties.ts(397,21): error TS2401: A 'super' call must be a r class DerivedWithParenthesisAfterStatement extends Base { prop = true; constructor() { - ~~~~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. this.prop; ~~~~ @@ -284,7 +284,7 @@ derivedClassSuperProperties.ts(397,21): error TS2401: A 'super' call must be a r class DerivedWithClassDeclarationExtendingMember extends Base { memberClass = class { }; constructor() { - ~~~~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. class InnerClass extends this.memberClass { ~~~~ @@ -323,7 +323,7 @@ derivedClassSuperProperties.ts(397,21): error TS2401: A 'super' call must be a r class DerivedWithClassExpressionExtendingMember extends Base { memberClass = class { }; constructor() { - ~~~~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. console.log(class extends this.memberClass { }); ~~~~ @@ -378,7 +378,7 @@ derivedClassSuperProperties.ts(397,21): error TS2401: A 'super' call must be a r class DerivedWithObjectAccessorsUsingThisInKeys extends Base { propName = "prop"; constructor() { - ~~~~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. const obj = { _prop: "prop", @@ -416,7 +416,7 @@ derivedClassSuperProperties.ts(397,21): error TS2401: A 'super' call must be a r class DerivedWithObjectComputedPropertyBody extends Base { propName = "prop"; constructor() { - ~~~~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. const obj = { prop: this.propName, @@ -430,7 +430,7 @@ derivedClassSuperProperties.ts(397,21): error TS2401: A 'super' call must be a r class DerivedWithObjectComputedPropertyName extends Base { propName = "prop"; constructor() { - ~~~~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. const obj = { [this.propName]: true, diff --git a/tests/baselines/reference/externModule.errors.txt b/tests/baselines/reference/externModule.errors.txt index 7af94395ad377..5d933216d1d9c 100644 --- a/tests/baselines/reference/externModule.errors.txt +++ b/tests/baselines/reference/externModule.errors.txt @@ -42,7 +42,7 @@ externModule.ts(37,3): error TS2552: Cannot find name 'XDate'. Did you mean 'Dat constructor(year: number, month: number, date: number, hours: number, minutes: number, seconds: number, ms: number); constructor(value: number); constructor(); - ~~~~~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS2390: Constructor implementation is missing. static parse(string: string): number; diff --git a/tests/baselines/reference/illegalSuperCallsInConstructor.errors.txt b/tests/baselines/reference/illegalSuperCallsInConstructor.errors.txt index f076a820ef923..4e558592d9f2d 100644 --- a/tests/baselines/reference/illegalSuperCallsInConstructor.errors.txt +++ b/tests/baselines/reference/illegalSuperCallsInConstructor.errors.txt @@ -13,7 +13,7 @@ illegalSuperCallsInConstructor.ts(16,17): error TS2337: Super calls are not perm class Derived extends Base { constructor() { - ~~~~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS2377: Constructors for derived classes must contain a 'super' call. var r2 = () => super(); ~~~~~ diff --git a/tests/baselines/reference/jsFileCompilationConstructorOverloadSyntax.errors.txt b/tests/baselines/reference/jsFileCompilationConstructorOverloadSyntax.errors.txt index 0ff11a2b87aa5..c2eefe3d28742 100644 --- a/tests/baselines/reference/jsFileCompilationConstructorOverloadSyntax.errors.txt +++ b/tests/baselines/reference/jsFileCompilationConstructorOverloadSyntax.errors.txt @@ -4,7 +4,7 @@ a.js(2,3): error TS8017: Signature declarations can only be used in TypeScript f ==== a.js (1 errors) ==== class A { constructor(); - ~~~~~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS8017: Signature declarations can only be used in TypeScript files. } \ No newline at end of file diff --git a/tests/baselines/reference/parameterPropertyInConstructor2.errors.txt b/tests/baselines/reference/parameterPropertyInConstructor2.errors.txt index 6023abbd12ec8..4bfba6c77cd0d 100644 --- a/tests/baselines/reference/parameterPropertyInConstructor2.errors.txt +++ b/tests/baselines/reference/parameterPropertyInConstructor2.errors.txt @@ -7,7 +7,7 @@ parameterPropertyInConstructor2.ts(4,24): error TS2300: Duplicate identifier 'na module mod { class Customers { constructor(public names: string); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS2394: This overload signature is not compatible with its implementation signature. !!! related TS2750 parameterPropertyInConstructor2.ts:4:5: The implementation signature is declared here. ~~~~~~~~~~~~~~~~~~~~ diff --git a/tests/baselines/reference/parserClassDeclaration10.errors.txt b/tests/baselines/reference/parserClassDeclaration10.errors.txt index 6ff186b65e005..ae25e5e2d30d2 100644 --- a/tests/baselines/reference/parserClassDeclaration10.errors.txt +++ b/tests/baselines/reference/parserClassDeclaration10.errors.txt @@ -5,7 +5,7 @@ parserClassDeclaration10.ts(3,4): error TS2391: Function implementation is missi ==== parserClassDeclaration10.ts (2 errors) ==== class C { constructor(); - ~~~~~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS2390: Constructor implementation is missing. foo(); ~~~ diff --git a/tests/baselines/reference/parserClassDeclaration11.errors.txt b/tests/baselines/reference/parserClassDeclaration11.errors.txt index 2b2872c44af6d..5238bd514be95 100644 --- a/tests/baselines/reference/parserClassDeclaration11.errors.txt +++ b/tests/baselines/reference/parserClassDeclaration11.errors.txt @@ -4,7 +4,7 @@ parserClassDeclaration11.ts(2,4): error TS2390: Constructor implementation is mi ==== parserClassDeclaration11.ts (1 errors) ==== class C { constructor(); - ~~~~~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS2390: Constructor implementation is missing. foo() { } } \ No newline at end of file diff --git a/tests/baselines/reference/parserClassDeclaration12.errors.txt b/tests/baselines/reference/parserClassDeclaration12.errors.txt index 6915a0ce6560c..3a1e64bc4526b 100644 --- a/tests/baselines/reference/parserClassDeclaration12.errors.txt +++ b/tests/baselines/reference/parserClassDeclaration12.errors.txt @@ -4,7 +4,7 @@ parserClassDeclaration12.ts(2,4): error TS2394: This overload signature is not c ==== parserClassDeclaration12.ts (1 errors) ==== class C { constructor(); - ~~~~~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS2394: This overload signature is not compatible with its implementation signature. !!! related TS2750 parserClassDeclaration12.ts:3:4: The implementation signature is declared here. constructor(a) { } diff --git a/tests/baselines/reference/parserClassDeclaration14.errors.txt b/tests/baselines/reference/parserClassDeclaration14.errors.txt index 43bfa611ab482..5262a6387d0d1 100644 --- a/tests/baselines/reference/parserClassDeclaration14.errors.txt +++ b/tests/baselines/reference/parserClassDeclaration14.errors.txt @@ -8,6 +8,6 @@ parserClassDeclaration14.ts(3,4): error TS2390: Constructor implementation is mi ~~~ !!! error TS2391: Function implementation is missing or not immediately following the declaration. constructor(); - ~~~~~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS2390: Constructor implementation is missing. } \ No newline at end of file diff --git a/tests/baselines/reference/parserClassDeclaration8.errors.txt b/tests/baselines/reference/parserClassDeclaration8.errors.txt index 041612831759f..51a040f0c4860 100644 --- a/tests/baselines/reference/parserClassDeclaration8.errors.txt +++ b/tests/baselines/reference/parserClassDeclaration8.errors.txt @@ -4,6 +4,6 @@ parserClassDeclaration8.ts(2,3): error TS2390: Constructor implementation is mis ==== parserClassDeclaration8.ts (1 errors) ==== class C { constructor(); - ~~~~~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS2390: Constructor implementation is missing. } \ No newline at end of file diff --git a/tests/baselines/reference/parserConstructorDeclaration12.errors.txt b/tests/baselines/reference/parserConstructorDeclaration12.errors.txt index 6dcdb24fe052f..f64e38d695577 100644 --- a/tests/baselines/reference/parserConstructorDeclaration12.errors.txt +++ b/tests/baselines/reference/parserConstructorDeclaration12.errors.txt @@ -27,56 +27,56 @@ parserConstructorDeclaration12.ts(9,16): error TS1092: Type parameters cannot ap ==== parserConstructorDeclaration12.ts (24 errors) ==== class C { constructor<>() { } - ~~~~~~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS2392: Multiple constructor implementations are not allowed. ~~ !!! error TS1098: Type parameter list cannot be empty. !!! error TS1092: Type parameters cannot appear on a constructor declaration. constructor<> () { } - ~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS2392: Multiple constructor implementations are not allowed. ~~ !!! error TS1098: Type parameter list cannot be empty. !!! error TS1092: Type parameters cannot appear on a constructor declaration. constructor <>() { } - ~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS2392: Multiple constructor implementations are not allowed. ~~ !!! error TS1098: Type parameter list cannot be empty. !!! error TS1092: Type parameters cannot appear on a constructor declaration. constructor <> () { } - ~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS2392: Multiple constructor implementations are not allowed. ~~ !!! error TS1098: Type parameter list cannot be empty. !!! error TS1092: Type parameters cannot appear on a constructor declaration. constructor< >() { } - ~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS2392: Multiple constructor implementations are not allowed. ~~~ !!! error TS1098: Type parameter list cannot be empty. !!! error TS1092: Type parameters cannot appear on a constructor declaration. constructor< > () { } - ~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS2392: Multiple constructor implementations are not allowed. ~~~ !!! error TS1098: Type parameter list cannot be empty. !!! error TS1092: Type parameters cannot appear on a constructor declaration. constructor < >() { } - ~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS2392: Multiple constructor implementations are not allowed. ~~~ !!! error TS1098: Type parameter list cannot be empty. !!! error TS1092: Type parameters cannot appear on a constructor declaration. constructor < > () { } - ~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS2392: Multiple constructor implementations are not allowed. ~~~ !!! error TS1098: Type parameter list cannot be empty. diff --git a/tests/baselines/reference/parserConstructorDeclaration8.errors.txt b/tests/baselines/reference/parserConstructorDeclaration8.errors.txt index 4f2b74579fde3..8b37b60364f46 100644 --- a/tests/baselines/reference/parserConstructorDeclaration8.errors.txt +++ b/tests/baselines/reference/parserConstructorDeclaration8.errors.txt @@ -6,7 +6,7 @@ parserConstructorDeclaration8.ts(3,21): error TS1005: '(' expected. class C { // Not a constructor public constructor; - ~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~ !!! error TS2390: Constructor implementation is missing. ~ !!! error TS1005: '(' expected. diff --git a/tests/baselines/reference/parserParameterList17.errors.txt b/tests/baselines/reference/parserParameterList17.errors.txt index 663bb3d9f7594..58b8ec781885b 100644 --- a/tests/baselines/reference/parserParameterList17.errors.txt +++ b/tests/baselines/reference/parserParameterList17.errors.txt @@ -5,7 +5,7 @@ parserParameterList17.ts(2,16): error TS2371: A parameter initializer is only al ==== parserParameterList17.ts (2 errors) ==== class C { constructor(a = 4); - ~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS2394: This overload signature is not compatible with its implementation signature. !!! related TS2750 parserParameterList17.ts:3:4: The implementation signature is declared here. ~~~~~ diff --git a/tests/baselines/reference/privateNameBadSuper.errors.txt b/tests/baselines/reference/privateNameBadSuper.errors.txt index 7c76ed949f254..653b7503a0cfc 100644 --- a/tests/baselines/reference/privateNameBadSuper.errors.txt +++ b/tests/baselines/reference/privateNameBadSuper.errors.txt @@ -7,7 +7,7 @@ privateNameBadSuper.ts(5,5): error TS17009: 'super' must be called before access class A extends B { #x; constructor() { - ~~~~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. this; ~~~~ diff --git a/tests/baselines/reference/staticPropSuper.errors.txt b/tests/baselines/reference/staticPropSuper.errors.txt index 2ede952c5f7d9..6799efa935ba7 100644 --- a/tests/baselines/reference/staticPropSuper.errors.txt +++ b/tests/baselines/reference/staticPropSuper.errors.txt @@ -20,7 +20,7 @@ staticPropSuper.ts(32,5): error TS2377: Constructors for derived classes must co public p: number = 10; constructor() { - ~~~~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS2377: Constructors for derived classes must contain a 'super' call. var x = 1; // should error } @@ -30,7 +30,7 @@ staticPropSuper.ts(32,5): error TS2377: Constructors for derived classes must co private p: number = 11; constructor() { - ~~~~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS2377: Constructors for derived classes must contain a 'super' call. var x = 1; // should error } @@ -40,7 +40,7 @@ staticPropSuper.ts(32,5): error TS2377: Constructors for derived classes must co p: number = 12; constructor() { - ~~~~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS2377: Constructors for derived classes must contain a 'super' call. var x = 1; // should error } diff --git a/tests/baselines/reference/strictModeInConstructor.errors.txt b/tests/baselines/reference/strictModeInConstructor.errors.txt index fa9fba9332666..65a9114036b3e 100644 --- a/tests/baselines/reference/strictModeInConstructor.errors.txt +++ b/tests/baselines/reference/strictModeInConstructor.errors.txt @@ -30,7 +30,7 @@ strictModeInConstructor.ts(29,17): error TS17009: 'super' must be called before public s: number = 9; constructor () { - ~~~~~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. var x = 1; // No error var y = this.s; // Error diff --git a/tests/baselines/reference/superCallInsideClassDeclaration.errors.txt b/tests/baselines/reference/superCallInsideClassDeclaration.errors.txt index 55034c56dc770..6764c2c26170e 100644 --- a/tests/baselines/reference/superCallInsideClassDeclaration.errors.txt +++ b/tests/baselines/reference/superCallInsideClassDeclaration.errors.txt @@ -10,7 +10,7 @@ superCallInsideClassDeclaration.ts(8,5): error TS2377: Constructors for derived class B extends A { constructor() { - ~~~~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS2377: Constructors for derived classes must contain a 'super' call. class D extends C { diff --git a/tests/baselines/reference/superCallInsideClassExpression.errors.txt b/tests/baselines/reference/superCallInsideClassExpression.errors.txt index ae97af2301b5f..9312a1a97a838 100644 --- a/tests/baselines/reference/superCallInsideClassExpression.errors.txt +++ b/tests/baselines/reference/superCallInsideClassExpression.errors.txt @@ -10,7 +10,7 @@ superCallInsideClassExpression.ts(8,5): error TS2377: Constructors for derived c class B extends A { constructor() { - ~~~~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS2377: Constructors for derived classes must contain a 'super' call. var D = class extends C { diff --git a/tests/baselines/reference/superInConstructorParam1.errors.txt b/tests/baselines/reference/superInConstructorParam1.errors.txt index ef5896fde7ecb..0182e68030f73 100644 --- a/tests/baselines/reference/superInConstructorParam1.errors.txt +++ b/tests/baselines/reference/superInConstructorParam1.errors.txt @@ -12,7 +12,7 @@ superInConstructorParam1.ts(8,19): error TS17011: 'super' must be called before class C extends B { constructor(a = super.foo()) { - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS2377: Constructors for derived classes must contain a 'super' call. ~~~~~ !!! error TS2336: 'super' cannot be referenced in constructor arguments. diff --git a/tests/baselines/reference/superNewCall1.errors.txt b/tests/baselines/reference/superNewCall1.errors.txt index 404d3d7766c2d..720bbfce22c22 100644 --- a/tests/baselines/reference/superNewCall1.errors.txt +++ b/tests/baselines/reference/superNewCall1.errors.txt @@ -13,7 +13,7 @@ superNewCall1.ts(9,13): error TS17011: 'super' must be called before accessing a class B extends A { constructor() { - ~~~~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS2377: Constructors for derived classes must contain a 'super' call. new super(value => String(value)); ~~~~~ diff --git a/tests/baselines/reference/taggedTemplatesWithTypeArguments2.errors.txt b/tests/baselines/reference/taggedTemplatesWithTypeArguments2.errors.txt index b48a2861753ba..2335fb2daf9ff 100644 --- a/tests/baselines/reference/taggedTemplatesWithTypeArguments2.errors.txt +++ b/tests/baselines/reference/taggedTemplatesWithTypeArguments2.errors.txt @@ -49,7 +49,7 @@ taggedTemplatesWithTypeArguments2.ts(36,34): error TS1034: 'super' must be follo class SomeDerived extends SomeBase { constructor() { - ~~~~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS2377: Constructors for derived classes must contain a 'super' call. super `hello world`; ~~~~~ From c8baf230eebf86ac3d8982f2f762c1af74819ce9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Sun, 7 Apr 2024 08:22:51 +0200 Subject: [PATCH 3/3] bailout from the scanning on `EndOfFileToken` --- src/compiler/utilities.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 1bcabedb4554a..f13946d637919 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -2276,8 +2276,9 @@ export function getErrorSpanForNode(sourceFile: SourceFile, node: Node): TextSpa const constructorDeclaration = node as ConstructorDeclaration; const start = skipTrivia(sourceFile.text, constructorDeclaration.pos); const scanner = createScanner(sourceFile.languageVersion, /*skipTrivia*/ true, sourceFile.languageVariant, sourceFile.text, /*onError*/ undefined, start); - while (scanner.scan() !== SyntaxKind.ConstructorKeyword) { - // empty + let token = scanner.scan(); + while (token !== SyntaxKind.ConstructorKeyword && token !== SyntaxKind.EndOfFileToken) { + token = scanner.scan(); } const end = scanner.getTokenEnd(); return createTextSpanFromBounds(start, end);