Skip to content

Commit 59d3a38

Browse files
authored
fix jsdoc errors in .ts in tsserver (#54185)
1 parent 7c03f7b commit 59d3a38

14 files changed

+457
-2
lines changed

src/compiler/checker.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3407,6 +3407,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
34073407
if (nameNotFoundMessage) {
34083408
addLazyDiagnostic(() => {
34093409
if (!errorLocation ||
3410+
errorLocation.parent.kind !== SyntaxKind.JSDocLink &&
34103411
!checkAndReportErrorForMissingPrefix(errorLocation, name, nameArg!) && // TODO: GH#18217
34113412
!checkAndReportErrorForInvalidInitializer() &&
34123413
!checkAndReportErrorForExtendingInterface(errorLocation) &&
@@ -45526,11 +45527,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4552645527
const symbol = getIntrinsicTagSymbol(name.parent as JsxOpeningLikeElement);
4552745528
return symbol === unknownSymbol ? undefined : symbol;
4552845529
}
45529-
const result = resolveEntityName(name, meaning, /*ignoreErrors*/ false, /*dontResolveAlias*/ true, getHostSignatureFromJSDoc(name));
45530+
const result = resolveEntityName(name, meaning, /*ignoreErrors*/ true, /*dontResolveAlias*/ true, getHostSignatureFromJSDoc(name));
4553045531
if (!result && isJSDoc) {
4553145532
const container = findAncestor(name, or(isClassLike, isInterfaceDeclaration));
4553245533
if (container) {
45533-
return resolveJSDocMemberName(name, /*ignoreErrors*/ false, getSymbolOfDeclaration(container));
45534+
return resolveJSDocMemberName(name, /*ignoreErrors*/ true, getSymbolOfDeclaration(container));
4553445535
}
4553545536
}
4553645537
if (result && isJSDoc) {

src/testRunner/tests.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import "./unittests/services/extract/functions";
5454
import "./unittests/services/extract/symbolWalker";
5555
import "./unittests/services/extract/ranges";
5656
import "./unittests/services/findAllReferences";
57+
import "./unittests/services/goToDefinition";
5758
import "./unittests/services/hostNewLineSupport";
5859
import "./unittests/services/languageService";
5960
import "./unittests/services/organizeImports";
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
import { protocol } from "../../_namespaces/ts.server";
2+
import { baselineTsserverLogs, createLoggerWithInMemoryLogs, createSession } from "../helpers/tsserver";
3+
import { createServerHost, File } from "../helpers/virtualFileSystemWithWatch";
4+
5+
describe("unittests:: services:: goToDefinition", () => {
6+
it("does not issue errors on jsdoc in TS", () => {
7+
const files: File[] = [
8+
{
9+
path: "/packages/babel-loader/tsconfig.json",
10+
content:
11+
`
12+
{
13+
"compilerOptions": {
14+
"target": "ES2018",
15+
"module": "commonjs",
16+
"strict": true,
17+
"esModuleInterop": true,
18+
"rootDir": "src",
19+
"outDir": "dist"
20+
},
21+
"include": ["src"],
22+
}
23+
`
24+
},
25+
{
26+
path: "/packages/babel-loader/src/index.ts",
27+
content:
28+
`
29+
declare class Stuff {
30+
/** For more thorough tests, use {@link checkFooIs} */
31+
checkFooLengthIs(len: number): void;
32+
33+
checkFooIs(value: object): void;
34+
}
35+
`
36+
},
37+
];
38+
const host = createServerHost(files);
39+
const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) });
40+
// Open files in the two configured projects
41+
session.executeCommandSeq<protocol.UpdateOpenRequest>({
42+
command: protocol.CommandTypes.UpdateOpen,
43+
arguments: {
44+
openFiles: [
45+
{
46+
file: files[1].path, // babel-loader/src/index.ts
47+
fileContent: files[1].content,
48+
}
49+
]
50+
}
51+
});
52+
session.executeCommandSeq<protocol.DefinitionRequest>({
53+
command: protocol.CommandTypes.Definition,
54+
arguments: {
55+
line: 3,
56+
offset: 45,
57+
file: "/packages/babel-loader/src/index.ts",
58+
},
59+
});
60+
// Now change `babel-loader` project to no longer import `core` project
61+
session.executeCommandSeq<protocol.SemanticDiagnosticsSyncRequest>({
62+
command: protocol.CommandTypes.SemanticDiagnosticsSync,
63+
arguments: {
64+
file: "/packages/babel-loader/src/index.ts",
65+
}
66+
});
67+
baselineTsserverLogs("goToDefinition", "does not issue errors on jsdoc in TS", session);
68+
69+
});
70+
it("does not issue errors on jsdoc in TS", () => {
71+
const files: File[] = [
72+
{
73+
path: "/packages/babel-loader/tsconfig.json",
74+
content:
75+
`
76+
{
77+
"compilerOptions": {
78+
"target": "ES2018",
79+
"module": "commonjs",
80+
"strict": true,
81+
"esModuleInterop": true,
82+
"rootDir": "src",
83+
"outDir": "dist"
84+
},
85+
"include": ["src"],
86+
}
87+
`
88+
},
89+
{
90+
path: "/packages/babel-loader/src/index.ts",
91+
content:
92+
`
93+
declare class Stuff {
94+
/**
95+
* Register a function to be run on mod initialization...
96+
*
97+
* {@link https://lua-api.factorio.com/latest/LuaBootstrap.html#LuaBootstrap.on_init View documentation}
98+
* @param f The handler for this event. Passing nil will unregister it.
99+
* @remarks For more context, refer to the {@link https://lua-api.factorio.com/latest/Data-Lifecycle.html Data Lifecycle} page.
100+
* @example Initialize a players table in global for later use.
101+
*
102+
*/
103+
on_init(f: (() => void) | undefined): void
104+
}
105+
`
106+
},
107+
];
108+
const host = createServerHost(files);
109+
const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) });
110+
// Open files in the two configured projects
111+
session.executeCommandSeq<protocol.UpdateOpenRequest>({
112+
command: protocol.CommandTypes.UpdateOpen,
113+
arguments: {
114+
openFiles: [
115+
{
116+
file: files[1].path, // babel-loader/src/index.ts
117+
fileContent: files[1].content,
118+
}
119+
]
120+
}
121+
});
122+
session.executeCommandSeq<protocol.DefinitionRequest>({
123+
command: protocol.CommandTypes.Definition,
124+
arguments: {
125+
line: 6,
126+
offset: 13,
127+
file: "/packages/babel-loader/src/index.ts",
128+
},
129+
});
130+
// Now change `babel-loader` project to no longer import `core` project
131+
session.executeCommandSeq<protocol.SemanticDiagnosticsSyncRequest>({
132+
command: protocol.CommandTypes.SemanticDiagnosticsSync,
133+
arguments: {
134+
file: "/packages/babel-loader/src/index.ts",
135+
}
136+
});
137+
baselineTsserverLogs("goToDefinition", "does not issue errors on jsdoc in TS2", session);
138+
139+
});
140+
});

tests/baselines/reference/classMemberInitializerScoping.symbols

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class CCC {
77

88
y: number = aaa;
99
>y : Symbol(CCC.y, Decl(classMemberInitializerScoping.ts, 1, 11))
10+
>aaa : Symbol(aaa, Decl(classMemberInitializerScoping.ts, 0, 3))
1011

1112
static staticY: number = aaa; // This shouldnt be error
1213
>staticY : Symbol(CCC.staticY, Decl(classMemberInitializerScoping.ts, 2, 20))

tests/baselines/reference/classMemberInitializerScoping2(target=es2017,usedefineforclassfields=false).symbols

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class C {
77

88
p = x
99
>p : Symbol(C.p, Decl(classMemberInitializerScoping2.ts, 1, 9))
10+
>x : Symbol(x, Decl(classMemberInitializerScoping2.ts, 0, 5))
1011

1112
constructor(x: string) { }
1213
>x : Symbol(x, Decl(classMemberInitializerScoping2.ts, 3, 16))

tests/baselines/reference/classMemberInitializerScoping2(target=es2017,usedefineforclassfields=true).symbols

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class C {
77

88
p = x
99
>p : Symbol(C.p, Decl(classMemberInitializerScoping2.ts, 1, 9))
10+
>x : Symbol(x, Decl(classMemberInitializerScoping2.ts, 0, 5))
1011

1112
constructor(x: string) { }
1213
>x : Symbol(x, Decl(classMemberInitializerScoping2.ts, 3, 16))

tests/baselines/reference/classMemberInitializerScoping2(target=esnext,usedefineforclassfields=false).symbols

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class C {
77

88
p = x
99
>p : Symbol(C.p, Decl(classMemberInitializerScoping2.ts, 1, 9))
10+
>x : Symbol(x, Decl(classMemberInitializerScoping2.ts, 0, 5))
1011

1112
constructor(x: string) { }
1213
>x : Symbol(x, Decl(classMemberInitializerScoping2.ts, 3, 16))

tests/baselines/reference/classMemberInitializerWithLamdaScoping.symbols

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class Test1 {
6666
>console.log : Symbol(log, Decl(classMemberInitializerWithLamdaScoping.ts, 0, 22))
6767
>console : Symbol(console, Decl(classMemberInitializerWithLamdaScoping.ts, 0, 11))
6868
>log : Symbol(log, Decl(classMemberInitializerWithLamdaScoping.ts, 0, 22))
69+
>field1 : Symbol(field1, Decl(classMemberInitializerWithLamdaScoping.ts, 17, 3))
6970

7071
// but since this code would be generated inside constructor, in generated js
7172
// it would resolve to private field1 and thats not what user intended here.

tests/baselines/reference/classMemberInitializerWithLamdaScoping2.symbols

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class Test1 {
2424
>console.log : Symbol(log, Decl(classMemberInitializerWithLamdaScoping2_1.ts, 0, 22))
2525
>console : Symbol(console, Decl(classMemberInitializerWithLamdaScoping2_1.ts, 0, 11))
2626
>log : Symbol(log, Decl(classMemberInitializerWithLamdaScoping2_1.ts, 0, 22))
27+
>field1 : Symbol(field1, Decl(classMemberInitializerWithLamdaScoping2_0.ts, 0, 3))
2728

2829
// but since this code would be generated inside constructor, in generated js
2930
// it would resolve to private field1 and thats not what user intended here.

tests/baselines/reference/classMemberInitializerWithLamdaScoping3.symbols

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export class Test1 {
2424
>console.log : Symbol(log, Decl(classMemberInitializerWithLamdaScoping3_1.ts, 0, 22))
2525
>console : Symbol(console, Decl(classMemberInitializerWithLamdaScoping3_1.ts, 0, 11))
2626
>log : Symbol(log, Decl(classMemberInitializerWithLamdaScoping3_1.ts, 0, 22))
27+
>field1 : Symbol(field1, Decl(classMemberInitializerWithLamdaScoping3_0.ts, 0, 3))
2728

2829
// but since this code would be generated inside constructor, in generated js
2930
// it would resolve to private field1 and thats not what user intended here.

tests/baselines/reference/constructorParameterShadowsOuterScopes.symbols

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class C {
1212

1313
b = x; // error, evaluated in scope of constructor, cannot reference x
1414
>b : Symbol(C.b, Decl(constructorParameterShadowsOuterScopes.ts, 6, 9))
15+
>x : Symbol(x, Decl(constructorParameterShadowsOuterScopes.ts, 5, 3))
1516

1617
constructor(x: string) {
1718
>x : Symbol(x, Decl(constructorParameterShadowsOuterScopes.ts, 8, 16))
@@ -29,6 +30,7 @@ class D {
2930

3031
b = y; // error, evaluated in scope of constructor, cannot reference y
3132
>b : Symbol(D.b, Decl(constructorParameterShadowsOuterScopes.ts, 14, 9))
33+
>y : Symbol(y, Decl(constructorParameterShadowsOuterScopes.ts, 13, 3))
3234

3335
constructor(x: string) {
3436
>x : Symbol(x, Decl(constructorParameterShadowsOuterScopes.ts, 16, 16))

tests/baselines/reference/constructorParametersThatShadowExternalNamesInVariableDeclarations.symbols

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class A {
77

88
private a = x;
99
>a : Symbol(A.a, Decl(constructorParametersThatShadowExternalNamesInVariableDeclarations.ts, 1, 9))
10+
>x : Symbol(x, Decl(constructorParametersThatShadowExternalNamesInVariableDeclarations.ts, 0, 3))
1011

1112
constructor(x: number) {
1213
>x : Symbol(x, Decl(constructorParametersThatShadowExternalNamesInVariableDeclarations.ts, 3, 16))
@@ -18,6 +19,7 @@ class B {
1819

1920
private a = x;
2021
>a : Symbol(B.a, Decl(constructorParametersThatShadowExternalNamesInVariableDeclarations.ts, 7, 9))
22+
>x : Symbol(x, Decl(constructorParametersThatShadowExternalNamesInVariableDeclarations.ts, 0, 3))
2123

2224
constructor() {
2325
var x = "";

0 commit comments

Comments
 (0)