Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/services/codefixes/convertFunctionToEs6Class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/services/textChanges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down