Skip to content

Commit 175cf4e

Browse files
committed
Support semi
1 parent 601fc5e commit 175cf4e

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

src/services/codefixes/returnValueCorrect.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,12 @@ namespace ts.codefix {
171171

172172
function addReturnStatement(changes: textChanges.ChangeTracker, sourceFile: SourceFile, expression: Expression, statement: Statement) {
173173
suppressLeadingAndTrailingTrivia(expression);
174-
changes.replaceNode(sourceFile, statement, createReturn(expression));
174+
const probablyNeedSemi = probablyUsesSemicolons(sourceFile);
175+
changes.replaceNode(sourceFile, statement, createReturn(expression), {
176+
leadingTriviaOption: textChanges.LeadingTriviaOption.Exclude,
177+
trailingTriviaOption: textChanges.TrailingTriviaOption.Exclude,
178+
suffix: probablyNeedSemi ? ";" : undefined
179+
});
175180
}
176181

177182
function removeBlockBodyBrace(changes: textChanges.ChangeTracker, sourceFile: SourceFile, declaration: ArrowFunction, expression: Expression, commentSource: Node, withParen: boolean) {

tests/cases/fourslash/codeFixCorrectReturnValue24.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ verify.codeFix({
77
description: "Add a return statement",
88
index: 0,
99
newFileContent:
10-
`function Foo (a: () => number) { a() }
10+
`function Foo (a: () => number) { a() }
1111
Foo(() => { /* leading */ return 1 /* trailing */ })`
1212
})

tests/cases/fourslash/codeFixCorrectReturnValue25.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ verify.codeFix({
77
description: "Remove block body braces",
88
index: 1,
99
newFileContent:
10-
`function Foo (a: () => number) { a() }
10+
`function Foo (a: () => number) { a() }
1111
Foo(() => /* leading */ 1 /* trailing */)`
1212
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/// <reference path='fourslash.ts' />
2+
//// interface A {
3+
//// bar: string;
4+
//// }
5+
////
6+
//// function Foo (a: () => A) { a(); }
7+
//// Foo(() => {
8+
//// { bar: '123'; }
9+
//// })
10+
11+
verify.codeFix({
12+
description: "Add a return statement",
13+
index: 0,
14+
newFileContent:
15+
`interface A {
16+
bar: string;
17+
}
18+
19+
function Foo (a: () => A) { a(); }
20+
Foo(() => {
21+
return { bar: '123' };
22+
})`
23+
})

0 commit comments

Comments
 (0)