mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-04 21:53:42 -06:00
Don't suppress comments when adding or removing braces to/from arrow function. (#45597)
Fixes microsoft/typescript#44228, microsoft/typescript#44229.
This commit is contained in:
parent
b1df3fec16
commit
a53ab0935d
@ -66,13 +66,11 @@ namespace ts.refactor.addOrRemoveBracesToArrowFunction {
|
||||
if (actionName === addBracesAction.name) {
|
||||
const returnStatement = factory.createReturnStatement(expression);
|
||||
body = factory.createBlock([returnStatement], /* multiLine */ true);
|
||||
suppressLeadingAndTrailingTrivia(body);
|
||||
copyLeadingComments(expression!, returnStatement, file, SyntaxKind.MultiLineCommentTrivia, /* hasTrailingNewLine */ true);
|
||||
}
|
||||
else if (actionName === removeBracesAction.name && returnStatement) {
|
||||
const actualExpression = expression || factory.createVoidZero();
|
||||
body = needsParentheses(actualExpression) ? factory.createParenthesizedExpression(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);
|
||||
|
||||
@ -0,0 +1,19 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
////const a = /*a*/()/*b*/ => {
|
||||
//// return (
|
||||
//// // comment
|
||||
//// 1
|
||||
//// );
|
||||
////};
|
||||
|
||||
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 = () => (
|
||||
// comment
|
||||
1
|
||||
);`,
|
||||
});
|
||||
@ -0,0 +1,23 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
////const a = /*a*/()/*b*/ => {
|
||||
//// return (
|
||||
//// /*
|
||||
//// multi-line comment
|
||||
//// */
|
||||
//// 1
|
||||
//// );
|
||||
////};
|
||||
|
||||
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 = () => (
|
||||
/*
|
||||
multi-line comment
|
||||
*/
|
||||
1
|
||||
);`,
|
||||
});
|
||||
@ -0,0 +1,19 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
////const a = /*a*/()/*b*/ => (
|
||||
//// // comment
|
||||
//// 1
|
||||
////);
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Add or remove braces in an arrow function",
|
||||
actionName: "Add braces to arrow function",
|
||||
actionDescription: "Add braces to arrow function",
|
||||
newContent: `const a = () => {
|
||||
return (
|
||||
// comment
|
||||
1
|
||||
);
|
||||
};`,
|
||||
});
|
||||
@ -0,0 +1,23 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
////const a = /*a*/()/*b*/ => (
|
||||
//// /*
|
||||
//// multi-line comment
|
||||
//// */
|
||||
//// 1
|
||||
////);
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Add or remove braces in an arrow function",
|
||||
actionName: "Add braces to arrow function",
|
||||
actionDescription: "Add braces to arrow function",
|
||||
newContent: `const a = () => {
|
||||
return (
|
||||
/*
|
||||
multi-line comment
|
||||
*/
|
||||
1
|
||||
);
|
||||
};`,
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user