Skip to content

Commit 6ea291a

Browse files
authored
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 3c09153. * error except for target:"esnext" && useDefineForClassFields
1 parent 1e48057 commit 6ea291a

File tree

5 files changed

+75
-2
lines changed

5 files changed

+75
-2
lines changed

src/compiler/checker.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29677,8 +29677,9 @@ namespace ts {
2967729677
// - The constructor declares parameter properties
2967829678
// or the containing class declares instance member variables with initializers.
2967929679
const superCallShouldBeFirst =
29680-
some((<ClassDeclaration>node.parent).members, isInstancePropertyWithInitializerOrPrivateIdentifierProperty) ||
29681-
some(node.parameters, p => hasModifier(p, ModifierFlags.ParameterPropertyModifier));
29680+
(compilerOptions.target !== ScriptTarget.ESNext || !compilerOptions.useDefineForClassFields) &&
29681+
(some((<ClassDeclaration>node.parent).members, isInstancePropertyWithInitializerOrPrivateIdentifierProperty) ||
29682+
some(node.parameters, p => hasModifier(p, ModifierFlags.ParameterPropertyModifier)));
2968229683

2968329684
// Skip past any prologue directives to find the first statement
2968429685
// to ensure that it was a super call.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//// [privateNameBadSuperUseDefineForClassFields.ts]
2+
class B {};
3+
class A extends B {
4+
#x;
5+
constructor() {
6+
void 0; // Error: 'super' call must come first
7+
super();
8+
}
9+
}
10+
11+
12+
//// [privateNameBadSuperUseDefineForClassFields.js]
13+
class B {
14+
}
15+
;
16+
class A extends B {
17+
#x;
18+
constructor() {
19+
void 0; // Error: 'super' call must come first
20+
super();
21+
}
22+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
=== tests/cases/conformance/classes/members/privateNames/privateNameBadSuperUseDefineForClassFields.ts ===
2+
class B {};
3+
>B : Symbol(B, Decl(privateNameBadSuperUseDefineForClassFields.ts, 0, 0))
4+
5+
class A extends B {
6+
>A : Symbol(A, Decl(privateNameBadSuperUseDefineForClassFields.ts, 0, 11))
7+
>B : Symbol(B, Decl(privateNameBadSuperUseDefineForClassFields.ts, 0, 0))
8+
9+
#x;
10+
>#x : Symbol(A.#x, Decl(privateNameBadSuperUseDefineForClassFields.ts, 1, 19))
11+
12+
constructor() {
13+
void 0; // Error: 'super' call must come first
14+
super();
15+
>super : Symbol(B, Decl(privateNameBadSuperUseDefineForClassFields.ts, 0, 0))
16+
}
17+
}
18+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
=== tests/cases/conformance/classes/members/privateNames/privateNameBadSuperUseDefineForClassFields.ts ===
2+
class B {};
3+
>B : B
4+
5+
class A extends B {
6+
>A : A
7+
>B : B
8+
9+
#x;
10+
>#x : any
11+
12+
constructor() {
13+
void 0; // Error: 'super' call must come first
14+
>void 0 : undefined
15+
>0 : 0
16+
17+
super();
18+
>super() : void
19+
>super : typeof B
20+
}
21+
}
22+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// @target: esnext
2+
// @useDefineForClassFields: true
3+
class B {};
4+
class A extends B {
5+
#x;
6+
constructor() {
7+
void 0; // Error: 'super' call must come first
8+
super();
9+
}
10+
}

0 commit comments

Comments
 (0)