convertFunctionToEs6Class: Copy comment from variable declaration (#23445)

This commit is contained in:
Andy
2018-04-17 09:15:05 -07:00
committed by GitHub
parent 55f9a6ffc2
commit e50b24a83b
2 changed files with 18 additions and 1 deletions

View File

@@ -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;
}

View File

@@ -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; }
}
`,
});