mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-10 18:04:18 -05:00
convertFunctionToEs6Class: Copy comment from variable declaration (#23445)
This commit is contained in:
@@ -34,13 +34,14 @@ namespace ts.codefix {
|
||||
|
||||
case SyntaxKind.VariableDeclaration:
|
||||
precedingNode = ctorDeclaration.parent.parent;
|
||||
newClassDeclaration = createClassFromVariableDeclaration(ctorDeclaration as VariableDeclaration);
|
||||
if ((<VariableDeclarationList>ctorDeclaration.parent).declarations.length === 1) {
|
||||
copyComments(precedingNode, newClassDeclaration, sourceFile);
|
||||
deleteNode(precedingNode);
|
||||
}
|
||||
else {
|
||||
deleteNode(ctorDeclaration, /*inList*/ true);
|
||||
}
|
||||
newClassDeclaration = createClassFromVariableDeclaration(ctorDeclaration as VariableDeclaration);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @allowJs: true
|
||||
// @Filename: /a.js
|
||||
/////** Doc */
|
||||
////const C = function() { this.x = 0; }
|
||||
|
||||
verify.codeFix({
|
||||
description: "Convert function to an ES2015 class",
|
||||
newFileContent:
|
||||
`/** Doc */
|
||||
class C {
|
||||
constructor() { this.x = 0; }
|
||||
}
|
||||
`,
|
||||
});
|
||||
Reference in New Issue
Block a user