Skip to content

Commit 5b49a14

Browse files
committed
fix symbol resolve
1 parent c89574c commit 5b49a14

File tree

8 files changed

+157
-86
lines changed

8 files changed

+157
-86
lines changed

src/compiler/checker.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36206,6 +36206,17 @@ namespace ts {
3620636206
return node.parent.kind === SyntaxKind.ExpressionWithTypeArguments;
3620736207
}
3620836208

36209+
function isJSDocEntryNameReference(node: Identifier | PrivateIdentifier | PropertyAccessExpression | QualifiedName): boolean {
36210+
while (node.parent.kind === SyntaxKind.QualifiedName) {
36211+
node = node.parent as QualifiedName;
36212+
}
36213+
while (node.parent.kind === SyntaxKind.PropertyAccessExpression) {
36214+
node = node.parent as PropertyAccessExpression;
36215+
}
36216+
36217+
return node.parent.kind === SyntaxKind.JSDocNameExpression;
36218+
}
36219+
3620936220
function forEachEnclosingClass<T>(node: Node, callback: (node: Node) => T | undefined): T | undefined {
3621036221
let result: T | undefined;
3621136222

@@ -36390,6 +36401,10 @@ namespace ts {
3639036401
const meaning = name.parent.kind === SyntaxKind.TypeReference ? SymbolFlags.Type : SymbolFlags.Namespace;
3639136402
return resolveEntityName(<EntityName>name, meaning, /*ignoreErrors*/ false, /*dontResolveAlias*/ true);
3639236403
}
36404+
else if (isJSDocEntryNameReference(name)) {
36405+
const meaning = SymbolFlags.Type | SymbolFlags.Namespace | SymbolFlags.Value;
36406+
return resolveEntityName(<EntityName>name, meaning, /*ignoreErrors*/ false, /*dontResolveAlias*/ true);
36407+
}
3639336408

3639436409
if (name.parent.kind === SyntaxKind.TypePredicate) {
3639536410
return resolveEntityName(<Identifier>name, /*meaning*/ SymbolFlags.FunctionScopedVariable);

src/compiler/emitter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3516,7 +3516,7 @@ namespace ts {
35163516
emit(node.name);
35173517
writePunctuation("}");
35183518
}
3519-
3519+
35203520
function emitJSDocHeritageTag(tag: JSDocImplementsTag | JSDocAugmentsTag) {
35213521
emitJSDocTagName(tag.tagName);
35223522
writeSpace();

src/compiler/factory/nodeFactory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4276,7 +4276,7 @@ namespace ts {
42764276
? update(createJSDocSeeTag(tagName, name, comment), node)
42774277
: node;
42784278
}
4279-
4279+
42804280
// @api
42814281
function createJSDocNameExpression(name: EntityName): JSDocNameExpression {
42824282
const node = createBaseNode<JSDocNameExpression>(SyntaxKind.JSDocNameExpression);

src/compiler/parser.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,11 @@ namespace ts {
477477
visitNode(cbNode, (<JSDocFunctionType>node).type);
478478
case SyntaxKind.JSDocComment:
479479
return visitNodes(cbNode, cbNodes, (<JSDoc>node).tags);
480+
case SyntaxKind.JSDocSeeTag:
481+
return visitNode(cbNode, (node as JSDocSeeTag).tagName) ||
482+
visitNode(cbNode, (node as JSDocSeeTag).name);
483+
case SyntaxKind.JSDocNameExpression:
484+
return visitNode(cbNode, (node as JSDocNameExpression).name);
480485
case SyntaxKind.JSDocParameterTag:
481486
case SyntaxKind.JSDocPropertyTag:
482487
return visitNode(cbNode, (node as JSDocTag).tagName) ||
@@ -7150,7 +7155,7 @@ namespace ts {
71507155
export function parseJSDocNameExpression(mayOmitBraces?: boolean): JSDocNameExpression {
71517156
const pos = getNodePos();
71527157
const hasBrace = (mayOmitBraces ? parseOptional : parseExpected)(SyntaxKind.OpenBraceToken);
7153-
const entityName = doInsideOfContext(NodeFlags.JSDoc, () => parseEntityName(/* allowReservedWords*/ true));
7158+
const entityName = doInsideOfContext(NodeFlags.JSDoc, () => parseEntityName(/* allowReservedWords*/ true));
71547159
if (!mayOmitBraces || hasBrace) {
71557160
parseExpectedJSDoc(SyntaxKind.CloseBraceToken);
71567161
}

tests/baselines/reference/api/tsserverlibrary.d.ts

Lines changed: 55 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -403,44 +403,46 @@ declare namespace ts {
403403
UnparsedSource = 296,
404404
InputFiles = 297,
405405
JSDocTypeExpression = 298,
406-
JSDocAllType = 299,
407-
JSDocUnknownType = 300,
408-
JSDocNullableType = 301,
409-
JSDocNonNullableType = 302,
410-
JSDocOptionalType = 303,
411-
JSDocFunctionType = 304,
412-
JSDocVariadicType = 305,
413-
JSDocNamepathType = 306,
414-
JSDocComment = 307,
415-
JSDocTypeLiteral = 308,
416-
JSDocSignature = 309,
417-
JSDocTag = 310,
418-
JSDocAugmentsTag = 311,
419-
JSDocImplementsTag = 312,
420-
JSDocAuthorTag = 313,
421-
JSDocDeprecatedTag = 314,
422-
JSDocClassTag = 315,
423-
JSDocPublicTag = 316,
424-
JSDocPrivateTag = 317,
425-
JSDocProtectedTag = 318,
426-
JSDocReadonlyTag = 319,
427-
JSDocCallbackTag = 320,
428-
JSDocEnumTag = 321,
429-
JSDocParameterTag = 322,
430-
JSDocReturnTag = 323,
431-
JSDocThisTag = 324,
432-
JSDocTypeTag = 325,
433-
JSDocTemplateTag = 326,
434-
JSDocTypedefTag = 327,
435-
JSDocPropertyTag = 328,
436-
SyntaxList = 329,
437-
NotEmittedStatement = 330,
438-
PartiallyEmittedExpression = 331,
439-
CommaListExpression = 332,
440-
MergeDeclarationMarker = 333,
441-
EndOfDeclarationMarker = 334,
442-
SyntheticReferenceExpression = 335,
443-
Count = 336,
406+
JSDocNameExpression = 299,
407+
JSDocAllType = 300,
408+
JSDocUnknownType = 301,
409+
JSDocNullableType = 302,
410+
JSDocNonNullableType = 303,
411+
JSDocOptionalType = 304,
412+
JSDocFunctionType = 305,
413+
JSDocVariadicType = 306,
414+
JSDocNamepathType = 307,
415+
JSDocComment = 308,
416+
JSDocTypeLiteral = 309,
417+
JSDocSignature = 310,
418+
JSDocTag = 311,
419+
JSDocAugmentsTag = 312,
420+
JSDocImplementsTag = 313,
421+
JSDocAuthorTag = 314,
422+
JSDocDeprecatedTag = 315,
423+
JSDocClassTag = 316,
424+
JSDocPublicTag = 317,
425+
JSDocPrivateTag = 318,
426+
JSDocProtectedTag = 319,
427+
JSDocReadonlyTag = 320,
428+
JSDocCallbackTag = 321,
429+
JSDocEnumTag = 322,
430+
JSDocParameterTag = 323,
431+
JSDocReturnTag = 324,
432+
JSDocThisTag = 325,
433+
JSDocTypeTag = 326,
434+
JSDocTemplateTag = 327,
435+
JSDocTypedefTag = 328,
436+
JSDocSeeTag = 329,
437+
JSDocPropertyTag = 330,
438+
SyntaxList = 331,
439+
NotEmittedStatement = 332,
440+
PartiallyEmittedExpression = 333,
441+
CommaListExpression = 334,
442+
MergeDeclarationMarker = 335,
443+
EndOfDeclarationMarker = 336,
444+
SyntheticReferenceExpression = 337,
445+
Count = 338,
444446
FirstAssignment = 62,
445447
LastAssignment = 77,
446448
FirstCompoundAssignment = 63,
@@ -469,9 +471,9 @@ declare namespace ts {
469471
LastStatement = 245,
470472
FirstNode = 156,
471473
FirstJSDocNode = 298,
472-
LastJSDocNode = 328,
473-
FirstJSDocTagNode = 310,
474-
LastJSDocTagNode = 328,
474+
LastJSDocNode = 330,
475+
FirstJSDocTagNode = 311,
476+
LastJSDocTagNode = 330,
475477
}
476478
export type TriviaSyntaxKind = SyntaxKind.SingleLineCommentTrivia | SyntaxKind.MultiLineCommentTrivia | SyntaxKind.NewLineTrivia | SyntaxKind.WhitespaceTrivia | SyntaxKind.ShebangTrivia | SyntaxKind.ConflictMarkerTrivia;
477479
export type LiteralSyntaxKind = SyntaxKind.NumericLiteral | SyntaxKind.BigIntLiteral | SyntaxKind.StringLiteral | SyntaxKind.JsxText | SyntaxKind.JsxTextAllWhiteSpaces | SyntaxKind.RegularExpressionLiteral | SyntaxKind.NoSubstitutionTemplateLiteral;
@@ -1682,6 +1684,10 @@ declare namespace ts {
16821684
readonly kind: SyntaxKind.JSDocTypeExpression;
16831685
readonly type: TypeNode;
16841686
}
1687+
export interface JSDocNameExpression extends Node {
1688+
readonly kind: SyntaxKind.JSDocNameExpression;
1689+
readonly name: EntityName;
1690+
}
16851691
export interface JSDocType extends TypeNode {
16861692
_jsDocTypeBrand: any;
16871693
}
@@ -1780,6 +1786,10 @@ declare namespace ts {
17801786
readonly constraint: JSDocTypeExpression | undefined;
17811787
readonly typeParameters: NodeArray<TypeParameterDeclaration>;
17821788
}
1789+
export interface JSDocSeeTag extends JSDocTag {
1790+
readonly kind: SyntaxKind.JSDocSeeTag;
1791+
readonly name: JSDocNameExpression;
1792+
}
17831793
export interface JSDocReturnTag extends JSDocTag {
17841794
readonly kind: SyntaxKind.JSDocReturnTag;
17851795
readonly typeExpression?: JSDocTypeExpression;
@@ -3399,6 +3409,8 @@ declare namespace ts {
33993409
updateJSDocNamepathType(node: JSDocNamepathType, type: TypeNode): JSDocNamepathType;
34003410
createJSDocTypeExpression(type: TypeNode): JSDocTypeExpression;
34013411
updateJSDocTypeExpression(node: JSDocTypeExpression, type: TypeNode): JSDocTypeExpression;
3412+
createJSDocNameExpression(name: EntityName): JSDocNameExpression;
3413+
updateJSDocNameExpression(node: JSDocNameExpression, name: EntityName): JSDocNameExpression;
34023414
createJSDocTypeLiteral(jsDocPropertyTags?: readonly JSDocPropertyLikeTag[], isArrayType?: boolean): JSDocTypeLiteral;
34033415
updateJSDocTypeLiteral(node: JSDocTypeLiteral, jsDocPropertyTags: readonly JSDocPropertyLikeTag[] | undefined, isArrayType: boolean | undefined): JSDocTypeLiteral;
34043416
createJSDocSignature(typeParameters: readonly JSDocTemplateTag[] | undefined, parameters: readonly JSDocParameterTag[], type?: JSDocReturnTag): JSDocSignature;
@@ -3413,6 +3425,8 @@ declare namespace ts {
34133425
updateJSDocPropertyTag(node: JSDocPropertyTag, tagName: Identifier | undefined, name: EntityName, isBracketed: boolean, typeExpression: JSDocTypeExpression | undefined, isNameFirst: boolean, comment: string | undefined): JSDocPropertyTag;
34143426
createJSDocTypeTag(tagName: Identifier | undefined, typeExpression: JSDocTypeExpression, comment?: string): JSDocTypeTag;
34153427
updateJSDocTypeTag(node: JSDocTypeTag, tagName: Identifier | undefined, typeExpression: JSDocTypeExpression, comment: string | undefined): JSDocTypeTag;
3428+
createJSDocSeeTag(tagName: Identifier | undefined, nameExpression: JSDocNameExpression, comment?: string): JSDocSeeTag;
3429+
updateJSDocSeeTag(node: JSDocSeeTag, tagName: Identifier | undefined, nameExpression: JSDocNameExpression, comment?: string): JSDocSeeTag;
34163430
createJSDocReturnTag(tagName: Identifier | undefined, typeExpression?: JSDocTypeExpression, comment?: string): JSDocReturnTag;
34173431
updateJSDocReturnTag(node: JSDocReturnTag, tagName: Identifier | undefined, typeExpression: JSDocTypeExpression | undefined, comment: string | undefined): JSDocReturnTag;
34183432
createJSDocThisTag(tagName: Identifier | undefined, typeExpression?: JSDocTypeExpression, comment?: string): JSDocThisTag;

tests/baselines/reference/api/typescript.d.ts

Lines changed: 55 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -403,44 +403,46 @@ declare namespace ts {
403403
UnparsedSource = 296,
404404
InputFiles = 297,
405405
JSDocTypeExpression = 298,
406-
JSDocAllType = 299,
407-
JSDocUnknownType = 300,
408-
JSDocNullableType = 301,
409-
JSDocNonNullableType = 302,
410-
JSDocOptionalType = 303,
411-
JSDocFunctionType = 304,
412-
JSDocVariadicType = 305,
413-
JSDocNamepathType = 306,
414-
JSDocComment = 307,
415-
JSDocTypeLiteral = 308,
416-
JSDocSignature = 309,
417-
JSDocTag = 310,
418-
JSDocAugmentsTag = 311,
419-
JSDocImplementsTag = 312,
420-
JSDocAuthorTag = 313,
421-
JSDocDeprecatedTag = 314,
422-
JSDocClassTag = 315,
423-
JSDocPublicTag = 316,
424-
JSDocPrivateTag = 317,
425-
JSDocProtectedTag = 318,
426-
JSDocReadonlyTag = 319,
427-
JSDocCallbackTag = 320,
428-
JSDocEnumTag = 321,
429-
JSDocParameterTag = 322,
430-
JSDocReturnTag = 323,
431-
JSDocThisTag = 324,
432-
JSDocTypeTag = 325,
433-
JSDocTemplateTag = 326,
434-
JSDocTypedefTag = 327,
435-
JSDocPropertyTag = 328,
436-
SyntaxList = 329,
437-
NotEmittedStatement = 330,
438-
PartiallyEmittedExpression = 331,
439-
CommaListExpression = 332,
440-
MergeDeclarationMarker = 333,
441-
EndOfDeclarationMarker = 334,
442-
SyntheticReferenceExpression = 335,
443-
Count = 336,
406+
JSDocNameExpression = 299,
407+
JSDocAllType = 300,
408+
JSDocUnknownType = 301,
409+
JSDocNullableType = 302,
410+
JSDocNonNullableType = 303,
411+
JSDocOptionalType = 304,
412+
JSDocFunctionType = 305,
413+
JSDocVariadicType = 306,
414+
JSDocNamepathType = 307,
415+
JSDocComment = 308,
416+
JSDocTypeLiteral = 309,
417+
JSDocSignature = 310,
418+
JSDocTag = 311,
419+
JSDocAugmentsTag = 312,
420+
JSDocImplementsTag = 313,
421+
JSDocAuthorTag = 314,
422+
JSDocDeprecatedTag = 315,
423+
JSDocClassTag = 316,
424+
JSDocPublicTag = 317,
425+
JSDocPrivateTag = 318,
426+
JSDocProtectedTag = 319,
427+
JSDocReadonlyTag = 320,
428+
JSDocCallbackTag = 321,
429+
JSDocEnumTag = 322,
430+
JSDocParameterTag = 323,
431+
JSDocReturnTag = 324,
432+
JSDocThisTag = 325,
433+
JSDocTypeTag = 326,
434+
JSDocTemplateTag = 327,
435+
JSDocTypedefTag = 328,
436+
JSDocSeeTag = 329,
437+
JSDocPropertyTag = 330,
438+
SyntaxList = 331,
439+
NotEmittedStatement = 332,
440+
PartiallyEmittedExpression = 333,
441+
CommaListExpression = 334,
442+
MergeDeclarationMarker = 335,
443+
EndOfDeclarationMarker = 336,
444+
SyntheticReferenceExpression = 337,
445+
Count = 338,
444446
FirstAssignment = 62,
445447
LastAssignment = 77,
446448
FirstCompoundAssignment = 63,
@@ -469,9 +471,9 @@ declare namespace ts {
469471
LastStatement = 245,
470472
FirstNode = 156,
471473
FirstJSDocNode = 298,
472-
LastJSDocNode = 328,
473-
FirstJSDocTagNode = 310,
474-
LastJSDocTagNode = 328,
474+
LastJSDocNode = 330,
475+
FirstJSDocTagNode = 311,
476+
LastJSDocTagNode = 330,
475477
}
476478
export type TriviaSyntaxKind = SyntaxKind.SingleLineCommentTrivia | SyntaxKind.MultiLineCommentTrivia | SyntaxKind.NewLineTrivia | SyntaxKind.WhitespaceTrivia | SyntaxKind.ShebangTrivia | SyntaxKind.ConflictMarkerTrivia;
477479
export type LiteralSyntaxKind = SyntaxKind.NumericLiteral | SyntaxKind.BigIntLiteral | SyntaxKind.StringLiteral | SyntaxKind.JsxText | SyntaxKind.JsxTextAllWhiteSpaces | SyntaxKind.RegularExpressionLiteral | SyntaxKind.NoSubstitutionTemplateLiteral;
@@ -1682,6 +1684,10 @@ declare namespace ts {
16821684
readonly kind: SyntaxKind.JSDocTypeExpression;
16831685
readonly type: TypeNode;
16841686
}
1687+
export interface JSDocNameExpression extends Node {
1688+
readonly kind: SyntaxKind.JSDocNameExpression;
1689+
readonly name: EntityName;
1690+
}
16851691
export interface JSDocType extends TypeNode {
16861692
_jsDocTypeBrand: any;
16871693
}
@@ -1780,6 +1786,10 @@ declare namespace ts {
17801786
readonly constraint: JSDocTypeExpression | undefined;
17811787
readonly typeParameters: NodeArray<TypeParameterDeclaration>;
17821788
}
1789+
export interface JSDocSeeTag extends JSDocTag {
1790+
readonly kind: SyntaxKind.JSDocSeeTag;
1791+
readonly name: JSDocNameExpression;
1792+
}
17831793
export interface JSDocReturnTag extends JSDocTag {
17841794
readonly kind: SyntaxKind.JSDocReturnTag;
17851795
readonly typeExpression?: JSDocTypeExpression;
@@ -3399,6 +3409,8 @@ declare namespace ts {
33993409
updateJSDocNamepathType(node: JSDocNamepathType, type: TypeNode): JSDocNamepathType;
34003410
createJSDocTypeExpression(type: TypeNode): JSDocTypeExpression;
34013411
updateJSDocTypeExpression(node: JSDocTypeExpression, type: TypeNode): JSDocTypeExpression;
3412+
createJSDocNameExpression(name: EntityName): JSDocNameExpression;
3413+
updateJSDocNameExpression(node: JSDocNameExpression, name: EntityName): JSDocNameExpression;
34023414
createJSDocTypeLiteral(jsDocPropertyTags?: readonly JSDocPropertyLikeTag[], isArrayType?: boolean): JSDocTypeLiteral;
34033415
updateJSDocTypeLiteral(node: JSDocTypeLiteral, jsDocPropertyTags: readonly JSDocPropertyLikeTag[] | undefined, isArrayType: boolean | undefined): JSDocTypeLiteral;
34043416
createJSDocSignature(typeParameters: readonly JSDocTemplateTag[] | undefined, parameters: readonly JSDocParameterTag[], type?: JSDocReturnTag): JSDocSignature;
@@ -3413,6 +3425,8 @@ declare namespace ts {
34133425
updateJSDocPropertyTag(node: JSDocPropertyTag, tagName: Identifier | undefined, name: EntityName, isBracketed: boolean, typeExpression: JSDocTypeExpression | undefined, isNameFirst: boolean, comment: string | undefined): JSDocPropertyTag;
34143426
createJSDocTypeTag(tagName: Identifier | undefined, typeExpression: JSDocTypeExpression, comment?: string): JSDocTypeTag;
34153427
updateJSDocTypeTag(node: JSDocTypeTag, tagName: Identifier | undefined, typeExpression: JSDocTypeExpression, comment: string | undefined): JSDocTypeTag;
3428+
createJSDocSeeTag(tagName: Identifier | undefined, nameExpression: JSDocNameExpression, comment?: string): JSDocSeeTag;
3429+
updateJSDocSeeTag(node: JSDocSeeTag, tagName: Identifier | undefined, nameExpression: JSDocNameExpression, comment?: string): JSDocSeeTag;
34163430
createJSDocReturnTag(tagName: Identifier | undefined, typeExpression?: JSDocTypeExpression, comment?: string): JSDocReturnTag;
34173431
updateJSDocReturnTag(node: JSDocReturnTag, tagName: Identifier | undefined, typeExpression: JSDocTypeExpression | undefined, comment: string | undefined): JSDocReturnTag;
34183432
createJSDocThisTag(tagName: Identifier | undefined, typeExpression?: JSDocTypeExpression, comment?: string): JSDocThisTag;

tests/cases/fourslash/codeFixInferFromUsageExistingJSDoc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ var o = {
7373
* 2
7474
* 3
7575
* @returns {number} First one
76-
* @see also
76+
* @see {also}
7777
* @return Second one
7878
* @extends {C<number>} nothing really
7979
* @class

tests/cases/fourslash/jsDocSee1.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
///<reference path="fourslash.ts" />
2+
3+
//// interface [|/*def1*/Foo|] {
4+
//// foo: string
5+
//// }
6+
7+
//// namespace NS {
8+
//// export interface [| /*def2*/Bar|] {
9+
//// baz: Foo
10+
//// }
11+
//// }
12+
13+
//// /** @see {/*use1*/[|Foo|]} foooo*/
14+
//// const a = ""
15+
16+
//// /** @see {NS./*use2*/[|Bar|]} ns.bar*/
17+
//// const b = ""
18+
19+
goTo.marker("use1");
20+
verify.goToDefinitionIs("def1");
21+
22+
goTo.marker("use2");
23+
verify.goToDefinitionIs("def2");

0 commit comments

Comments
 (0)