Skip to content

Commit 708e77d

Browse files
committed
Fix TS link resolution in first comment of file
Resolves #2994
1 parent 0489e32 commit 708e77d

File tree

5 files changed

+26
-21
lines changed

5 files changed

+26
-21
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ title: Changelog
44

55
## Unreleased
66

7+
### Bug Fixes
8+
9+
- Fixed link resolution not working correctly in first comment on the file in some cases, #2994.
10+
711
## v0.28.10 (2025-08-10)
812

913
### Bug Fixes

src/lib/converter/comments/discovery.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -357,15 +357,11 @@ function findJsDocForComment(
357357
if (ranges[0].kind === ts.SyntaxKind.MultiLineCommentTrivia) {
358358
const jsDocs = ts
359359
.getJSDocCommentsAndTags(node)
360-
.map((doc) => ts.findAncestor(doc, ts.isJSDoc)) as ts.JSDoc[];
360+
.map((doc) => ts.findAncestor(doc, ts.isJSDoc)!);
361361

362362
if (ts.isSourceFile(node)) {
363363
if (node.statements.length) {
364-
jsDocs.push(
365-
...(ts
366-
.getJSDocCommentsAndTags(node.statements[0])
367-
.map((doc) => ts.findAncestor(doc, ts.isJSDoc)) as ts.JSDoc[]),
368-
);
364+
jsDocs.push(...node.statements[0].getChildren().filter(ts.isJSDoc));
369365
}
370366
}
371367

src/lib/types/ts-internal/index.d.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,8 @@ declare module "typescript" {
2323
// https://github.com/microsoft/TypeScript/blob/v5.0.2/src/compiler/utilities.ts#L7432
2424
export function getCheckFlags(symbol: ts.Symbol): CheckFlags;
2525

26-
// https://github.com/microsoft/TypeScript/blob/v5.0.2/src/compiler/utilities.ts#L4171
27-
export function getJSDocCommentsAndTags(
28-
hostNode: Node,
29-
noCache?: boolean,
30-
): readonly (JSDoc | JSDocTag)[];
31-
32-
export function getInterfaceBaseTypeNodes(
33-
node: InterfaceDeclaration,
34-
): NodeArray<ExpressionWithTypeArguments> | undefined;
35-
3626
export function getAllSuperTypeNodes(node: ts.Node): readonly ts.TypeNode[];
3727

38-
export interface Signature {
39-
thisParameter?: ts.Symbol;
40-
}
41-
4228
// https://github.com/microsoft/TypeScript/blob/e213b2af3430bdc9cf5fbc76a8634d832e7aaaaa/src/compiler/types.ts#L5298-L5299
4329
export interface UnionType {
4430
/* @internal */
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* {@link x} <-- should be resolved with TS resolution
3+
* @packageDocumentation
4+
*/
5+
6+
/** Required comment */
7+
import { x } from "gh2994";
8+
9+
export var y: 2;
10+
11+
declare module "gh2994" {
12+
var x: 1;
13+
}

src/test/issues.c2.test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import type { InlineTagDisplayPart } from "../lib/models/Comment.js";
1717
import { getConverter2App, getConverter2Project } from "./programs.js";
1818
import { TestLogger } from "./TestLogger.js";
1919
import { equalKind, getComment, getLinks, getSigComment, query, querySig, reflToTree } from "./utils.js";
20-
import { DefaultTheme, KindRouter, PageEvent } from "../index.js";
20+
import { DefaultTheme, KindRouter, PageEvent, ReflectionSymbolId } from "../index.js";
2121

2222
const app = getConverter2App();
2323

@@ -2144,4 +2144,10 @@ describe("Issue Tests", () => {
21442144
equal(x.inheritedFrom?.reflection?.getFullName(), undefined);
21452145
equal(x.inheritedFrom?.name, "Tricky.x");
21462146
});
2147+
2148+
it("#2994 uses TS link resolution in first comment of file", () => {
2149+
const project = convert();
2150+
const link = project.comment?.summary.find(part => part.kind === "inline-tag");
2151+
ok(link?.target instanceof ReflectionSymbolId);
2152+
});
21472153
});

0 commit comments

Comments
 (0)