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

Add unqualified JSDoc member references #44202

Merged
merged 2 commits into from
May 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39320,7 +39320,14 @@ namespace ts {
const symbol = getIntrinsicTagSymbol(name.parent as JsxOpeningLikeElement);
return symbol === unknownSymbol ? undefined : symbol;
}
return resolveEntityName(name, meaning, /*ignoreErrors*/ false, /*dontResolveAlias*/ !isJSDoc, getHostSignatureFromJSDoc(name));
const result = resolveEntityName(name, meaning, /*ignoreErrors*/ false, /*dontResolveAlias*/ !isJSDoc, getHostSignatureFromJSDoc(name));
if (!result && isJSDoc) {
const container = findAncestor(name, or(isClassLike, isInterfaceDeclaration));
if (container) {
return resolveJSDocMemberName(name, getSymbolOfNode(container));
}
}
return result;
}
else if (name.kind === SyntaxKind.PropertyAccessExpression || name.kind === SyntaxKind.QualifiedName) {
const links = getNodeLinks(name);
Expand Down Expand Up @@ -39359,25 +39366,27 @@ namespace ts {
* 1. K#m as K.prototype.m for a class (or other value) K
* 2. K.m as K.prototype.m
* 3. I.m as I.m for a type I, or any other I.m that fails to resolve in (1) or (2)
*
* For unqualified names, a container K may be provided as a second argument.
*/
function resolveJSDocMemberName(name: EntityName | JSDocMemberName): Symbol | undefined {
function resolveJSDocMemberName(name: EntityName | JSDocMemberName, container?: Symbol): Symbol | undefined {
if (isEntityName(name)) {
const symbol = resolveEntityName(
name,
SymbolFlags.Type | SymbolFlags.Namespace | SymbolFlags.Value,
/*ignoreErrors*/ false,
/*dontResolveAlias*/ true,
getHostSignatureFromJSDoc(name));
if (symbol || isIdentifier(name)) {
// can't recur on identifier, so just return when it's undefined
// resolve static values first
const meaning = SymbolFlags.Type | SymbolFlags.Namespace | SymbolFlags.Value;
let symbol = resolveEntityName(name, meaning, /*ignoreErrors*/ false, /*dontResolveAlias*/ true, getHostSignatureFromJSDoc(name));
if (!symbol && isIdentifier(name) && container) {
symbol = getMergedSymbol(getSymbol(getExportsOfSymbol(container), name.escapedText, meaning));
}
if (symbol) {
return symbol;
}
}
const left = resolveJSDocMemberName(name.left);
const left = isIdentifier(name) ? container : resolveJSDocMemberName(name.left);
const right = isIdentifier(name) ? name.escapedText : name.right.escapedText;
if (left) {
const proto = left.flags & SymbolFlags.Value && getPropertyOfType(getTypeOfSymbol(left), "prototype" as __String);
const t = proto ? getTypeOfSymbol(proto) : getDeclaredTypeOfSymbol(left);
return getPropertyOfType(t, name.right.escapedText);
return getPropertyOfType(t, right);
}
}

Expand Down
110 changes: 100 additions & 10 deletions tests/baselines/reference/findAllReferencesLinkTag1.baseline.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
// n = 1
// static s() { }
// /**
// * {@link m}
// * @see {m}
// * {@link [|m|]}
// * @see {[|m|]}
// * {@link C.[|m|]}
// * @see {C.[|m|]}
// * {@link C#[|m|]}
Expand Down Expand Up @@ -144,6 +144,24 @@
"isWriteAccess": true,
"isDefinition": true
},
{
"textSpan": {
"start": 73,
"length": 1
},
"fileName": "/tests/cases/fourslash/findAllReferencesLinkTag1.ts",
"isWriteAccess": false,
"isDefinition": false
},
{
"textSpan": {
"start": 89,
"length": 1
},
"fileName": "/tests/cases/fourslash/findAllReferencesLinkTag1.ts",
"isWriteAccess": false,
"isDefinition": false
},
{
"textSpan": {
"start": 108,
Expand Down Expand Up @@ -219,8 +237,8 @@
// */
// p() { }
// /**
// * {@link n}
// * @see {n}
// * {@link [|n|]}
// * @see {[|n|]}
// * {@link C.[|n|]}
// * @see {C.[|n|]}
// * {@link C#[|n|]}
Expand Down Expand Up @@ -340,6 +358,24 @@
"isWriteAccess": true,
"isDefinition": true
},
{
"textSpan": {
"start": 265,
"length": 1
},
"fileName": "/tests/cases/fourslash/findAllReferencesLinkTag1.ts",
"isWriteAccess": false,
"isDefinition": false
},
{
"textSpan": {
"start": 281,
"length": 1
},
"fileName": "/tests/cases/fourslash/findAllReferencesLinkTag1.ts",
"isWriteAccess": false,
"isDefinition": false
},
{
"textSpan": {
"start": 300,
Expand Down Expand Up @@ -426,8 +462,8 @@
// */
// q() { }
// /**
// * {@link s}
// * @see {s}
// * {@link [|s|]}
// * @see {[|s|]}
// * {@link C.[|s|]}
// * @see {C.[|s|]}
// */
Expand Down Expand Up @@ -544,6 +580,24 @@
"isWriteAccess": true,
"isDefinition": true
},
{
"textSpan": {
"start": 457,
"length": 1
},
"fileName": "/tests/cases/fourslash/findAllReferencesLinkTag1.ts",
"isWriteAccess": false,
"isDefinition": false
},
{
"textSpan": {
"start": 473,
"length": 1
},
"fileName": "/tests/cases/fourslash/findAllReferencesLinkTag1.ts",
"isWriteAccess": false,
"isDefinition": false
},
{
"textSpan": {
"start": 492,
Expand Down Expand Up @@ -606,8 +660,8 @@
// [|a|]/*FIND ALL REFS*/()
// b: 1
// /**
// * {@link a}
// * @see {a}
// * {@link [|a|]}
// * @see {[|a|]}
// * {@link I.[|a|]}
// * @see {I.[|a|]}
// * {@link I#[|a|]}
Expand Down Expand Up @@ -712,6 +766,24 @@
"isWriteAccess": false,
"isDefinition": true
},
{
"textSpan": {
"start": 589,
"length": 1
},
"fileName": "/tests/cases/fourslash/findAllReferencesLinkTag1.ts",
"isWriteAccess": false,
"isDefinition": false
},
{
"textSpan": {
"start": 605,
"length": 1
},
"fileName": "/tests/cases/fourslash/findAllReferencesLinkTag1.ts",
"isWriteAccess": false,
"isDefinition": false
},
{
"textSpan": {
"start": 624,
Expand Down Expand Up @@ -801,8 +873,8 @@
// */
// c()
// /**
// * {@link b}
// * @see {b}
// * {@link [|b|]}
// * @see {[|b|]}
// * {@link I.[|b|]}
// * @see {I.[|b|]}
// */
Expand Down Expand Up @@ -890,6 +962,24 @@
"isWriteAccess": false,
"isDefinition": true
},
{
"textSpan": {
"start": 720,
"length": 1
},
"fileName": "/tests/cases/fourslash/findAllReferencesLinkTag1.ts",
"isWriteAccess": false,
"isDefinition": false
},
{
"textSpan": {
"start": 736,
"length": 1
},
"fileName": "/tests/cases/fourslash/findAllReferencesLinkTag1.ts",
"isWriteAccess": false,
"isDefinition": false
},
{
"textSpan": {
"start": 755,
Expand Down