Skip to content

Commit 0a20ad3

Browse files
committed
jsdoc import type find-all-refs/rename
1 parent 0b0029d commit 0a20ad3

7 files changed

+160
-4
lines changed

src/compiler/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5586,7 +5586,7 @@ export interface ValidImportTypeNode extends ImportTypeNode {
55865586

55875587
/** @internal */
55885588
export type AnyValidImportOrReExport =
5589-
| (ImportDeclaration | ExportDeclaration) & { moduleSpecifier: StringLiteral; }
5589+
| (ImportDeclaration | ExportDeclaration | JSDocImportTypeTag) & { moduleSpecifier: StringLiteral; }
55905590
| ImportEqualsDeclaration & { moduleReference: ExternalModuleReference & { expression: StringLiteral; }; }
55915591
| RequireOrImportCall
55925592
| ValidImportTypeNode;

src/compiler/utilities.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -4022,6 +4022,7 @@ export function tryGetImportFromModuleSpecifier(node: StringLiteralLike): AnyVal
40224022
switch (node.parent.kind) {
40234023
case SyntaxKind.ImportDeclaration:
40244024
case SyntaxKind.ExportDeclaration:
4025+
case SyntaxKind.JSDocImportTypeTag:
40254026
return node.parent as AnyValidImportOrReExport;
40264027
case SyntaxKind.ExternalModuleReference:
40274028
return (node.parent as ExternalModuleReference).parent as AnyValidImportOrReExport;
@@ -4070,7 +4071,7 @@ export function getNamespaceDeclarationNode(node: ImportDeclaration | ImportEqua
40704071
}
40714072

40724073
/** @internal */
4073-
export function isDefaultImport(node: ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration): boolean {
4074+
export function isDefaultImport(node: ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration | JSDocImportTypeTag): boolean {
40744075
return node.kind === SyntaxKind.ImportDeclaration && !!node.importClause && !!node.importClause.name;
40754076
}
40764077

src/services/importTracker.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ import {
5757
isVariableDeclaration,
5858
isVariableDeclarationInitializedToBareOrAccessedRequire,
5959
isVariableStatement,
60+
JSDocImportTypeTag,
6061
ModifierFlags,
6162
ModuleBlock,
6263
ModuleDeclaration,
@@ -138,7 +139,7 @@ interface AmbientModuleDeclaration extends ModuleDeclaration {
138139
}
139140
type SourceFileLike = SourceFile | AmbientModuleDeclaration;
140141
// Identifier for the case of `const x = require("y")`.
141-
type Importer = AnyImportOrReExport | ValidImportTypeNode | Identifier;
142+
type Importer = AnyImportOrReExport | ValidImportTypeNode | Identifier | JSDocImportTypeTag;
142143
type ImporterOrCallExpression = Importer | CallExpression;
143144

144145
/** Returns import statements that directly reference the exporting module, and a list of files that may access the module through a namespace. */
@@ -215,6 +216,7 @@ function getImportersForExport(
215216
break;
216217

217218
case SyntaxKind.ImportDeclaration:
219+
case SyntaxKind.JSDocImportTypeTag:
218220
directImports.push(direct);
219221
const namedBindings = direct.importClause && direct.importClause.namedBindings;
220222
if (namedBindings && namedBindings.kind === SyntaxKind.NamespaceImport) {
@@ -267,7 +269,7 @@ function getImportersForExport(
267269
});
268270
}
269271

270-
function handleNamespaceImport(importDeclaration: ImportEqualsDeclaration | ImportDeclaration, name: Identifier, isReExport: boolean, alreadyAddedDirect: boolean): void {
272+
function handleNamespaceImport(importDeclaration: ImportEqualsDeclaration | ImportDeclaration | JSDocImportTypeTag, name: Identifier, isReExport: boolean, alreadyAddedDirect: boolean): void {
271273
if (exportKind === ExportKind.ExportEquals) {
272274
// This is a direct import, not import-as-namespace.
273275
if (!alreadyAddedDirect) directImports.push(importDeclaration);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
// === findAllReferences ===
2+
// === /a.js ===
3+
// /**
4+
// * <|@importType { [|{| defId: 0, isWriteAccess: true |}A|] } from "./b";
5+
// |>*/
6+
//
7+
// /**
8+
// * @param { [|{| defId: 0 |}A|]/*FIND ALL REFS*/ } a
9+
// */
10+
// function f(a) {}
11+
12+
// === /b.ts ===
13+
// <|export interface [|{| defId: 1, isWriteAccess: true |}A|] { }|>
14+
15+
// === Definitions ===
16+
// === /a.js ===
17+
// /**
18+
// * <|@importType { [|{| defId: 0 |}A|] } from "./b";
19+
// |>*/
20+
//
21+
// /**
22+
// * @param { A/*FIND ALL REFS*/ } a
23+
// */
24+
// function f(a) {}
25+
26+
// === /b.ts ===
27+
// <|export interface [|{| defId: 1 |}A|] { }|>
28+
29+
// === Details ===
30+
[
31+
{
32+
"defId": 0,
33+
"containerKind": "",
34+
"containerName": "",
35+
"kind": "alias",
36+
"name": "(alias) interface A\nimport A",
37+
"displayParts": [
38+
{
39+
"text": "(",
40+
"kind": "punctuation"
41+
},
42+
{
43+
"text": "alias",
44+
"kind": "text"
45+
},
46+
{
47+
"text": ")",
48+
"kind": "punctuation"
49+
},
50+
{
51+
"text": " ",
52+
"kind": "space"
53+
},
54+
{
55+
"text": "interface",
56+
"kind": "keyword"
57+
},
58+
{
59+
"text": " ",
60+
"kind": "space"
61+
},
62+
{
63+
"text": "A",
64+
"kind": "aliasName"
65+
},
66+
{
67+
"text": "\n",
68+
"kind": "lineBreak"
69+
},
70+
{
71+
"text": "import",
72+
"kind": "keyword"
73+
},
74+
{
75+
"text": " ",
76+
"kind": "space"
77+
},
78+
{
79+
"text": "A",
80+
"kind": "aliasName"
81+
}
82+
]
83+
},
84+
{
85+
"defId": 1,
86+
"containerKind": "",
87+
"containerName": "",
88+
"kind": "interface",
89+
"name": "interface A",
90+
"displayParts": [
91+
{
92+
"text": "interface",
93+
"kind": "keyword"
94+
},
95+
{
96+
"text": " ",
97+
"kind": "space"
98+
},
99+
{
100+
"text": "A",
101+
"kind": "interfaceName"
102+
}
103+
]
104+
}
105+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// === findRenameLocations ===
2+
// === /a.js ===
3+
// /**
4+
// * <|@importType { /*START PREFIX*/A as [|ARENAME|] } from "./b";
5+
// |>*/
6+
//
7+
// /**
8+
// * @param { [|ARENAME|]/*RENAME*/ } a
9+
// */
10+
// function f(a) {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @allowJS: true
4+
// @checkJs: true
5+
6+
// @Filename: /b.ts
7+
////export interface A { }
8+
9+
// @Filename: /a.js
10+
/////**
11+
//// * @importType { A } from "./b";
12+
//// */
13+
////
14+
/////**
15+
//// * @param { [|A/**/|] } a
16+
//// */
17+
////function f(a) {}
18+
19+
verify.baselineFindAllReferences("");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @allowJS: true
4+
// @checkJs: true
5+
6+
// @Filename: /b.ts
7+
////export interface A { }
8+
9+
// @Filename: /a.js
10+
/////**
11+
//// * @importType { A } from "./b";
12+
//// */
13+
////
14+
/////**
15+
//// * @param { [|A/**/|] } a
16+
//// */
17+
////function f(a) {}
18+
19+
verify.baselineRename("");

0 commit comments

Comments
 (0)