Skip to content

Commit e50b24a

Browse files
author
Andy
authored
convertFunctionToEs6Class: Copy comment from variable declaration (#23445)
1 parent 55f9a6f commit e50b24a

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/services/codefixes/convertFunctionToEs6Class.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,14 @@ namespace ts.codefix {
3434

3535
case SyntaxKind.VariableDeclaration:
3636
precedingNode = ctorDeclaration.parent.parent;
37+
newClassDeclaration = createClassFromVariableDeclaration(ctorDeclaration as VariableDeclaration);
3738
if ((<VariableDeclarationList>ctorDeclaration.parent).declarations.length === 1) {
39+
copyComments(precedingNode, newClassDeclaration, sourceFile);
3840
deleteNode(precedingNode);
3941
}
4042
else {
4143
deleteNode(ctorDeclaration, /*inList*/ true);
4244
}
43-
newClassDeclaration = createClassFromVariableDeclaration(ctorDeclaration as VariableDeclaration);
4445
break;
4546
}
4647

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @allowJs: true
4+
// @Filename: /a.js
5+
/////** Doc */
6+
////const C = function() { this.x = 0; }
7+
8+
verify.codeFix({
9+
description: "Convert function to an ES2015 class",
10+
newFileContent:
11+
`/** Doc */
12+
class C {
13+
constructor() { this.x = 0; }
14+
}
15+
`,
16+
});

0 commit comments

Comments
 (0)