From 4838eff2d7b0833c62b6e9e667fd3d5e006cf070 Mon Sep 17 00:00:00 2001 From: Yui T Date: Mon, 29 May 2017 20:37:01 -0700 Subject: [PATCH 1/2] "function" without followed by "(" should be considered as Global function type --- src/compiler/checker.ts | 1 + src/compiler/parser.ts | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 125e492cc39..9ff1c4b41b9 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6855,6 +6855,7 @@ namespace ts { case "Object": return anyType; case "Function": + case "function": return globalFunctionType; case "Array": case "array": diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 07d4a9ada41..04d70639e12 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -6075,7 +6075,10 @@ namespace ts { case SyntaxKind.OpenBraceToken: return parseJSDocRecordType(); case SyntaxKind.FunctionKeyword: - return parseJSDocFunctionType(); + if (lookAhead(nextTokenIsOpenParen)) { + return parseJSDocFunctionType(); + } + break; case SyntaxKind.DotDotDotToken: return parseJSDocVariadicType(); case SyntaxKind.NewKeyword: From 0ead501c86203d3c5473acaaf98e1c61ad0c5bab Mon Sep 17 00:00:00 2001 From: Yui T Date: Mon, 29 May 2017 20:37:15 -0700 Subject: [PATCH 2/2] Update tests and baselines --- tests/baselines/reference/jsDocTypeTag2.js | 24 ++---------------- tests/baselines/reference/jsDocTypes2.js | 7 ++++++ tests/baselines/reference/jsDocTypes2.symbols | 25 +++++++++++++------ tests/baselines/reference/jsDocTypes2.types | 14 +++++++++++ tests/cases/conformance/salsa/jsDocTypes2.ts | 4 +++ 5 files changed, 44 insertions(+), 30 deletions(-) diff --git a/tests/baselines/reference/jsDocTypeTag2.js b/tests/baselines/reference/jsDocTypeTag2.js index 07535dcee08..d54b4557f06 100644 --- a/tests/baselines/reference/jsDocTypeTag2.js +++ b/tests/baselines/reference/jsDocTypeTag2.js @@ -431,28 +431,8 @@ "kind": "space" }, { - "text": "(", - "kind": "punctuation" - }, - { - "text": ")", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "=>", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "any", - "kind": "keyword" + "text": "Function", + "kind": "localName" } ], "documentation": [], diff --git a/tests/baselines/reference/jsDocTypes2.js b/tests/baselines/reference/jsDocTypes2.js index a3848704fad..ba59043978c 100644 --- a/tests/baselines/reference/jsDocTypes2.js +++ b/tests/baselines/reference/jsDocTypes2.js @@ -11,6 +11,10 @@ anyT1 = "hi"; const x = (a) => a + 1; x(1); +/** @type {function} */ +const y = (a) => a + 1; +x(1); + /** @type {function (number)} */ const x1 = (a) => a + 1; x1(0); @@ -29,6 +33,9 @@ anyT1 = "hi"; /** @type {Function} */ var x = function (a) { return a + 1; }; x(1); +/** @type {function} */ +var y = function (a) { return a + 1; }; +x(1); /** @type {function (number)} */ var x1 = function (a) { return a + 1; }; x1(0); diff --git a/tests/baselines/reference/jsDocTypes2.symbols b/tests/baselines/reference/jsDocTypes2.symbols index 96b32b9ad91..8f4dc4e7b43 100644 --- a/tests/baselines/reference/jsDocTypes2.symbols +++ b/tests/baselines/reference/jsDocTypes2.symbols @@ -20,21 +20,30 @@ const x = (a) => a + 1; x(1); >x : Symbol(x, Decl(0.js, 9, 5)) +/** @type {function} */ +const y = (a) => a + 1; +>y : Symbol(y, Decl(0.js, 13, 5)) +>a : Symbol(a, Decl(0.js, 13, 11)) +>a : Symbol(a, Decl(0.js, 13, 11)) + +x(1); +>x : Symbol(x, Decl(0.js, 9, 5)) + /** @type {function (number)} */ const x1 = (a) => a + 1; ->x1 : Symbol(x1, Decl(0.js, 13, 5)) ->a : Symbol(a, Decl(0.js, 13, 12)) ->a : Symbol(a, Decl(0.js, 13, 12)) +>x1 : Symbol(x1, Decl(0.js, 17, 5)) +>a : Symbol(a, Decl(0.js, 17, 12)) +>a : Symbol(a, Decl(0.js, 17, 12)) x1(0); ->x1 : Symbol(x1, Decl(0.js, 13, 5)) +>x1 : Symbol(x1, Decl(0.js, 17, 5)) /** @type {function (number): number} */ const x2 = (a) => a + 1; ->x2 : Symbol(x2, Decl(0.js, 17, 5)) ->a : Symbol(a, Decl(0.js, 17, 12)) ->a : Symbol(a, Decl(0.js, 17, 12)) +>x2 : Symbol(x2, Decl(0.js, 21, 5)) +>a : Symbol(a, Decl(0.js, 21, 12)) +>a : Symbol(a, Decl(0.js, 21, 12)) x2(0); ->x2 : Symbol(x2, Decl(0.js, 17, 5)) +>x2 : Symbol(x2, Decl(0.js, 21, 5)) diff --git a/tests/baselines/reference/jsDocTypes2.types b/tests/baselines/reference/jsDocTypes2.types index db5a5902d10..599c19c7ffc 100644 --- a/tests/baselines/reference/jsDocTypes2.types +++ b/tests/baselines/reference/jsDocTypes2.types @@ -29,6 +29,20 @@ x(1); >x : Function >1 : 1 +/** @type {function} */ +const y = (a) => a + 1; +>y : Function +>(a) => a + 1 : (a: any) => any +>a : any +>a + 1 : any +>a : any +>1 : 1 + +x(1); +>x(1) : any +>x : Function +>1 : 1 + /** @type {function (number)} */ const x1 = (a) => a + 1; >x1 : (arg0: number) => any diff --git a/tests/cases/conformance/salsa/jsDocTypes2.ts b/tests/cases/conformance/salsa/jsDocTypes2.ts index 612804b91d7..21107f87ccf 100644 --- a/tests/cases/conformance/salsa/jsDocTypes2.ts +++ b/tests/cases/conformance/salsa/jsDocTypes2.ts @@ -14,6 +14,10 @@ anyT1 = "hi"; const x = (a) => a + 1; x(1); +/** @type {function} */ +const y = (a) => a + 1; +x(1); + /** @type {function (number)} */ const x1 = (a) => a + 1; x1(0);