convertFunctionToEs6Class: Copy comments from constructor to class (#22738)

This commit is contained in:
Andy
2018-03-22 08:12:02 -07:00
committed by GitHub
parent effcf2ac56
commit f2f2393f4b
3 changed files with 5 additions and 3 deletions

View File

@@ -49,6 +49,8 @@ namespace ts.codefix {
return undefined;
}
copyComments(ctorDeclaration, newClassDeclaration, sourceFile);
// Because the preceding node could be touched, we need to insert nodes before delete nodes.
changes.insertNodeAfter(sourceFile, precedingNode, newClassDeclaration);
for (const deleteCallback of deletes) {

View File

@@ -221,6 +221,7 @@ namespace ts.textChanges {
return this;
}
/** Warning: This deletes comments too. See `copyComments` in `convertFunctionToEs6Class`. */
public deleteNode(sourceFile: SourceFile, node: Node, options: ConfigurableStartEnd = {}) {
const startPosition = getAdjustedStartPosition(sourceFile, node, options, Position.FullStart);
const endPosition = getAdjustedEndPosition(sourceFile, node, options);

View File

@@ -14,9 +14,8 @@
verify.codeFix({
description: "Convert function to an ES2015 class",
newFileContent:
// NOTE: '// Comment' should be included, but due to incorrect handling of trivia,
// it's omitted right now.
`class fn {\r
`// Comment\r
class fn {\r
constructor() {\r
this.baz = 10;\r
}\r