Skip to content

Commit d7c3371

Browse files
author
Kanchalai Tanglertsampan
committed
Merge branch 'master' into master-refactorJsDocTest
2 parents e82e737 + f938caf commit d7c3371

12 files changed

+419
-37
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6855,6 +6855,7 @@ namespace ts {
68556855
case "Object":
68566856
return anyType;
68576857
case "Function":
6858+
case "function":
68586859
return globalFunctionType;
68596860
case "Array":
68606861
case "array":

src/compiler/parser.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6075,7 +6075,10 @@ namespace ts {
60756075
case SyntaxKind.OpenBraceToken:
60766076
return parseJSDocRecordType();
60776077
case SyntaxKind.FunctionKeyword:
6078-
return parseJSDocFunctionType();
6078+
if (lookAhead(nextTokenIsOpenParen)) {
6079+
return parseJSDocFunctionType();
6080+
}
6081+
break;
60796082
case SyntaxKind.DotDotDotToken:
60806083
return parseJSDocVariadicType();
60816084
case SyntaxKind.NewKeyword:
@@ -6091,7 +6094,6 @@ namespace ts {
60916094
case SyntaxKind.NullKeyword:
60926095
case SyntaxKind.UndefinedKeyword:
60936096
case SyntaxKind.NeverKeyword:
6094-
case SyntaxKind.ObjectKeyword:
60956097
return parseTokenNode<JSDocType>();
60966098
case SyntaxKind.StringLiteral:
60976099
case SyntaxKind.NumericLiteral:
@@ -6769,7 +6771,7 @@ namespace ts {
67696771
const jsDocTypeReference = <JSDocTypeReference>typeExpression.type;
67706772
if (jsDocTypeReference.name.kind === SyntaxKind.Identifier) {
67716773
const name = <Identifier>jsDocTypeReference.name;
6772-
if (name.text === "Object") {
6774+
if (name.text === "Object" || name.text === "object") {
67736775
typedefTag.jsDocTypeLiteral = scanChildTags();
67746776
}
67756777
}

tests/baselines/reference/checkJsdocTypeTag1.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ anyT1 = "hi";
1818
const x = (a) => a + 1;
1919
x(1);
2020

21+
/** @type {function} */
22+
const y = (a) => a + 1;
23+
x(1);
24+
2125
/** @type {function (number)} */
2226
const x1 = (a) => a + 1;
2327
x1(0);
@@ -41,6 +45,9 @@ anyT1 = "hi";
4145
/** @type {Function} */
4246
var x = function (a) { return a + 1; };
4347
x(1);
48+
/** @type {function} */
49+
var y = function (a) { return a + 1; };
50+
x(1);
4451
/** @type {function (number)} */
4552
var x1 = function (a) { return a + 1; };
4653
x1(0);

tests/baselines/reference/checkJsdocTypeTag1.types

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,20 @@ x(1);
4444
>x : Function
4545
>1 : 1
4646

47+
/** @type {function} */
48+
const y = (a) => a + 1;
49+
>y : Function
50+
>(a) => a + 1 : (a: any) => any
51+
>a : any
52+
>a + 1 : any
53+
>a : any
54+
>1 : 1
55+
56+
x(1);
57+
>x(1) : any
58+
>x : Function
59+
>1 : 1
60+
4761
/** @type {function (number)} */
4862
const x1 = (a) => a + 1;
4963
>x1 : (arg0: number) => any

tests/baselines/reference/checkJsdocTypedefInParamTag1.js

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,29 @@
66
* @property {string=} y
77
* @property {string} [z]
88
* @property {string} [w="hi"]
9-
*
9+
*
1010
* @param {Opts} opts
1111
*/
12-
function foo(opts) {}
12+
function foo(opts) {
13+
opts.x;
14+
}
1315

14-
foo({x: 'abc'});
16+
foo({x: 'abc'});
17+
18+
/**
19+
* @typedef {object} Opts1
20+
* @property {string} x
21+
* @property {string=} y
22+
* @property {string} [z]
23+
* @property {string} [w="hi"]
24+
*
25+
* @param {Opts1} opts
26+
*/
27+
function foo1(opts) {
28+
opts.x;
29+
}
30+
foo1({x: 'abc'});
31+
1532

1633
//// [0.js]
1734
// @ts-check
@@ -24,5 +41,20 @@ foo({x: 'abc'});
2441
*
2542
* @param {Opts} opts
2643
*/
27-
function foo(opts) { }
44+
function foo(opts) {
45+
opts.x;
46+
}
2847
foo({ x: 'abc' });
48+
/**
49+
* @typedef {object} Opts1
50+
* @property {string} x
51+
* @property {string=} y
52+
* @property {string} [z]
53+
* @property {string} [w="hi"]
54+
*
55+
* @param {Opts1} opts
56+
*/
57+
function foo1(opts) {
58+
opts.x;
59+
}
60+
foo1({ x: 'abc' });

tests/baselines/reference/checkJsdocTypedefInParamTag1.symbols

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,42 @@
66
* @property {string=} y
77
* @property {string} [z]
88
* @property {string} [w="hi"]
9-
*
9+
*
1010
* @param {Opts} opts
1111
*/
12-
function foo(opts) {}
12+
function foo(opts) {
1313
>foo : Symbol(foo, Decl(0.js, 0, 0))
1414
>opts : Symbol(opts, Decl(0.js, 10, 13))
1515

16+
opts.x;
17+
>opts.x : Symbol(x, Decl(0.js, 3, 3))
18+
>opts : Symbol(opts, Decl(0.js, 10, 13))
19+
>x : Symbol(x, Decl(0.js, 3, 3))
20+
}
21+
1622
foo({x: 'abc'});
1723
>foo : Symbol(foo, Decl(0.js, 0, 0))
18-
>x : Symbol(x, Decl(0.js, 12, 5))
24+
>x : Symbol(x, Decl(0.js, 14, 5))
25+
26+
/**
27+
* @typedef {object} Opts1
28+
* @property {string} x
29+
* @property {string=} y
30+
* @property {string} [z]
31+
* @property {string} [w="hi"]
32+
*
33+
* @param {Opts1} opts
34+
*/
35+
function foo1(opts) {
36+
>foo1 : Symbol(foo1, Decl(0.js, 14, 16))
37+
>opts : Symbol(opts, Decl(0.js, 25, 14))
38+
39+
opts.x;
40+
>opts.x : Symbol(x, Decl(0.js, 18, 3))
41+
>opts : Symbol(opts, Decl(0.js, 25, 14))
42+
>x : Symbol(x, Decl(0.js, 18, 3))
43+
}
44+
foo1({x: 'abc'});
45+
>foo1 : Symbol(foo1, Decl(0.js, 14, 16))
46+
>x : Symbol(x, Decl(0.js, 28, 6))
1947

tests/baselines/reference/checkJsdocTypedefInParamTag1.types

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,48 @@
66
* @property {string=} y
77
* @property {string} [z]
88
* @property {string} [w="hi"]
9-
*
9+
*
1010
* @param {Opts} opts
1111
*/
12-
function foo(opts) {}
12+
function foo(opts) {
1313
>foo : (opts: { x: string; y?: string; z?: string; w?: string; }) => void
1414
>opts : { x: string; y?: string; z?: string; w?: string; }
1515

16+
opts.x;
17+
>opts.x : string
18+
>opts : { x: string; y?: string; z?: string; w?: string; }
19+
>x : string
20+
}
21+
1622
foo({x: 'abc'});
1723
>foo({x: 'abc'}) : void
1824
>foo : (opts: { x: string; y?: string; z?: string; w?: string; }) => void
1925
>{x: 'abc'} : { x: string; }
2026
>x : string
2127
>'abc' : "abc"
2228

29+
/**
30+
* @typedef {object} Opts1
31+
* @property {string} x
32+
* @property {string=} y
33+
* @property {string} [z]
34+
* @property {string} [w="hi"]
35+
*
36+
* @param {Opts1} opts
37+
*/
38+
function foo1(opts) {
39+
>foo1 : (opts: { x: string; y?: string; z?: string; w?: string; }) => void
40+
>opts : { x: string; y?: string; z?: string; w?: string; }
41+
42+
opts.x;
43+
>opts.x : string
44+
>opts : { x: string; y?: string; z?: string; w?: string; }
45+
>x : string
46+
}
47+
foo1({x: 'abc'});
48+
>foo1({x: 'abc'}) : void
49+
>foo1 : (opts: { x: string; y?: string; z?: string; w?: string; }) => void
50+
>{x: 'abc'} : { x: string; }
51+
>x : string
52+
>'abc' : "abc"
53+

tests/baselines/reference/jsDocTypeTag2.js

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -431,28 +431,8 @@
431431
"kind": "space"
432432
},
433433
{
434-
"text": "(",
435-
"kind": "punctuation"
436-
},
437-
{
438-
"text": ")",
439-
"kind": "punctuation"
440-
},
441-
{
442-
"text": " ",
443-
"kind": "space"
444-
},
445-
{
446-
"text": "=>",
447-
"kind": "punctuation"
448-
},
449-
{
450-
"text": " ",
451-
"kind": "space"
452-
},
453-
{
454-
"text": "any",
455-
"kind": "keyword"
434+
"text": "Function",
435+
"kind": "localName"
456436
}
457437
],
458438
"documentation": [],

0 commit comments

Comments
 (0)