Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 928da67

Browse filesBrowse files
authored
Merge pull request microsoft#16156 from Microsoft/report-jsdoc-syntax-errors
Report JSDoc syntax errors
2 parents 2fa59d5 + 41e1345 commit 928da67
Copy full SHA for 928da67

5 files changed

+68-5Lines changed: 68 additions & 5 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/compiler/parser.ts‎

Copy file name to clipboardExpand all lines: src/compiler/parser.ts
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6322,6 +6322,12 @@ namespace ts {
63226322
comment.parent = parent;
63236323
}
63246324

6325+
if (isInJavaScriptFile(parent)) {
6326+
if (!sourceFile.jsDocDiagnostics) {
6327+
sourceFile.jsDocDiagnostics = [];
6328+
}
6329+
sourceFile.jsDocDiagnostics.push(...parseDiagnostics);
6330+
}
63256331
currentToken = saveToken;
63266332
parseDiagnostics.length = saveParseDiagnosticsLength;
63276333
parseErrorBeforeNextFinishedNode = saveParseErrorBeforeNextFinishedNode;
Collapse file

‎src/compiler/program.ts‎

Copy file name to clipboardExpand all lines: src/compiler/program.ts
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,9 @@ namespace ts {
10211021
if (isSourceFileJavaScript(sourceFile)) {
10221022
if (!sourceFile.additionalSyntacticDiagnostics) {
10231023
sourceFile.additionalSyntacticDiagnostics = getJavaScriptSyntacticDiagnosticsForFile(sourceFile);
1024+
if (isCheckJsEnabledForFile(sourceFile, options)) {
1025+
sourceFile.additionalSyntacticDiagnostics = concatenate(sourceFile.additionalSyntacticDiagnostics, sourceFile.jsDocDiagnostics);
1026+
}
10241027
}
10251028
return concatenate(sourceFile.additionalSyntacticDiagnostics, sourceFile.parseDiagnostics);
10261029
}
Collapse file

‎src/compiler/types.ts‎

Copy file name to clipboardExpand all lines: src/compiler/types.ts
+8-5Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2316,16 +2316,19 @@ namespace ts {
23162316
/* @internal */ identifierCount: number;
23172317
/* @internal */ symbolCount: number;
23182318

2319-
// File level diagnostics reported by the parser (includes diagnostics about /// references
2319+
// File-level diagnostics reported by the parser (includes diagnostics about /// references
23202320
// as well as code diagnostics).
23212321
/* @internal */ parseDiagnostics: Diagnostic[];
23222322

2323-
// Stores additional file level diagnostics reported by the program
2324-
/* @internal */ additionalSyntacticDiagnostics?: Diagnostic[];
2325-
2326-
// File level diagnostics reported by the binder.
2323+
// File-level diagnostics reported by the binder.
23272324
/* @internal */ bindDiagnostics: Diagnostic[];
23282325

2326+
// File-level JSDoc diagnostics reported by the JSDoc parser
2327+
/* @internal */ jsDocDiagnostics?: Diagnostic[];
2328+
2329+
// Stores additional file-level diagnostics reported by the program
2330+
/* @internal */ additionalSyntacticDiagnostics?: Diagnostic[];
2331+
23292332
// Stores a line map for the file.
23302333
// This field should never be used directly to obtain line map, use getLineMap function instead.
23312334
/* @internal */ lineMap: number[];
Collapse file
+31Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
tests/cases/conformance/jsdoc/foo.js(2,15): error TS1005: '}' expected.
2+
tests/cases/conformance/jsdoc/foo.js(3,19): error TS1005: '}' expected.
3+
tests/cases/conformance/jsdoc/foo.js(4,18): error TS1003: Identifier expected.
4+
tests/cases/conformance/jsdoc/foo.js(4,19): error TS1005: '}' expected.
5+
6+
7+
==== tests/cases/conformance/jsdoc/foo.js (4 errors) ====
8+
/**
9+
* @param {(x)=>void} x
10+
~~
11+
!!! error TS1005: '}' expected.
12+
* @param {typeof String} y
13+
~~~~~~
14+
!!! error TS1005: '}' expected.
15+
* @param {string & number} z
16+
17+
!!! error TS1003: Identifier expected.
18+
~
19+
!!! error TS1005: '}' expected.
20+
**/
21+
function foo(x, y, z) { }
22+
23+
==== tests/cases/conformance/jsdoc/skipped.js (0 errors) ====
24+
// @ts-nocheck
25+
/**
26+
* @param {(x)=>void} x
27+
* @param {typeof String} y
28+
* @param {string & number} z
29+
**/
30+
function bar(x, y, z) { }
31+
Collapse file
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// @checkJs: true
2+
// @allowJs: true
3+
// @noEmit: true
4+
5+
// @Filename: foo.js
6+
/**
7+
* @param {(x)=>void} x
8+
* @param {typeof String} y
9+
* @param {string & number} z
10+
**/
11+
function foo(x, y, z) { }
12+
13+
// @Filename: skipped.js
14+
// @ts-nocheck
15+
/**
16+
* @param {(x)=>void} x
17+
* @param {typeof String} y
18+
* @param {string & number} z
19+
**/
20+
function bar(x, y, z) { }

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.