Skip to content

Commit

Permalink
fix(55937): 'Infer function return type' offered in preceding trivia (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
a-tarasyuk authored Oct 2, 2023
1 parent d9cd2d0 commit c640c5d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/services/refactors/inferFunctionReturnType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
FunctionDeclaration,
FunctionExpression,
getLocaleSpecificMessage,
getTokenAtPosition,
getTouchingPropertyName,
isArrowFunction,
isBlock,
isInJSFile,
Expand Down Expand Up @@ -104,7 +104,7 @@ function doChange(sourceFile: SourceFile, changes: textChanges.ChangeTracker, de
function getInfo(context: RefactorContext): FunctionInfo | RefactorErrorInfo | undefined {
if (isInJSFile(context.file) || !refactorKindBeginsWith(inferReturnTypeAction.kind, context.kind)) return;

const token = getTokenAtPosition(context.file, context.startPosition);
const token = getTouchingPropertyName(context.file, context.startPosition);
const declaration = findAncestor(token, n =>
isBlock(n) || n.parent && isArrowFunction(n.parent) && (n.kind === SyntaxKind.EqualsGreaterThanToken || n.parent.body === n) ? "quit" :
isConvertibleDeclaration(n)) as ConvertibleDeclaration | undefined;
Expand Down
10 changes: 10 additions & 0 deletions tests/cases/fourslash/refactorInferFunctionReturnType24.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/// <reference path='fourslash.ts' />

////let x = 10;/*a*//*b*/
////
////function func() {
//// return 10;
////}

goTo.select("a", "b");
verify.not.refactorAvailable("Infer function return type");

0 comments on commit c640c5d

Please sign in to comment.