-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
JSDoc string literal types #9995
Changes from all commits
a6642d6
6fbd79b
5c2ba01
f8103b5
e5973b8
4c35296
3c32478
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -346,6 +346,7 @@ namespace ts { | |
JSDocTypedefTag, | ||
JSDocPropertyTag, | ||
JSDocTypeLiteral, | ||
JSDocLiteralType, | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You may need to update the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated |
||
// Synthesized list | ||
SyntaxList, | ||
|
@@ -376,9 +377,9 @@ namespace ts { | |
LastBinaryOperator = CaretEqualsToken, | ||
FirstNode = QualifiedName, | ||
FirstJSDocNode = JSDocTypeExpression, | ||
LastJSDocNode = JSDocTypeLiteral, | ||
LastJSDocNode = JSDocLiteralType, | ||
FirstJSDocTagNode = JSDocComment, | ||
LastJSDocTagNode = JSDocTypeLiteral | ||
LastJSDocTagNode = JSDocLiteralType | ||
} | ||
|
||
export const enum NodeFlags { | ||
|
@@ -1492,6 +1493,10 @@ namespace ts { | |
type: JSDocType; | ||
} | ||
|
||
export interface JSDocLiteralType extends JSDocType { | ||
literal: LiteralTypeNode; | ||
} | ||
|
||
export type JSDocTypeReferencingNode = JSDocThisType | JSDocConstructorType | JSDocVariadicType | JSDocOptionalType | JSDocNullableType | JSDocNonNullableType; | ||
|
||
// @kind(SyntaxKind.JSDocRecordMember) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
//// [in.js] | ||
/** | ||
* @param {'literal'} p1 | ||
* @param {"literal"} p2 | ||
* @param {'literal' | 'other'} p3 | ||
* @param {'literal' | number} p4 | ||
* @param {12 | true | 'str'} p5 | ||
*/ | ||
function f(p1, p2, p3, p4, p5) { | ||
return p1 + p2 + p3 + p4 + p5 + '.'; | ||
} | ||
|
||
|
||
//// [out.js] | ||
/** | ||
* @param {'literal'} p1 | ||
* @param {"literal"} p2 | ||
* @param {'literal' | 'other'} p3 | ||
* @param {'literal' | number} p4 | ||
* @param {12 | true | 'str'} p5 | ||
*/ | ||
function f(p1, p2, p3, p4, p5) { | ||
return p1 + p2 + p3 + p4 + p5 + '.'; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
=== tests/cases/conformance/jsdoc/in.js === | ||
/** | ||
* @param {'literal'} p1 | ||
* @param {"literal"} p2 | ||
* @param {'literal' | 'other'} p3 | ||
* @param {'literal' | number} p4 | ||
* @param {12 | true | 'str'} p5 | ||
*/ | ||
function f(p1, p2, p3, p4, p5) { | ||
>f : Symbol(f, Decl(in.js, 0, 0)) | ||
>p1 : Symbol(p1, Decl(in.js, 7, 11)) | ||
>p2 : Symbol(p2, Decl(in.js, 7, 14)) | ||
>p3 : Symbol(p3, Decl(in.js, 7, 18)) | ||
>p4 : Symbol(p4, Decl(in.js, 7, 22)) | ||
>p5 : Symbol(p5, Decl(in.js, 7, 26)) | ||
|
||
return p1 + p2 + p3 + p4 + p5 + '.'; | ||
>p1 : Symbol(p1, Decl(in.js, 7, 11)) | ||
>p2 : Symbol(p2, Decl(in.js, 7, 14)) | ||
>p3 : Symbol(p3, Decl(in.js, 7, 18)) | ||
>p4 : Symbol(p4, Decl(in.js, 7, 22)) | ||
>p5 : Symbol(p5, Decl(in.js, 7, 26)) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
=== tests/cases/conformance/jsdoc/in.js === | ||
/** | ||
* @param {'literal'} p1 | ||
* @param {"literal"} p2 | ||
* @param {'literal' | 'other'} p3 | ||
* @param {'literal' | number} p4 | ||
* @param {12 | true | 'str'} p5 | ||
*/ | ||
function f(p1, p2, p3, p4, p5) { | ||
>f : (p1: "literal", p2: "literal", p3: "literal" | "other", p4: number | "literal", p5: true | 12 | "str") => string | ||
>p1 : "literal" | ||
>p2 : "literal" | ||
>p3 : "literal" | "other" | ||
>p4 : number | "literal" | ||
>p5 : true | 12 | "str" | ||
|
||
return p1 + p2 + p3 + p4 + p5 + '.'; | ||
>p1 + p2 + p3 + p4 + p5 + '.' : string | ||
>p1 + p2 + p3 + p4 + p5 : string | ||
>p1 + p2 + p3 + p4 : string | ||
>p1 + p2 + p3 : string | ||
>p1 + p2 : string | ||
>p1 : "literal" | ||
>p2 : "literal" | ||
>p3 : "literal" | "other" | ||
>p4 : number | "literal" | ||
>p5 : true | 12 | "str" | ||
>'.' : string | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// @allowJs: true | ||
// @filename: in.js | ||
// @out: out.js | ||
/** | ||
* @param {'literal'} p1 | ||
* @param {"literal"} p2 | ||
* @param {'literal' | 'other'} p3 | ||
* @param {'literal' | number} p4 | ||
* @param {12 | true | 'str'} p5 | ||
*/ | ||
function f(p1, p2, p3, p4, p5) { | ||
return p1 + p2 + p3 + p4 + p5 + '.'; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/// <reference path='fourslash.ts'/> | ||
// @allowJs: true | ||
// @Filename: in.js | ||
/////** I am documentation | ||
//// * @param {'literal'} p1 | ||
//// * @param {"literal"} p2 | ||
//// * @param {'other1' | 'other2'} p3 | ||
//// * @param {'literal' | number} p4 | ||
//// * @param {12 | true} p5 | ||
//// */ | ||
////function f(p1, p2, p3, p4, p5) { | ||
//// return p1 + p2 + p3 + p4 + p5 + '.'; | ||
////} | ||
////f/*1*/('literal', 'literal', "o/*2*/ther1", 12); | ||
|
||
goTo.marker('1'); | ||
verify.quickInfoExists(); | ||
verify.quickInfoIs('function f(p1: "literal", p2: "literal", p3: "other1" | "other2", p4: number | "literal", p5: true | 12): string', 'I am documentation'); | ||
|
||
goTo.marker('2'); | ||
verify.completionListContains("other1"); | ||
verify.completionListContains("other2"); | ||
verify.memberListCount(2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need
NeverKeyword
andUndefinedKeyword
here tooThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and
NullKeyword
as well.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, those are not literal types, it turns out. In the interests of getting this PR in, I'll do those separately.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They probably need their own special handling (see the lines preceding the diff in checker)