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