diff --git a/src/services/refactors/addOrRemoveBracesToArrowFunction.ts b/src/services/refactors/addOrRemoveBracesToArrowFunction.ts
index 7f423f4df05..c7c3a04e8d3 100644
--- a/src/services/refactors/addOrRemoveBracesToArrowFunction.ts
+++ b/src/services/refactors/addOrRemoveBracesToArrowFunction.ts
@@ -44,6 +44,7 @@ namespace ts.refactor.addOrRemoveBracesToArrowFunction {
const { expression, returnStatement, func } = info;
let body: ConciseBody;
+
if (actionName === addBracesActionName) {
const returnStatement = createReturn(expression);
body = createBlock([returnStatement], /* multiLine */ true);
@@ -54,13 +55,18 @@ namespace ts.refactor.addOrRemoveBracesToArrowFunction {
const actualExpression = expression || createVoidZero();
body = needsParentheses(actualExpression) ? createParen(actualExpression) : actualExpression;
suppressLeadingAndTrailingTrivia(body);
+ copyTrailingAsLeadingComments(returnStatement, body, file, SyntaxKind.MultiLineCommentTrivia, /* hasTrailingNewLine */ false);
copyLeadingComments(returnStatement, body, file, SyntaxKind.MultiLineCommentTrivia, /* hasTrailingNewLine */ false);
+ copyTrailingComments(returnStatement, body, file, SyntaxKind.MultiLineCommentTrivia, /* hasTrailingNewLine */ false);
}
else {
Debug.fail("invalid action");
}
- const edits = textChanges.ChangeTracker.with(context, t => t.replaceNode(file, func.body, body));
+ const edits = textChanges.ChangeTracker.with(context, t => {
+ t.replaceNode(file, func.body, body);
+ });
+
return { renameFilename: undefined, renameLocation: undefined, edits };
}
diff --git a/tests/cases/fourslash/refactorAddOrRemoveBracesToArrowFunction24.ts b/tests/cases/fourslash/refactorAddOrRemoveBracesToArrowFunction24.ts
new file mode 100644
index 00000000000..3bee61a201c
--- /dev/null
+++ b/tests/cases/fourslash/refactorAddOrRemoveBracesToArrowFunction24.ts
@@ -0,0 +1,11 @@
+///
+
+//// const a = (a: number) /*a*/=>/*b*/ {/* comment */ return a;};
+
+goTo.select("a", "b");
+edit.applyRefactor({
+ refactorName: "Add or remove braces in an arrow function",
+ actionName: "Remove braces from arrow function",
+ actionDescription: "Remove braces from arrow function",
+ newContent: `const a = (a: number) => /* comment */ a;`,
+});
diff --git a/tests/cases/fourslash/refactorAddOrRemoveBracesToArrowFunction25.ts b/tests/cases/fourslash/refactorAddOrRemoveBracesToArrowFunction25.ts
new file mode 100644
index 00000000000..5f7226c2e93
--- /dev/null
+++ b/tests/cases/fourslash/refactorAddOrRemoveBracesToArrowFunction25.ts
@@ -0,0 +1,11 @@
+///
+
+//// const a = (a: number) /*a*/=>/*b*/ { return a; /* trailing */};
+
+goTo.select("a", "b");
+edit.applyRefactor({
+ refactorName: "Add or remove braces in an arrow function",
+ actionName: "Remove braces from arrow function",
+ actionDescription: "Remove braces from arrow function",
+ newContent: `const a = (a: number) => a /* trailing */;`,
+});
diff --git a/tests/cases/fourslash/refactorAddOrRemoveBracesToArrowFunction26.ts b/tests/cases/fourslash/refactorAddOrRemoveBracesToArrowFunction26.ts
new file mode 100644
index 00000000000..24234c7107d
--- /dev/null
+++ b/tests/cases/fourslash/refactorAddOrRemoveBracesToArrowFunction26.ts
@@ -0,0 +1,11 @@
+///
+
+//// const a = (a: number) /*a*/=>/*b*/ {/* leading */ return a; /* trailing */};
+
+goTo.select("a", "b");
+edit.applyRefactor({
+ refactorName: "Add or remove braces in an arrow function",
+ actionName: "Remove braces from arrow function",
+ actionDescription: "Remove braces from arrow function",
+ newContent: `const a = (a: number) => /* leading */ a /* trailing */;`,
+});
diff --git a/tests/cases/fourslash/refactorAddOrRemoveBracesToArrowFunction27.ts b/tests/cases/fourslash/refactorAddOrRemoveBracesToArrowFunction27.ts
new file mode 100644
index 00000000000..7f36317a233
--- /dev/null
+++ b/tests/cases/fourslash/refactorAddOrRemoveBracesToArrowFunction27.ts
@@ -0,0 +1,13 @@
+///
+
+//// const b = (a: number) /*a*/=>/*b*/ { /* leading */
+//// return a; /* trailing */
+//// }
+
+goTo.select("a", "b");
+edit.applyRefactor({
+ refactorName: "Add or remove braces in an arrow function",
+ actionName: "Remove braces from arrow function",
+ actionDescription: "Remove braces from arrow function",
+ newContent: `const b = (a: number) => /* leading */ a /* trailing */`,
+});
diff --git a/tests/cases/fourslash/refactorAddOrRemoveBracesToArrowFunction28.ts b/tests/cases/fourslash/refactorAddOrRemoveBracesToArrowFunction28.ts
new file mode 100644
index 00000000000..a79b89c9f2f
--- /dev/null
+++ b/tests/cases/fourslash/refactorAddOrRemoveBracesToArrowFunction28.ts
@@ -0,0 +1,11 @@
+///
+
+//// const a = (a: number) /*a*/=>/*b*/ { return a; /* c */ /* d */ };
+
+goTo.select("a", "b");
+edit.applyRefactor({
+ refactorName: "Add or remove braces in an arrow function",
+ actionName: "Remove braces from arrow function",
+ actionDescription: "Remove braces from arrow function",
+ newContent: `const a = (a: number) => a /* c */ /* d */;`,
+});