Skip to content

Commit a013759

Browse files
authored
Merge pull request #10399 from Microsoft/jsdoc-never-undefined-null-types
JSDoc supports null, undefined and never types
2 parents ec1f6b1 + 2c814f4 commit a013759

File tree

9 files changed

+100
-20
lines changed

9 files changed

+100
-20
lines changed

src/compiler/checker.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5552,6 +5552,12 @@ namespace ts {
55525552
return nullType;
55535553
case SyntaxKind.NeverKeyword:
55545554
return neverType;
5555+
case SyntaxKind.JSDocNullKeyword:
5556+
return nullType;
5557+
case SyntaxKind.JSDocUndefinedKeyword:
5558+
return undefinedType;
5559+
case SyntaxKind.JSDocNeverKeyword:
5560+
return neverType;
55555561
case SyntaxKind.ThisType:
55565562
case SyntaxKind.ThisKeyword:
55575563
return getTypeFromThisTypeNode(node);

src/compiler/parser.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5893,6 +5893,9 @@ namespace ts {
58935893
case SyntaxKind.BooleanKeyword:
58945894
case SyntaxKind.SymbolKeyword:
58955895
case SyntaxKind.VoidKeyword:
5896+
case SyntaxKind.NullKeyword:
5897+
case SyntaxKind.UndefinedKeyword:
5898+
case SyntaxKind.NeverKeyword:
58965899
return parseTokenNode<JSDocType>();
58975900
case SyntaxKind.StringLiteral:
58985901
case SyntaxKind.NumericLiteral:

src/compiler/types.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,9 @@ namespace ts {
351351
JSDocPropertyTag,
352352
JSDocTypeLiteral,
353353
JSDocLiteralType,
354+
JSDocNullKeyword,
355+
JSDocUndefinedKeyword,
356+
JSDocNeverKeyword,
354357

355358
// Synthesized list
356359
SyntaxList,
@@ -383,7 +386,7 @@ namespace ts {
383386
FirstJSDocNode = JSDocTypeExpression,
384387
LastJSDocNode = JSDocLiteralType,
385388
FirstJSDocTagNode = JSDocComment,
386-
LastJSDocTagNode = JSDocLiteralType
389+
LastJSDocTagNode = JSDocNeverKeyword
387390
}
388391

389392
export const enum NodeFlags {

src/harness/unittests/jsDocParsing.ts

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -767,33 +767,19 @@ namespace ts {
767767
parsesCorrectly(
768768
"{null}",
769769
`{
770-
"kind": "JSDocTypeReference",
770+
"kind": "NullKeyword",
771771
"pos": 1,
772-
"end": 5,
773-
"name": {
774-
"kind": "Identifier",
775-
"pos": 1,
776-
"end": 5,
777-
"originalKeywordKind": "NullKeyword",
778-
"text": "null"
779-
}
772+
"end": 5
780773
}`);
781774
});
782775

783776
it("keyword3", () => {
784777
parsesCorrectly(
785778
"{undefined}",
786779
`{
787-
"kind": "JSDocTypeReference",
780+
"kind": "UndefinedKeyword",
788781
"pos": 1,
789-
"end": 10,
790-
"name": {
791-
"kind": "Identifier",
792-
"pos": 1,
793-
"end": 10,
794-
"originalKeywordKind": "UndefinedKeyword",
795-
"text": "undefined"
796-
}
782+
"end": 10
797783
}`);
798784
});
799785

@@ -2379,4 +2365,4 @@ namespace ts {
23792365
});
23802366
});
23812367
});
2382-
}
2368+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//// [in.js]
2+
/**
3+
* @param {never} p1
4+
* @param {undefined} p2
5+
* @param {null} p3
6+
* @returns {void} nothing
7+
*/
8+
function f(p1, p2, p3) {
9+
}
10+
11+
12+
//// [out.js]
13+
/**
14+
* @param {never} p1
15+
* @param {undefined} p2
16+
* @param {null} p3
17+
* @returns {void} nothing
18+
*/
19+
function f(p1, p2, p3) {
20+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
=== tests/cases/conformance/jsdoc/in.js ===
2+
/**
3+
* @param {never} p1
4+
* @param {undefined} p2
5+
* @param {null} p3
6+
* @returns {void} nothing
7+
*/
8+
function f(p1, p2, p3) {
9+
>f : Symbol(f, Decl(in.js, 0, 0))
10+
>p1 : Symbol(p1, Decl(in.js, 6, 11))
11+
>p2 : Symbol(p2, Decl(in.js, 6, 14))
12+
>p3 : Symbol(p3, Decl(in.js, 6, 18))
13+
}
14+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
=== tests/cases/conformance/jsdoc/in.js ===
2+
/**
3+
* @param {never} p1
4+
* @param {undefined} p2
5+
* @param {null} p3
6+
* @returns {void} nothing
7+
*/
8+
function f(p1, p2, p3) {
9+
>f : (p1: never, p2: undefined, p3: null) => void
10+
>p1 : never
11+
>p2 : undefined
12+
>p3 : null
13+
}
14+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// @allowJs: true
2+
// @filename: in.js
3+
// @out: out.js
4+
/**
5+
* @param {never} p1
6+
* @param {undefined} p2
7+
* @param {null} p3
8+
* @returns {void} nothing
9+
*/
10+
function f(p1, p2, p3) {
11+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
///<reference path="fourslash.ts" />
2+
// @allowNonTsExtensions: true
3+
// @Filename: Foo.js
4+
////
5+
//// * @param {never | {x: string}} p1
6+
//// * @param {undefined | {y: number}} p2
7+
//// * @param {null | {z: boolean}} p3
8+
//// * @returns {void} nothing
9+
//// */
10+
////function f(p1, p2, p3) {
11+
//// p1./*1*/
12+
//// p2./*2*/
13+
//// p3./*3*/
14+
////}
15+
16+
goTo.marker('1');
17+
verify.memberListContains("x");
18+
19+
goTo.marker('2');
20+
verify.memberListContains("y");
21+
22+
goTo.marker('3');
23+
verify.memberListContains("z");

0 commit comments

Comments
 (0)