mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
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:
@@ -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) {
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}`
|
||||
);
|
||||
Reference in New Issue
Block a user