fix(51716): find all references in imported JSDoc types (#51729)

This commit is contained in:
Oleksandr T 2022-12-20 23:16:17 +02:00 committed by GitHub
parent cf68a12d69
commit 6f4d340458
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 140 additions and 1 deletions

View File

@ -44,6 +44,7 @@ import {
isImportEqualsDeclaration,
isImportTypeNode,
isInJSFile,
isJSDocCallbackTag,
isJSDocTypedefTag,
isModuleExportsAccessExpression,
isNamedExports,
@ -612,7 +613,7 @@ export function getImportOrExportSymbol(node: Node, symbol: Symbol, checker: Typ
else if (isBinaryExpression(grandparent)) {
return getSpecialPropertyExport(grandparent, /*useLhsSymbol*/ true);
}
else if (isJSDocTypedefTag(parent)) {
else if (isJSDocTypedefTag(parent) || isJSDocCallbackTag(parent)) {
return exportInfo(symbol, ExportKind.Named);
}
}

View File

@ -0,0 +1,120 @@
// === /a.js ===
// /**
// * @callback /*FIND ALL REFS*/[|A|]
// * @param {unknown} response
// */
//
// module.exports = {};
// === /b.js ===
// /** @typedef {import("./a").[|A|]} A */
[
{
"definition": {
"containerKind": "",
"containerName": "",
"fileName": "/a.js",
"kind": "type",
"name": "type A = (response: unknown) => any",
"textSpan": {
"start": 17,
"length": 1
},
"displayParts": [
{
"text": "type",
"kind": "keyword"
},
{
"text": " ",
"kind": "space"
},
{
"text": "A",
"kind": "aliasName"
},
{
"text": " ",
"kind": "space"
},
{
"text": "=",
"kind": "operator"
},
{
"text": " ",
"kind": "space"
},
{
"text": "(",
"kind": "punctuation"
},
{
"text": "response",
"kind": "parameterName"
},
{
"text": ":",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "unknown",
"kind": "keyword"
},
{
"text": ")",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "=>",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "any",
"kind": "keyword"
}
],
"contextSpan": {
"start": 7,
"length": 42
}
},
"references": [
{
"textSpan": {
"start": 17,
"length": 1
},
"fileName": "/a.js",
"contextSpan": {
"start": 7,
"length": 42
},
"isWriteAccess": true,
"isDefinition": true
},
{
"textSpan": {
"start": 28,
"length": 1
},
"fileName": "/b.js",
"isWriteAccess": false,
"isDefinition": false
}
]
}
]

View File

@ -0,0 +1,18 @@
/// <reference path="fourslash.ts" />
// @module: commonjs
// @allowJs: true
// @checkJs: true
// @Filename: /a.js
/////**
//// * @callback /**/A
//// * @param {unknown} response
//// */
////
////module.exports = {};
// @Filename: /b.js
/////** @typedef {import("./a").A} A */
verify.baselineFindAllReferences("");