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 0c06126

Browse filesBrowse files
committed
fix converter
1 parent bd9a8b5 commit 0c06126
Copy full SHA for 0c06126

11 files changed

+53-19Lines changed: 53 additions & 19 deletions
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/compiler/scanner.ts‎

Copy file name to clipboardExpand all lines: src/compiler/scanner.ts
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -626,13 +626,13 @@ namespace ts {
626626
* @returns If "reduce" is true, the accumulated value. If "reduce" is false, the first truthy
627627
* return value of the callback.
628628
*/
629-
function iterateCommentRanges<T, U>(reduce: boolean, text: string, pos: number, trailing: boolean, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean, state: T, memo: U | undefined) => U, state: T, initial?: U): U | undefined {
629+
function iterateCommentRanges<T, U>(reduce: boolean, text: string, pos: number, trailing: boolean, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean, state: T, memo: U | undefined) => U, state: T, initial?: U, inline?: boolean): U | undefined {
630630
let pendingPos!: number;
631631
let pendingEnd!: number;
632632
let pendingKind!: CommentKind;
633633
let pendingHasTrailingNewLine!: boolean;
634634
let hasPendingCommentRange = false;
635-
let collecting = trailing || pos === 0;
635+
let collecting = inline || trailing || pos === 0;
636636
let accumulator = initial;
637637
scan: while (pos >= 0 && pos < text.length) {
638638
const ch = text.charCodeAt(pos);
@@ -725,9 +725,9 @@ namespace ts {
725725
}
726726

727727
export function forEachLeadingCommentRange<U>(text: string, pos: number, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean) => U): U | undefined;
728-
export function forEachLeadingCommentRange<T, U>(text: string, pos: number, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean, state: T) => U, state: T): U | undefined;
729-
export function forEachLeadingCommentRange<T, U>(text: string, pos: number, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean, state: T) => U, state?: T): U | undefined {
730-
return iterateCommentRanges(/*reduce*/ false, text, pos, /*trailing*/ false, cb, state);
728+
export function forEachLeadingCommentRange<T, U>(text: string, pos: number, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean, state: T) => U, state: T, inline?: boolean): U | undefined;
729+
export function forEachLeadingCommentRange<T, U>(text: string, pos: number, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean, state: T) => U, state?: T, inline?: boolean): U | undefined {
730+
return iterateCommentRanges(/*reduce*/ false, text, pos, /*trailing*/ false, cb, state, /* initial */ undefined, inline);
731731
}
732732

733733
export function forEachTrailingCommentRange<U>(text: string, pos: number, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean) => U): U | undefined;
Collapse file

‎src/services/refactors/addOrRemoveBracesToArrowFunction.ts‎

Copy file name to clipboardExpand all lines: src/services/refactors/addOrRemoveBracesToArrowFunction.ts
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,14 @@ namespace ts.refactor.addOrRemoveBracesToArrowFunction {
4646
let body: ConciseBody;
4747
if (actionName === addBracesActionName) {
4848
const returnStatement = createReturn(expression);
49-
body = createBlock([returnStatement]);
50-
copyComments(expression, returnStatement, file, SyntaxKind.SingleLineCommentTrivia, true);
49+
body = createBlock([returnStatement], /* multiLine */ true);
50+
suppressLeadingAndTrailingTrivia(expression);
51+
copyComments(expression, returnStatement, file, SyntaxKind.MultiLineCommentTrivia, true, true);
5152
}
5253
else if (actionName === removeBracesActionName) {
5354
const returnStatement = <ReturnStatement>expression.parent;
5455
body = needsParentheses(expression) ? createParen(expression) : expression;
56+
suppressLeadingAndTrailingTrivia(returnStatement);
5557
copyComments(returnStatement, body, file, SyntaxKind.MultiLineCommentTrivia, false);
5658
}
5759
else {
@@ -99,7 +101,6 @@ namespace ts.refactor.addOrRemoveBracesToArrowFunction {
99101
else if (func.body.statements.length === 1) {
100102
const firstStatement = first(func.body.statements);
101103
if (isReturnStatement(firstStatement)) {
102-
103104
return {
104105
func,
105106
addBraces: false,
Collapse file

‎src/services/utilities.ts‎

Copy file name to clipboardExpand all lines: src/services/utilities.ts
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1643,7 +1643,7 @@ namespace ts {
16431643
return lastPos;
16441644
}
16451645

1646-
export function copyComments(sourceNode: Node, targetNode: Node, sourceFile: SourceFile, explicitKind?: CommentKind, explicitHtnl?: boolean) {
1646+
export function copyComments(sourceNode: Node, targetNode: Node, sourceFile: SourceFile, explicitKind?: CommentKind, explicitHtnl?: boolean, inline?: boolean) {
16471647
forEachLeadingCommentRange(sourceFile.text, sourceNode.pos, (pos, end, kind, htnl) => {
16481648
if (kind === SyntaxKind.MultiLineCommentTrivia) {
16491649
// Remove leading /*
@@ -1655,7 +1655,7 @@ namespace ts {
16551655
// Remove leading //
16561656
pos += 2;
16571657
}
1658-
addSyntheticLeadingComment(targetNode, explicitKind || kind, sourceFile.text.slice(pos, end), explicitHtnl !== undefined ? explicitHtnl : htnl);
1659-
});
1658+
addSyntheticLeadingComment(targetNode, explicitKind || kind, sourceFile.text.slice(pos, end), explicitHtnl !== undefined ? explicitHtnl : htnl);
1659+
}, undefined, inline)
16601660
}
16611661
}
Collapse file

‎tests/cases/fourslash/refactorAddOrRemoveBracesToArrowFunction1.ts‎

Copy file name to clipboardExpand all lines: tests/cases/fourslash/refactorAddOrRemoveBracesToArrowFunction1.ts
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,7 @@ edit.applyRefactor({
77
refactorName: "Add or remove braces in an arrow function",
88
actionName: "Add braces to arrow function",
99
actionDescription: "Add braces to arrow function",
10-
newContent: `const foo = a => { return a + 1; };`,
10+
newContent: `const foo = a => {
11+
return a + 1;
12+
};`,
1113
});
Collapse file

‎tests/cases/fourslash/refactorAddOrRemoveBracesToArrowFunction2.ts‎

Copy file name to clipboardExpand all lines: tests/cases/fourslash/refactorAddOrRemoveBracesToArrowFunction2.ts
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,7 @@ edit.applyRefactor({
77
refactorName: "Add or remove braces in an arrow function",
88
actionName: "Add braces to arrow function",
99
actionDescription: "Add braces to arrow function",
10-
newContent: `const foo = a => { return ({ a: 1 }); };`,
10+
newContent: `const foo = a => {
11+
return ({ a: 1 });
12+
};`,
1113
});
Collapse file

‎tests/cases/fourslash/refactorAddOrRemoveBracesToArrowFunction20.ts‎

Copy file name to clipboardExpand all lines: tests/cases/fourslash/refactorAddOrRemoveBracesToArrowFunction20.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ edit.applyRefactor({
1010
refactorName: "Add or remove braces in an arrow function",
1111
actionName: "Remove braces from arrow function",
1212
actionDescription: "Remove braces from arrow function",
13-
newContent: `const foo = a => /* return comment */ a;`,
13+
newContent: `const foo = a => /* return comment*/ a;`,
1414
});
Collapse file

‎tests/cases/fourslash/refactorAddOrRemoveBracesToArrowFunction21.ts‎

Copy file name to clipboardExpand all lines: tests/cases/fourslash/refactorAddOrRemoveBracesToArrowFunction21.ts
+6-3Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
goTo.select("a", "b");
66
edit.applyRefactor({
77
refactorName: "Add or remove braces in an arrow function",
8-
actionName: "Remove braces from arrow function",
9-
actionDescription: "Remove braces from arrow function",
10-
newContent: `const foo = a => { /* expression comment */ return a + 1; }`,
8+
actionName: "Add braces to arrow function",
9+
actionDescription: "Add braces to arrow function",
10+
newContent: `const foo = a => {
11+
/* expression comment */
12+
return a + 1;
13+
}`,
1114
});
Collapse file
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
//// const foo = /*a*/a/*b*/ =>
4+
//// /* expression comment */
5+
//// a + 1
6+
7+
goTo.select("a", "b");
8+
edit.applyRefactor({
9+
refactorName: "Add or remove braces in an arrow function",
10+
actionName: "Add braces to arrow function",
11+
actionDescription: "Add braces to arrow function",
12+
newContent: `const foo = a => {
13+
/* expression comment */
14+
return a + 1;
15+
}`,
16+
});
Collapse file

‎tests/cases/fourslash/refactorAddOrRemoveBracesToArrowFunction3.ts‎

Copy file name to clipboardExpand all lines: tests/cases/fourslash/refactorAddOrRemoveBracesToArrowFunction3.ts
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,7 @@ edit.applyRefactor({
77
refactorName: "Add or remove braces in an arrow function",
88
actionName: "Add braces to arrow function",
99
actionDescription: "Add braces to arrow function",
10-
newContent: `const foo = a => { return 1; };`,
10+
newContent: `const foo = a => {
11+
return 1;
12+
};`,
1113
});
Collapse file
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
//// const foo = /*a*/a/*b*/ => { };
4+
5+
goTo.select("a", "b");
6+
verify.not.refactorAvailable("Add or remove braces in an arrow function");

0 commit comments

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