Skip to content

Commit bab0c99

Browse files
authored
fix(29565): Add missing super() quickFix errors for constructo… (microsoft#36601)
1 parent bc12123 commit bab0c99

File tree

4 files changed

+67
-1
lines changed

4 files changed

+67
-1
lines changed

src/services/codefixes/fixConstructorForDerivedNeedSuperCall.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace ts.codefix {
1717

1818
function getNode(sourceFile: SourceFile, pos: number): ConstructorDeclaration {
1919
const token = getTokenAtPosition(sourceFile, pos);
20-
Debug.assert(token.kind === SyntaxKind.ConstructorKeyword, "token should be at the constructor keyword");
20+
Debug.assert(isConstructorDeclaration(token.parent), "token should be at the constructor declaration");
2121
return token.parent as ConstructorDeclaration;
2222
}
2323

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
////class A {}
4+
////class B extends A {
5+
//// [|constructor|]() {}
6+
////}
7+
8+
verify.codeFixAvailable([
9+
{ description: ts.Diagnostics.Add_missing_super_call.message }
10+
])
11+
12+
verify.codeFix({
13+
description: ts.Diagnostics.Add_missing_super_call.message,
14+
newFileContent:
15+
`class A {}
16+
class B extends A {
17+
constructor() {
18+
super();
19+
}
20+
}`
21+
});
22+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
////class A {}
4+
////class B extends A {
5+
//// [|public constructor|]() {}
6+
////}
7+
8+
verify.codeFixAvailable([
9+
{ description: ts.Diagnostics.Add_missing_super_call.message }
10+
])
11+
12+
verify.codeFix({
13+
description: ts.Diagnostics.Add_missing_super_call.message,
14+
newFileContent:
15+
`class A {}
16+
class B extends A {
17+
public constructor() {
18+
super();
19+
}
20+
}`
21+
});
22+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
////class A {}
4+
////class B extends A {
5+
//// public [|constructor|]() {}
6+
////}
7+
8+
verify.codeFixAvailable([
9+
{ description: ts.Diagnostics.Add_missing_super_call.message }
10+
])
11+
12+
verify.codeFix({
13+
description: ts.Diagnostics.Add_missing_super_call.message,
14+
newFileContent:
15+
`class A {}
16+
class B extends A {
17+
public constructor() {
18+
super();
19+
}
20+
}`
21+
});
22+

0 commit comments

Comments
 (0)