Remove superCallShouldBeFirst error (#37947)

* Remove superCallShouldBeFirst error

It seems redundant since TS gives an error on any use of `this` before
super, and non-`this` uses before `super` should be fine.

Fixes #37371

* Revert "Remove superCallShouldBeFirst error"

This reverts commit 3c09153c8a.

* error except for target:"esnext" && useDefineForClassFields
This commit is contained in:
Nathan Shively-Sanders 2020-04-21 12:58:37 -07:00 committed by GitHub
parent 1e48057b9e
commit 6ea291a142
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 75 additions and 2 deletions

View file

@ -29677,8 +29677,9 @@ namespace ts {
// - The constructor declares parameter properties
// or the containing class declares instance member variables with initializers.
const superCallShouldBeFirst =
some((<ClassDeclaration>node.parent).members, isInstancePropertyWithInitializerOrPrivateIdentifierProperty) ||
some(node.parameters, p => hasModifier(p, ModifierFlags.ParameterPropertyModifier));
(compilerOptions.target !== ScriptTarget.ESNext || !compilerOptions.useDefineForClassFields) &&
(some((<ClassDeclaration>node.parent).members, isInstancePropertyWithInitializerOrPrivateIdentifierProperty) ||
some(node.parameters, p => hasModifier(p, ModifierFlags.ParameterPropertyModifier)));
// Skip past any prologue directives to find the first statement
// to ensure that it was a super call.

View file

@ -0,0 +1,22 @@
//// [privateNameBadSuperUseDefineForClassFields.ts]
class B {};
class A extends B {
#x;
constructor() {
void 0; // Error: 'super' call must come first
super();
}
}
//// [privateNameBadSuperUseDefineForClassFields.js]
class B {
}
;
class A extends B {
#x;
constructor() {
void 0; // Error: 'super' call must come first
super();
}
}

View file

@ -0,0 +1,18 @@
=== tests/cases/conformance/classes/members/privateNames/privateNameBadSuperUseDefineForClassFields.ts ===
class B {};
>B : Symbol(B, Decl(privateNameBadSuperUseDefineForClassFields.ts, 0, 0))
class A extends B {
>A : Symbol(A, Decl(privateNameBadSuperUseDefineForClassFields.ts, 0, 11))
>B : Symbol(B, Decl(privateNameBadSuperUseDefineForClassFields.ts, 0, 0))
#x;
>#x : Symbol(A.#x, Decl(privateNameBadSuperUseDefineForClassFields.ts, 1, 19))
constructor() {
void 0; // Error: 'super' call must come first
super();
>super : Symbol(B, Decl(privateNameBadSuperUseDefineForClassFields.ts, 0, 0))
}
}

View file

@ -0,0 +1,22 @@
=== tests/cases/conformance/classes/members/privateNames/privateNameBadSuperUseDefineForClassFields.ts ===
class B {};
>B : B
class A extends B {
>A : A
>B : B
#x;
>#x : any
constructor() {
void 0; // Error: 'super' call must come first
>void 0 : undefined
>0 : 0
super();
>super() : void
>super : typeof B
}
}

View file

@ -0,0 +1,10 @@
// @target: esnext
// @useDefineForClassFields: true
class B {};
class A extends B {
#x;
constructor() {
void 0; // Error: 'super' call must come first
super();
}
}