Fix extract type on JS function params

This commit is contained in:
Andrew Branch
2019-10-25 16:13:47 -07:00
parent f12eee2e4b
commit 07a371bbf6
2 changed files with 19 additions and 5 deletions
+1 -5
View File
@@ -68,7 +68,7 @@ namespace ts.refactor {
if (!selection || !isTypeNode(selection)) return undefined;
const checker = context.program.getTypeChecker();
const firstStatement = Debug.assertDefined(isJS ? findAncestor(selection, isStatementAndHasJSDoc) : findAncestor(selection, isStatement), "Should find a statement");
const firstStatement = Debug.assertDefined(findAncestor(selection, isStatement), "Should find a statement");
const typeParameters = collectTypeParameters(checker, selection, firstStatement, file);
if (!typeParameters) return undefined;
@@ -100,10 +100,6 @@ namespace ts.refactor {
return undefined;
}
function isStatementAndHasJSDoc(n: Node): n is (Statement & HasJSDoc) {
return isStatement(n) && hasJSDocNodes(n);
}
function rangeContainsSkipTrivia(r1: TextRange, node: Node, file: SourceFile): boolean {
return rangeContainsStartEnd(r1, skipTrivia(file.text, node.pos), node.end);
}
@@ -0,0 +1,18 @@
/// <reference path='fourslash.ts' />
// @allowJs: true
// @Filename: a.js
////function a(/** @type {/*a*/string/*b*/} */ b) {}
goTo.file('a.js')
goTo.select("a", "b");
edit.applyRefactor({
refactorName: "Extract type",
actionName: "Extract to typedef",
actionDescription: "Extract to typedef",
newContent: `/**
* @typedef {string} /*RENAME*/NewType
*/
function a(/** @type {NewType} */ b) {}`,
});