Skip to content

Commit a53ab09

Browse files
Don't suppress comments when adding or removing braces to/from arrow function. (microsoft#45597)
Fixes microsoft#44228, microsoft#44229.
1 parent b1df3fe commit a53ab09

5 files changed

+84
-2
lines changed

src/services/refactors/addOrRemoveBracesToArrowFunction.ts

-2
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,11 @@ namespace ts.refactor.addOrRemoveBracesToArrowFunction {
6666
if (actionName === addBracesAction.name) {
6767
const returnStatement = factory.createReturnStatement(expression);
6868
body = factory.createBlock([returnStatement], /* multiLine */ true);
69-
suppressLeadingAndTrailingTrivia(body);
7069
copyLeadingComments(expression!, returnStatement, file, SyntaxKind.MultiLineCommentTrivia, /* hasTrailingNewLine */ true);
7170
}
7271
else if (actionName === removeBracesAction.name && returnStatement) {
7372
const actualExpression = expression || factory.createVoidZero();
7473
body = needsParentheses(actualExpression) ? factory.createParenthesizedExpression(actualExpression) : actualExpression;
75-
suppressLeadingAndTrailingTrivia(body);
7674
copyTrailingAsLeadingComments(returnStatement, body, file, SyntaxKind.MultiLineCommentTrivia, /* hasTrailingNewLine */ false);
7775
copyLeadingComments(returnStatement, body, file, SyntaxKind.MultiLineCommentTrivia, /* hasTrailingNewLine */ false);
7876
copyTrailingComments(returnStatement, body, file, SyntaxKind.MultiLineCommentTrivia, /* hasTrailingNewLine */ false);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
////const a = /*a*/()/*b*/ => {
4+
//// return (
5+
//// // comment
6+
//// 1
7+
//// );
8+
////};
9+
10+
goTo.select("a", "b");
11+
edit.applyRefactor({
12+
refactorName: "Add or remove braces in an arrow function",
13+
actionName: "Remove braces from arrow function",
14+
actionDescription: "Remove braces from arrow function",
15+
newContent: `const a = () => (
16+
// comment
17+
1
18+
);`,
19+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
////const a = /*a*/()/*b*/ => {
4+
//// return (
5+
//// /*
6+
//// multi-line comment
7+
//// */
8+
//// 1
9+
//// );
10+
////};
11+
12+
goTo.select("a", "b");
13+
edit.applyRefactor({
14+
refactorName: "Add or remove braces in an arrow function",
15+
actionName: "Remove braces from arrow function",
16+
actionDescription: "Remove braces from arrow function",
17+
newContent: `const a = () => (
18+
/*
19+
multi-line comment
20+
*/
21+
1
22+
);`,
23+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
////const a = /*a*/()/*b*/ => (
4+
//// // comment
5+
//// 1
6+
////);
7+
8+
goTo.select("a", "b");
9+
edit.applyRefactor({
10+
refactorName: "Add or remove braces in an arrow function",
11+
actionName: "Add braces to arrow function",
12+
actionDescription: "Add braces to arrow function",
13+
newContent: `const a = () => {
14+
return (
15+
// comment
16+
1
17+
);
18+
};`,
19+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
////const a = /*a*/()/*b*/ => (
4+
//// /*
5+
//// multi-line comment
6+
//// */
7+
//// 1
8+
////);
9+
10+
goTo.select("a", "b");
11+
edit.applyRefactor({
12+
refactorName: "Add or remove braces in an arrow function",
13+
actionName: "Add braces to arrow function",
14+
actionDescription: "Add braces to arrow function",
15+
newContent: `const a = () => {
16+
return (
17+
/*
18+
multi-line comment
19+
*/
20+
1
21+
);
22+
};`,
23+
});

0 commit comments

Comments
 (0)