Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
3f59aa9
stash
Kingwl Aug 10, 2018
7671221
add surmise for return type
Kingwl Aug 14, 2018
0b1e6cc
add support for more case
Kingwl Aug 14, 2018
1f9b9c0
add more test case
Kingwl Aug 16, 2018
aca1722
add more testcase and fix all test
Kingwl Aug 20, 2018
7cfd0fb
Merge branch 'master' into returnValueSurmise
Kingwl Apr 29, 2019
cbe59bb
fix changed diagnosis
Kingwl Apr 30, 2019
48f1cca
Merge branch 'master' into returnValueSurmise
Kingwl May 8, 2019
98d7eba
fix broken test case
Kingwl May 8, 2019
537e806
add more case
Kingwl May 8, 2019
505e299
Merge branch 'master' into returnValueSurmise
Kingwl Jan 9, 2020
6fecf32
rename quickfix
Kingwl Jan 9, 2020
4c0af72
fix conflict
Kingwl Jan 9, 2020
98377f3
fix fix desc
Kingwl Jan 9, 2020
49d21bf
fix semi
Kingwl Jan 9, 2020
a2b15ed
Merge branch 'master' into returnValueSurmise
Kingwl Mar 4, 2020
eabc5a4
Merge branch 'master' into returnValueSurmise
Kingwl Mar 4, 2020
944ddf4
Avoid replace brace with paren
Kingwl Mar 18, 2020
6c88a01
Split fix all action
Kingwl Mar 18, 2020
94f845a
Add return work in same line
Kingwl Mar 18, 2020
a7f37a3
Merge branch 'master' into returnValueSurmise
Kingwl Mar 18, 2020
7fe9a82
fix test cases
Kingwl Mar 18, 2020
af9552e
rename baseline
Kingwl Mar 26, 2020
601fc5e
refactor and handle comment
Kingwl Mar 26, 2020
175cf4e
Support semi
Kingwl Mar 26, 2020
8b332fe
Merge branch 'master' into returnValueSurmise
Kingwl Mar 26, 2020
5d8355c
make helper internal
Kingwl Mar 26, 2020
522cac8
Merge branch 'master' into returnValueSurmise
Kingwl Apr 2, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Support semi
  • Loading branch information
Kingwl committed Mar 26, 2020
commit 175cf4ea9f1f1b24a8cc312c67d3e41095a4e882
7 changes: 6 additions & 1 deletion src/services/codefixes/returnValueCorrect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,12 @@ namespace ts.codefix {

function addReturnStatement(changes: textChanges.ChangeTracker, sourceFile: SourceFile, expression: Expression, statement: Statement) {
suppressLeadingAndTrailingTrivia(expression);
changes.replaceNode(sourceFile, statement, createReturn(expression));
const probablyNeedSemi = probablyUsesSemicolons(sourceFile);
changes.replaceNode(sourceFile, statement, createReturn(expression), {
leadingTriviaOption: textChanges.LeadingTriviaOption.Exclude,
trailingTriviaOption: textChanges.TrailingTriviaOption.Exclude,
suffix: probablyNeedSemi ? ";" : undefined
});
}

function removeBlockBodyBrace(changes: textChanges.ChangeTracker, sourceFile: SourceFile, declaration: ArrowFunction, expression: Expression, commentSource: Node, withParen: boolean) {
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/fourslash/codeFixCorrectReturnValue24.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ verify.codeFix({
description: "Add a return statement",
index: 0,
newFileContent:
`function Foo (a: () => number) { a() }
`function Foo (a: () => number) { a() }
Foo(() => { /* leading */ return 1 /* trailing */ })`
})
2 changes: 1 addition & 1 deletion tests/cases/fourslash/codeFixCorrectReturnValue25.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ verify.codeFix({
description: "Remove block body braces",
index: 1,
newFileContent:
`function Foo (a: () => number) { a() }
`function Foo (a: () => number) { a() }
Foo(() => /* leading */ 1 /* trailing */)`
})
23 changes: 23 additions & 0 deletions tests/cases/fourslash/codeFixCorrectReturnValue26.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/// <reference path='fourslash.ts' />
//// interface A {
//// bar: string;
//// }
////
//// function Foo (a: () => A) { a(); }
//// Foo(() => {
//// { bar: '123'; }
//// })

verify.codeFix({
description: "Add a return statement",
index: 0,
newFileContent:
`interface A {
bar: string;
}

function Foo (a: () => A) { a(); }
Foo(() => {
return { bar: '123' };
})`
})