Fix #47753 - Organize imports removes type imports that are only referenced in @link (jsdoc) (#47824)

* Added unit test

* Added baseline test

* Dirty solution

* Code refactoring and improvements

* Added more test cases

* Refactor to use flatMap

* Added utility function to get all Nodes with JSDocs

* Minor improvements

* Use recursion to check all tree levels

* Removed unit test

* Removed previous changes

* Updated resolveEntityName call

* Updated dontResolveAlias clause

* Updated symbol flags

* Updated baseline

* Fix dont resolve alias problem

* Updated tests
This commit is contained in:
Felipe Armoni
2022-04-29 13:45:00 -07:00
committed by GitHub
parent 18b08fc7c9
commit fd06132ce9
4 changed files with 96 additions and 16 deletions
+1 -1
View File
@@ -41898,7 +41898,7 @@ namespace ts {
const symbol = getIntrinsicTagSymbol(name.parent as JsxOpeningLikeElement);
return symbol === unknownSymbol ? undefined : symbol;
}
const result = resolveEntityName(name, meaning, /*ignoreErrors*/ false, /*dontResolveAlias*/ !isJSDoc, getHostSignatureFromJSDoc(name));
const result = resolveEntityName(name, meaning, /*ignoreErrors*/ false, /* dontResolveAlias */ true, getHostSignatureFromJSDoc(name));
if (!result && isJSDoc) {
const container = findAncestor(name, or(isClassLike, isInterfaceDeclaration));
if (container) {
+15 -15
View File
@@ -59,10 +59,10 @@
"text": "C",
"kind": "linkName",
"target": {
"fileName": "/jsdocLink3.ts",
"fileName": "/module1.ts",
"textSpan": {
"start": 0,
"length": 18
"start": 9,
"length": 1
}
}
},
@@ -87,10 +87,10 @@
"text": "C",
"kind": "linkName",
"target": {
"fileName": "/jsdocLink3.ts",
"fileName": "/module1.ts",
"textSpan": {
"start": 0,
"length": 18
"start": 9,
"length": 1
}
}
},
@@ -110,10 +110,10 @@
"text": "C()",
"kind": "linkName",
"target": {
"fileName": "/jsdocLink3.ts",
"fileName": "/module1.ts",
"textSpan": {
"start": 0,
"length": 18
"start": 9,
"length": 1
}
}
},
@@ -133,10 +133,10 @@
"text": "C",
"kind": "linkName",
"target": {
"fileName": "/jsdocLink3.ts",
"fileName": "/module1.ts",
"textSpan": {
"start": 0,
"length": 18
"start": 9,
"length": 1
}
}
},
@@ -181,10 +181,10 @@
"text": "C",
"kind": "linkName",
"target": {
"fileName": "/jsdocLink3.ts",
"fileName": "/module1.ts",
"textSpan": {
"start": 0,
"length": 18
"start": 9,
"length": 1
}
}
},
@@ -0,0 +1,18 @@
/// <reference path="fourslash.ts" />
// @Filename: /module.ts
////import type { ZodType } from './declaration';
////
/////** Intended to be used in combination with {@link ZodType} */
////export function fun() { /* ... */ }
// @Filename: /declaration.ts
//// type ZodType = {};
//// export type { ZodType }
verify.organizeImports(`import type { ZodType } from './declaration';
/** Intended to be used in combination with {@link ZodType} */
export function fun() { /* ... */ }`
);
@@ -0,0 +1,62 @@
/// <reference path="fourslash.ts" />
// @Filename: /test.ts
////import { TypeA, TypeB, TypeC, UnreferencedType } from './my-types';
////
/////**
//// * MyClass {@link TypeA}
//// */
////export class MyClass {
////
//// /**
//// * Some Property {@link TypeB}
//// */
//// public something;
////
//// /**
//// * Some function {@link TypeC}
//// */
//// public myMethod() {
////
//// /**
//// * Some lambda function {@link TypeC}
//// */
//// const someFunction = () => {
//// return '';
//// }
//// someFunction();
//// }
////}
// @Filename: /my-types.ts
//// export type TypeA = string;
//// export class TypeB { }
//// export type TypeC = () => string;
verify.organizeImports(`import { TypeA, TypeB, TypeC } from './my-types';
/**
* MyClass {@link TypeA}
*/
export class MyClass {
/**
* Some Property {@link TypeB}
*/
public something;
/**
* Some function {@link TypeC}
*/
public myMethod() {
/**
* Some lambda function {@link TypeC}
*/
const someFunction = () => {
return '';
}
someFunction();
}
}`
);