Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(41825): JSDoc equivalent of import * #57207

Merged
merged 32 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
953e54b
feat(41825): add importType jsdoc tag
a-tarasyuk Jan 28, 2024
b67cba6
add jsdocImportTypeTag parsing tests
a-tarasyuk Jan 29, 2024
fc4ac15
update baseline
a-tarasyuk Jan 29, 2024
df23ce3
add jsdoc import type tag go to definition tests
a-tarasyuk Jan 29, 2024
0b0029d
jsdoc import type completions
a-tarasyuk Jan 30, 2024
0a20ad3
jsdoc import type find-all-refs/rename
a-tarasyuk Jan 30, 2024
386120f
rename importType to import
a-tarasyuk Jan 31, 2024
08806b6
add tests
a-tarasyuk Feb 1, 2024
d629693
auto import fix to existing jsdoc imports
a-tarasyuk Feb 1, 2024
6ec3b27
cleanup
a-tarasyuk Feb 2, 2024
ad24624
handle multiline import clause
a-tarasyuk Feb 3, 2024
26f633f
add tests
a-tarasyuk Feb 3, 2024
82f79be
cleanup
a-tarasyuk Feb 7, 2024
a76450e
add additional import tag parsing test
a-tarasyuk Feb 8, 2024
9003fbf
add additional import tag parsing tests
a-tarasyuk Feb 8, 2024
5a6cb6b
handle jsdoc import tags in convert import refactoring
a-tarasyuk Feb 8, 2024
67caac1
add additional tests
a-tarasyuk Feb 8, 2024
f7da8be
Merge branch 'main' of https://github.com/microsoft/TypeScript into f…
a-tarasyuk Feb 12, 2024
dd2a481
add import attrs to import tag. add additional tests
a-tarasyuk Feb 13, 2024
af9bc71
emit import declarations
a-tarasyuk Mar 1, 2024
5bbe7e7
Merge branch 'main' of https://github.com/microsoft/TypeScript into f…
a-tarasyuk Mar 1, 2024
7caacbd
emit type only imports
a-tarasyuk Mar 2, 2024
340ea99
Merge branch 'main' of https://github.com/microsoft/TypeScript into f…
a-tarasyuk Mar 7, 2024
e28ff89
Merge branch 'main' of https://github.com/microsoft/TypeScript into f…
a-tarasyuk Mar 16, 2024
2e4b90d
fix types
a-tarasyuk Mar 16, 2024
d37f70c
Merge branch 'main' of https://github.com/microsoft/TypeScript into f…
a-tarasyuk Mar 18, 2024
6bd9d73
always display errors for JSDoc imports in import attributes
a-tarasyuk Mar 18, 2024
aa9600d
Merge branch 'main' of https://github.com/microsoft/TypeScript into f…
a-tarasyuk Mar 18, 2024
32bbf4c
Merge branch 'main' of https://github.com/microsoft/TypeScript into f…
a-tarasyuk Mar 20, 2024
0da4e23
Merge branch 'main' of https://github.com/microsoft/TypeScript into f…
a-tarasyuk Mar 21, 2024
51f902e
Merge branch 'main' of https://github.com/microsoft/TypeScript into f…
a-tarasyuk Mar 26, 2024
653955e
add tests
a-tarasyuk Mar 26, 2024
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
jsdoc import type find-all-refs/rename
  • Loading branch information
a-tarasyuk committed Jan 30, 2024
commit 0a20ad3154f4d1a7a3da37f9a9c51d2a4cabb5db
2 changes: 1 addition & 1 deletion src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5586,7 +5586,7 @@ export interface ValidImportTypeNode extends ImportTypeNode {

/** @internal */
export type AnyValidImportOrReExport =
| (ImportDeclaration | ExportDeclaration) & { moduleSpecifier: StringLiteral; }
| (ImportDeclaration | ExportDeclaration | JSDocImportTypeTag) & { moduleSpecifier: StringLiteral; }
| ImportEqualsDeclaration & { moduleReference: ExternalModuleReference & { expression: StringLiteral; }; }
| RequireOrImportCall
| ValidImportTypeNode;
Expand Down
3 changes: 2 additions & 1 deletion src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4022,6 +4022,7 @@ export function tryGetImportFromModuleSpecifier(node: StringLiteralLike): AnyVal
switch (node.parent.kind) {
case SyntaxKind.ImportDeclaration:
case SyntaxKind.ExportDeclaration:
case SyntaxKind.JSDocImportTypeTag:
return node.parent as AnyValidImportOrReExport;
case SyntaxKind.ExternalModuleReference:
return (node.parent as ExternalModuleReference).parent as AnyValidImportOrReExport;
Expand Down Expand Up @@ -4070,7 +4071,7 @@ export function getNamespaceDeclarationNode(node: ImportDeclaration | ImportEqua
}

/** @internal */
export function isDefaultImport(node: ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration): boolean {
export function isDefaultImport(node: ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration | JSDocImportTypeTag): boolean {
return node.kind === SyntaxKind.ImportDeclaration && !!node.importClause && !!node.importClause.name;
}

Expand Down
6 changes: 4 additions & 2 deletions src/services/importTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import {
isVariableDeclaration,
isVariableDeclarationInitializedToBareOrAccessedRequire,
isVariableStatement,
JSDocImportTypeTag,
ModifierFlags,
ModuleBlock,
ModuleDeclaration,
Expand Down Expand Up @@ -138,7 +139,7 @@ interface AmbientModuleDeclaration extends ModuleDeclaration {
}
type SourceFileLike = SourceFile | AmbientModuleDeclaration;
// Identifier for the case of `const x = require("y")`.
type Importer = AnyImportOrReExport | ValidImportTypeNode | Identifier;
type Importer = AnyImportOrReExport | ValidImportTypeNode | Identifier | JSDocImportTypeTag;
type ImporterOrCallExpression = Importer | CallExpression;

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

case SyntaxKind.ImportDeclaration:
case SyntaxKind.JSDocImportTypeTag:
directImports.push(direct);
const namedBindings = direct.importClause && direct.importClause.namedBindings;
if (namedBindings && namedBindings.kind === SyntaxKind.NamespaceImport) {
Expand Down Expand Up @@ -267,7 +269,7 @@ function getImportersForExport(
});
}

function handleNamespaceImport(importDeclaration: ImportEqualsDeclaration | ImportDeclaration, name: Identifier, isReExport: boolean, alreadyAddedDirect: boolean): void {
function handleNamespaceImport(importDeclaration: ImportEqualsDeclaration | ImportDeclaration | JSDocImportTypeTag, name: Identifier, isReExport: boolean, alreadyAddedDirect: boolean): void {
if (exportKind === ExportKind.ExportEquals) {
// This is a direct import, not import-as-namespace.
if (!alreadyAddedDirect) directImports.push(importDeclaration);
Expand Down
105 changes: 105 additions & 0 deletions tests/baselines/reference/findAllRefsJsDocImportTypeTag.baseline.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
// === findAllReferences ===
// === /a.js ===
// /**
// * <|@importType { [|{| defId: 0, isWriteAccess: true |}A|] } from "./b";
// |>*/
//
// /**
// * @param { [|{| defId: 0 |}A|]/*FIND ALL REFS*/ } a
// */
// function f(a) {}

// === /b.ts ===
// <|export interface [|{| defId: 1, isWriteAccess: true |}A|] { }|>

// === Definitions ===
// === /a.js ===
// /**
// * <|@importType { [|{| defId: 0 |}A|] } from "./b";
// |>*/
//
// /**
// * @param { A/*FIND ALL REFS*/ } a
// */
// function f(a) {}

// === /b.ts ===
// <|export interface [|{| defId: 1 |}A|] { }|>

// === Details ===
[
{
"defId": 0,
"containerKind": "",
"containerName": "",
"kind": "alias",
"name": "(alias) interface A\nimport A",
"displayParts": [
{
"text": "(",
"kind": "punctuation"
},
{
"text": "alias",
"kind": "text"
},
{
"text": ")",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "interface",
"kind": "keyword"
},
{
"text": " ",
"kind": "space"
},
{
"text": "A",
"kind": "aliasName"
},
{
"text": "\n",
"kind": "lineBreak"
},
{
"text": "import",
"kind": "keyword"
},
{
"text": " ",
"kind": "space"
},
{
"text": "A",
"kind": "aliasName"
}
]
},
{
"defId": 1,
"containerKind": "",
"containerName": "",
"kind": "interface",
"name": "interface A",
"displayParts": [
{
"text": "interface",
"kind": "keyword"
},
{
"text": " ",
"kind": "space"
},
{
"text": "A",
"kind": "interfaceName"
}
]
}
]
10 changes: 10 additions & 0 deletions tests/baselines/reference/renameJsDocImportTypeTag.baseline.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// === findRenameLocations ===
// === /a.js ===
// /**
// * <|@importType { /*START PREFIX*/A as [|ARENAME|] } from "./b";
// |>*/
//
// /**
// * @param { [|ARENAME|]/*RENAME*/ } a
// */
// function f(a) {}
19 changes: 19 additions & 0 deletions tests/cases/fourslash/findAllRefsJsDocImportTypeTag.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/// <reference path='fourslash.ts' />

// @allowJS: true
// @checkJs: true

// @Filename: /b.ts
////export interface A { }

// @Filename: /a.js
/////**
//// * @importType { A } from "./b";
//// */
////
/////**
//// * @param { [|A/**/|] } a
//// */
////function f(a) {}

verify.baselineFindAllReferences("");
19 changes: 19 additions & 0 deletions tests/cases/fourslash/renameJsDocImportTypeTag.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/// <reference path='fourslash.ts' />

// @allowJS: true
// @checkJs: true

// @Filename: /b.ts
////export interface A { }

// @Filename: /a.js
/////**
//// * @importType { A } from "./b";
//// */
////
/////**
//// * @param { [|A/**/|] } a
//// */
////function f(a) {}

verify.baselineRename("");
Loading