mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-03-15 14:05:47 -05:00
convertFunctionToEs6Class: Copy comments from constructor to class (#22738)
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user