Skip to content

Commit 20b1482

Browse files
authored
fix(1880): No error message for JSDoc type parsing (#1881)
1 parent 49e5285 commit 20b1482

File tree

97 files changed

+777
-419
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+777
-419
lines changed

internal/compiler/program.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,6 +1056,12 @@ func (p *Program) getSemanticDiagnosticsForFileNotFilter(ctx context.Context, so
10561056
})
10571057
}
10581058

1059+
isJS := sourceFile.ScriptKind == core.ScriptKindJS || sourceFile.ScriptKind == core.ScriptKindJSX
1060+
isCheckJS := isJS && ast.IsCheckJSEnabledForFile(sourceFile, compilerOptions)
1061+
if isCheckJS {
1062+
diags = append(diags, sourceFile.JSDocDiagnostics()...)
1063+
}
1064+
10591065
filtered, directivesByLine := p.getDiagnosticsWithPrecedingDirectives(sourceFile, diags)
10601066
for _, directive := range directivesByLine {
10611067
// Above we changed all used directive kinds to @ts-ignore, so any @ts-expect-error directives that
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
a.js(1,12): error TS1110: Type expected.
2+
3+
4+
==== a.js (1 errors) ====
5+
/** @type {@import("a").Type} */
6+
~
7+
!!! error TS1110: Type expected.
8+
let x;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//// [tests/cases/compiler/invalidJsdocType.ts] ////
2+
3+
=== a.js ===
4+
/** @type {@import("a").Type} */
5+
let x;
6+
>x : Symbol(x, Decl(a.js, 1, 3))
7+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//// [tests/cases/compiler/invalidJsdocType.ts] ////
2+
3+
=== a.js ===
4+
/** @type {@import("a").Type} */
5+
let x;
6+
>x : any
7+

testdata/baselines/reference/submodule/compiler/jsEnumCrossFileExport.errors.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
enumDef.js(14,21): error TS1003: Identifier expected.
12
enumDef.js(16,18): error TS2339: Property 'Blah' does not exist on type '{ Action: { WindowDocked: number; WindowUndocked: number; ScriptsBreakpointSet: number; TimelineStarted: number; }; }'.
23
index.js(4,17): error TS2503: Cannot find namespace 'Host'.
34
index.js(8,21): error TS2304: Cannot find name 'Host'.
45
index.js(13,11): error TS2503: Cannot find namespace 'Host'.
56
index.js(18,11): error TS2503: Cannot find namespace 'Host'.
67

78

8-
==== enumDef.js (1 errors) ====
9+
==== enumDef.js (2 errors) ====
910
var Host = {};
1011
Host.UserMetrics = {};
1112
/** @enum {number} */
@@ -20,7 +21,10 @@ index.js(18,11): error TS2503: Cannot find namespace 'Host'.
2021
*/
2122
/**
2223
* @typedef {string}
24+
2325
*/
26+
27+
!!! error TS1003: Identifier expected.
2428
Host.UserMetrics.Blah = {
2529
~~~~
2630
!!! error TS2339: Property 'Blah' does not exist on type '{ Action: { WindowDocked: number; WindowUndocked: number; ScriptsBreakpointSet: number; TimelineStarted: number; }; }'.
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
/a.js(1,13): error TS1098: Type parameter list cannot be empty.
2+
/a.js(1,14): error TS1139: Type parameter declaration expected.
23

34

4-
==== /a.js (1 errors) ====
5+
==== /a.js (2 errors) ====
56
/** @param {<} x */
67
~~
78
!!! error TS1098: Type parameter list cannot be empty.
9+
~
10+
!!! error TS1139: Type parameter declaration expected.
811
function f(x) {}
912

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
example.js(3,11): error TS2552: Cannot find name 'function'. Did you mean 'Function'?
2+
example.js(3,19): error TS1005: '}' expected.
23

34

4-
==== example.js (1 errors) ====
5+
==== example.js (2 errors) ====
56
// @ts-check
67
/**
78
* @type {function(@foo)}
89
~~~~~~~~
910
!!! error TS2552: Cannot find name 'function'. Did you mean 'Function'?
1011
!!! related TS2728 lib.es5.d.ts:--:--: 'Function' is declared here.
12+
~
13+
!!! error TS1005: '}' expected.
1114
*/
1215
let x;

testdata/baselines/reference/submodule/compiler/uniqueSymbolJs.errors.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
a.js(5,18): error TS1268: An index signature parameter type must be 'string', 'number', 'symbol', or a template literal type.
22
a.js(5,23): error TS2749: 'foo' refers to a value, but is being used as a type here. Did you mean 'typeof foo'?
3+
a.js(5,28): error TS1005: ';' expected.
34

45

5-
==== a.js (2 errors) ====
6+
==== a.js (3 errors) ====
67
/** @type {unique symbol} */
78
const foo = Symbol();
89

@@ -12,4 +13,6 @@ a.js(5,23): error TS2749: 'foo' refers to a value, but is being used as a type h
1213
!!! error TS1268: An index signature parameter type must be 'string', 'number', 'symbol', or a template literal type.
1314
~~~
1415
!!! error TS2749: 'foo' refers to a value, but is being used as a type here. Did you mean 'typeof foo'?
16+
~~~~~~~
17+
!!! error TS1005: ';' expected.
1518

testdata/baselines/reference/submodule/conformance/asyncArrowFunction_allowJs.errors.txt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,41 @@
11
file.js(2,12): error TS2552: Cannot find name 'function'. Did you mean 'Function'?
2+
file.js(2,20): error TS1005: '}' expected.
23
file.js(6,12): error TS2552: Cannot find name 'function'. Did you mean 'Function'?
4+
file.js(6,20): error TS1005: '}' expected.
35
file.js(10,12): error TS2552: Cannot find name 'function'. Did you mean 'Function'?
6+
file.js(10,20): error TS1005: '}' expected.
47
file.js(16,12): error TS2552: Cannot find name 'function'. Did you mean 'Function'?
8+
file.js(16,20): error TS1005: '}' expected.
59
file.js(21,12): error TS2552: Cannot find name 'function'. Did you mean 'Function'?
10+
file.js(21,20): error TS1005: '}' expected.
611

712

8-
==== file.js (5 errors) ====
13+
==== file.js (10 errors) ====
914
// Error (good)
1015
/** @type {function(): string} */
1116
~~~~~~~~
1217
!!! error TS2552: Cannot find name 'function'. Did you mean 'Function'?
1318
!!! related TS2728 lib.es5.d.ts:--:--: 'Function' is declared here.
19+
~
20+
!!! error TS1005: '}' expected.
1421
const a = () => 0
1522

1623
// Error (good)
1724
/** @type {function(): string} */
1825
~~~~~~~~
1926
!!! error TS2552: Cannot find name 'function'. Did you mean 'Function'?
2027
!!! related TS2728 lib.es5.d.ts:--:--: 'Function' is declared here.
28+
~
29+
!!! error TS1005: '}' expected.
2130
const b = async () => 0
2231

2332
// No error (bad)
2433
/** @type {function(): string} */
2534
~~~~~~~~
2635
!!! error TS2552: Cannot find name 'function'. Did you mean 'Function'?
2736
!!! related TS2728 lib.es5.d.ts:--:--: 'Function' is declared here.
37+
~
38+
!!! error TS1005: '}' expected.
2839
const c = async () => {
2940
return 0
3041
}
@@ -34,6 +45,8 @@ file.js(21,12): error TS2552: Cannot find name 'function'. Did you mean 'Functio
3445
~~~~~~~~
3546
!!! error TS2552: Cannot find name 'function'. Did you mean 'Function'?
3647
!!! related TS2728 lib.es5.d.ts:--:--: 'Function' is declared here.
48+
~
49+
!!! error TS1005: '}' expected.
3750
const d = async () => {
3851
return ""
3952
}
@@ -42,6 +55,8 @@ file.js(21,12): error TS2552: Cannot find name 'function'. Did you mean 'Functio
4255
~~~~~~~~
4356
!!! error TS2552: Cannot find name 'function'. Did you mean 'Function'?
4457
!!! related TS2728 lib.es5.d.ts:--:--: 'Function' is declared here.
58+
~
59+
!!! error TS1005: '}' expected.
4560
const f = (p) => {}
4661

4762
// Error (good)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/a.js(7,15): error TS1005: '{' expected.
2+
/a.js(10,27): error TS1005: '{' expected.
3+
4+
5+
==== /a.js (2 errors) ====
6+
/**
7+
* @typedef {Object} T1
8+
* @property {number} a
9+
*/
10+
11+
/**
12+
* @satisfies T1
13+
~~
14+
!!! error TS1005: '{' expected.
15+
*/
16+
const t1 = { a: 1 };
17+
const t2 = /** @satisfies T1 */ ({ a: 1 });
18+
~~
19+
!!! error TS1005: '{' expected.
20+

0 commit comments

Comments
 (0)