Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1a59eb3

Browse filesBrowse files
committed
update body only
1 parent 0c06126 commit 1a59eb3
Copy full SHA for 1a59eb3

1 file changed

+6-21Lines changed: 6 additions & 21 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/services/refactors/addOrRemoveBracesToArrowFunction.ts‎

Copy file name to clipboardExpand all lines: src/services/refactors/addOrRemoveBracesToArrowFunction.ts
+6-21Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -41,49 +41,34 @@ namespace ts.refactor.addOrRemoveBracesToArrowFunction {
4141
if (!info) return undefined;
4242

4343
const { expression, func } = info;
44-
const changeTracker = textChanges.ChangeTracker.fromContext(context);
4544

4645
let body: ConciseBody;
4746
if (actionName === addBracesActionName) {
4847
const returnStatement = createReturn(expression);
4948
body = createBlock([returnStatement], /* multiLine */ true);
50-
suppressLeadingAndTrailingTrivia(expression);
49+
suppressLeadingAndTrailingTrivia(body);
5150
copyComments(expression, returnStatement, file, SyntaxKind.MultiLineCommentTrivia, true, true);
5251
}
5352
else if (actionName === removeBracesActionName) {
5453
const returnStatement = <ReturnStatement>expression.parent;
5554
body = needsParentheses(expression) ? createParen(expression) : expression;
56-
suppressLeadingAndTrailingTrivia(returnStatement);
55+
suppressLeadingAndTrailingTrivia(body);
5756
copyComments(returnStatement, body, file, SyntaxKind.MultiLineCommentTrivia, false);
5857
}
5958
else {
6059
Debug.fail('invalid action');
6160
}
6261

63-
updateBody(changeTracker, file, func, body);
64-
65-
return {
66-
renameFilename: undefined,
67-
renameLocation: undefined,
68-
edits: changeTracker.getChanges()
69-
};
62+
const edits = textChanges.ChangeTracker.with(context, t => updateBody(t, file, func, body));
63+
return { renameFilename: undefined, renameLocation: undefined, edits };
7064
}
7165

7266
function needsParentheses(expression: Expression) {
73-
if (isBinaryExpression(expression) && expression.operatorToken.kind === SyntaxKind.CommaToken) return true;
74-
if (isObjectLiteralExpression(expression)) return true;
75-
return false;
67+
return isBinaryExpression(expression) && expression.operatorToken.kind === SyntaxKind.CommaToken || isObjectLiteralExpression(expression);
7668
}
7769

7870
function updateBody(changeTracker: textChanges.ChangeTracker, file: SourceFile, container: ArrowFunction, body: ConciseBody) {
79-
const arrowFunction = updateArrowFunction(
80-
container,
81-
container.modifiers,
82-
container.typeParameters,
83-
container.parameters,
84-
container.type,
85-
body);
86-
changeTracker.replaceNode(file, container, arrowFunction);
71+
changeTracker.replaceNode(file, container.body, body);
8772
}
8873

8974
function getConvertibleArrowFunctionAtPosition(file: SourceFile, startPosition: number): Info | undefined {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.