Skip to content

Commit aa834d7

Browse files
committed
JSDoc supports null, undefined and never types
1 parent 73a6488 commit aa834d7

File tree

7 files changed

+73
-2
lines changed

7 files changed

+73
-2
lines changed

src/compiler/checker.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5547,6 +5547,12 @@ namespace ts {
55475547
return nullType;
55485548
case SyntaxKind.NeverKeyword:
55495549
return neverType;
5550+
case SyntaxKind.JSDocNullKeyword:
5551+
return nullType;
5552+
case SyntaxKind.JSDocUndefinedKeyword:
5553+
return undefinedType;
5554+
case SyntaxKind.JSDocNeverKeyword:
5555+
return neverType;
55505556
case SyntaxKind.ThisType:
55515557
case SyntaxKind.ThisKeyword:
55525558
return getTypeFromThisTypeNode(node);

src/compiler/parser.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1241,7 +1241,7 @@ namespace ts {
12411241
// not in error recovery. If we're in error recovery, we don't want an errant
12421242
// semicolon to be treated as a class member (since they're almost always used
12431243
// for statements.
1244-
return lookAhead(isClassMemberStart) || (token() === SyntaxKind.SemicolonToken && !inErrorRecovery);
1244+
return lookAhead(isClassMemberStart) || (token() === SyntaxKind.SemicolonToken && !inErrorRecovery);
12451245
case ParsingContext.EnumMembers:
12461246
// Include open bracket computed properties. This technically also lets in indexers,
12471247
// which would be a candidate for improved error reporting.
@@ -5890,6 +5890,9 @@ namespace ts {
58905890
case SyntaxKind.BooleanKeyword:
58915891
case SyntaxKind.SymbolKeyword:
58925892
case SyntaxKind.VoidKeyword:
5893+
case SyntaxKind.NullKeyword:
5894+
case SyntaxKind.UndefinedKeyword:
5895+
case SyntaxKind.NeverKeyword:
58935896
return parseTokenNode<JSDocType>();
58945897
case SyntaxKind.StringLiteral:
58955898
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 {
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+
}

0 commit comments

Comments
 (0)