Skip to content

JSDoc supports null, undefined and never types #10399

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5547,6 +5547,12 @@ namespace ts {
return nullType;
case SyntaxKind.NeverKeyword:
return neverType;
case SyntaxKind.JSDocNullKeyword:
return nullType;
case SyntaxKind.JSDocUndefinedKeyword:
return undefinedType;
case SyntaxKind.JSDocNeverKeyword:
return neverType;
case SyntaxKind.ThisType:
case SyntaxKind.ThisKeyword:
return getTypeFromThisTypeNode(node);
Expand Down
3 changes: 3 additions & 0 deletions src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5890,6 +5890,9 @@ namespace ts {
case SyntaxKind.BooleanKeyword:
case SyntaxKind.SymbolKeyword:
case SyntaxKind.VoidKeyword:
case SyntaxKind.NullKeyword:
case SyntaxKind.UndefinedKeyword:
case SyntaxKind.NeverKeyword:
return parseTokenNode<JSDocType>();
case SyntaxKind.StringLiteral:
case SyntaxKind.NumericLiteral:
Expand Down
5 changes: 4 additions & 1 deletion src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,9 @@ namespace ts {
JSDocPropertyTag,
JSDocTypeLiteral,
JSDocLiteralType,
JSDocNullKeyword,
JSDocUndefinedKeyword,
JSDocNeverKeyword,

// Synthesized list
SyntaxList,
Expand Down Expand Up @@ -383,7 +386,7 @@ namespace ts {
FirstJSDocNode = JSDocTypeExpression,
LastJSDocNode = JSDocLiteralType,
FirstJSDocTagNode = JSDocComment,
LastJSDocTagNode = JSDocLiteralType
LastJSDocTagNode = JSDocNeverKeyword
}

export const enum NodeFlags {
Expand Down
24 changes: 5 additions & 19 deletions src/harness/unittests/jsDocParsing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -767,33 +767,19 @@ namespace ts {
parsesCorrectly(
"{null}",
`{
"kind": "JSDocTypeReference",
"kind": "NullKeyword",
"pos": 1,
"end": 5,
"name": {
"kind": "Identifier",
"pos": 1,
"end": 5,
"originalKeywordKind": "NullKeyword",
"text": "null"
}
"end": 5
}`);
});

it("keyword3", () => {
parsesCorrectly(
"{undefined}",
`{
"kind": "JSDocTypeReference",
"kind": "UndefinedKeyword",
"pos": 1,
"end": 10,
"name": {
"kind": "Identifier",
"pos": 1,
"end": 10,
"originalKeywordKind": "UndefinedKeyword",
"text": "undefined"
}
"end": 10
}`);
});

Expand Down Expand Up @@ -2379,4 +2365,4 @@ namespace ts {
});
});
});
}
}
20 changes: 20 additions & 0 deletions tests/baselines/reference/jsdocNeverUndefinedNull.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//// [in.js]
/**
* @param {never} p1
* @param {undefined} p2
* @param {null} p3
* @returns {void} nothing
*/
function f(p1, p2, p3) {
}


//// [out.js]
/**
* @param {never} p1
* @param {undefined} p2
* @param {null} p3
* @returns {void} nothing
*/
function f(p1, p2, p3) {
}
14 changes: 14 additions & 0 deletions tests/baselines/reference/jsdocNeverUndefinedNull.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
=== tests/cases/conformance/jsdoc/in.js ===
/**
* @param {never} p1
* @param {undefined} p2
* @param {null} p3
* @returns {void} nothing
*/
function f(p1, p2, p3) {
>f : Symbol(f, Decl(in.js, 0, 0))
>p1 : Symbol(p1, Decl(in.js, 6, 11))
>p2 : Symbol(p2, Decl(in.js, 6, 14))
>p3 : Symbol(p3, Decl(in.js, 6, 18))
}

14 changes: 14 additions & 0 deletions tests/baselines/reference/jsdocNeverUndefinedNull.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
=== tests/cases/conformance/jsdoc/in.js ===
/**
* @param {never} p1
* @param {undefined} p2
* @param {null} p3
* @returns {void} nothing
*/
function f(p1, p2, p3) {
>f : (p1: never, p2: undefined, p3: null) => void
>p1 : never
>p2 : undefined
>p3 : null
}

11 changes: 11 additions & 0 deletions tests/cases/conformance/jsdoc/jsdocNeverUndefinedNull.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// @allowJs: true
// @filename: in.js
// @out: out.js
/**
* @param {never} p1
* @param {undefined} p2
* @param {null} p3
* @returns {void} nothing
*/
function f(p1, p2, p3) {
}
23 changes: 23 additions & 0 deletions tests/cases/fourslash/jsdocNullableUnion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
///<reference path="fourslash.ts" />
// @allowNonTsExtensions: true
// @Filename: Foo.js
////
//// * @param {never | {x: string}} p1
//// * @param {undefined | {y: number}} p2
//// * @param {null | {z: boolean}} p3
//// * @returns {void} nothing
//// */
////function f(p1, p2, p3) {
//// p1./*1*/
//// p2./*2*/
//// p3./*3*/
////}

goTo.marker('1');
verify.memberListContains("x");

goTo.marker('2');
verify.memberListContains("y");

goTo.marker('3');
verify.memberListContains("z");