Skip to content

Commit 347ad5d

Browse files
committed
feat(49834): omit self-referenced enum declaration in JsDoc
1 parent 1622247 commit 347ad5d

File tree

5 files changed

+41
-0
lines changed

5 files changed

+41
-0
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,7 @@ m2: ${(this.mapper2 as unknown as DebugTypeMapper).__debugToString().split("\n")
677677
resolveName(name, location, meaning, excludeGlobals) {
678678
return resolveName(location, escapeLeadingUnderscores(name), meaning, /*nameNotFoundMessage*/ undefined, /*nameArg*/ undefined, /*isUse*/ false, excludeGlobals);
679679
},
680+
resolveEntityName,
680681
getJsxNamespace: n => unescapeLeadingUnderscores(getJsxNamespace(n)),
681682
getJsxFragmentFactory: n => {
682683
const jsxFragmentFactory = getJsxFragmentFactoryEntity(n);

src/compiler/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4582,6 +4582,7 @@ namespace ts {
45824582
*/
45834583
/* @internal */ getAllPossiblePropertiesOfTypes(type: readonly Type[]): Symbol[];
45844584
/* @internal */ resolveName(name: string, location: Node | undefined, meaning: SymbolFlags, excludeGlobals: boolean): Symbol | undefined;
4585+
/* @internal */ resolveEntityName(name: EntityNameOrEntityNameExpression, meaning: SymbolFlags, ignoreErrors?: boolean, dontResolveAlias?: boolean, location?: Node): Symbol | undefined;
45854586
/* @internal */ getJsxNamespace(location?: Node): string;
45864587
/* @internal */ getJsxFragmentFactory(location: Node): string | undefined;
45874588

src/services/goToDefinition.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,17 @@ namespace ts.GoToDefinition {
293293
}
294294

295295
function getSymbol(node: Node, checker: TypeChecker, stopAtAlias: boolean | undefined) {
296+
if (isEntityNameExpression(node) && isInJSDoc(node)) {
297+
const location = getJSDocHost(node);
298+
if (location && isEnumMember(location)) {
299+
const flags = SymbolFlags.Type | SymbolFlags.Namespace | SymbolFlags.Value;
300+
const symbol = checker.resolveEntityName(node, flags, /*ignoreErrors*/ true, /*dontResolveAlias*/ true, getSourceFileOfNode(location));
301+
if (symbol) {
302+
return { symbol, failedAliasResolution: false };
303+
}
304+
}
305+
}
306+
296307
const symbol = checker.getSymbolAtLocation(node);
297308
// If this is an alias, and the request came at the declaration location
298309
// get the aliased symbol instead. This allows for goto def on an import e.g.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @Filename: a.ts
4+
////enum E {
5+
//// /** {@link /*1*/[|Foo|]} */
6+
//// Foo
7+
////}
8+
////interface [|/*2*/Foo|] {
9+
//// foo: E.Foo;
10+
////}
11+
12+
goTo.marker("1");
13+
verify.goToDefinitionIs("2");
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @filename: a.ts
4+
////interface [|/*2*/Foo|] {
5+
//// foo: E.Foo;
6+
////}
7+
8+
// @Filename: b.ts
9+
////enum E {
10+
//// /** {@link /*1*/[|Foo|]} */
11+
//// Foo
12+
////}
13+
14+
goTo.marker("1");
15+
verify.goToDefinitionIs("2");

0 commit comments

Comments
 (0)