Skip to content

Commit 76a4694

Browse files
author
Andy
authored
parser: Fix testing for missing list (microsoft#25411)
* parser: Fix testing for missing list * Fix return type
1 parent cb4cb7a commit 76a4694

File tree

5 files changed

+35
-4
lines changed

5 files changed

+35
-4
lines changed

src/compiler/parser.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2090,8 +2090,18 @@ namespace ts {
20902090
return result;
20912091
}
20922092

2093-
function createMissingList<T extends Node>(): NodeArray<T> {
2094-
return createNodeArray<T>([], getNodePos());
2093+
interface MissingList<T extends Node> extends NodeArray<T> {
2094+
isMissingList: true;
2095+
}
2096+
2097+
function createMissingList<T extends Node>(): MissingList<T> {
2098+
const list = createNodeArray<T>([], getNodePos()) as MissingList<T>;
2099+
list.isMissingList = true;
2100+
return list;
2101+
}
2102+
2103+
function isMissingList(arr: NodeArray<Node>): boolean {
2104+
return !!(arr as MissingList<Node>).isMissingList;
20952105
}
20962106

20972107
function parseBracketedList<T extends Node>(kind: ParsingContext, parseElement: () => T, open: SyntaxKind, close: SyntaxKind): NodeArray<T> {
@@ -2260,8 +2270,7 @@ namespace ts {
22602270
case SyntaxKind.FunctionType:
22612271
case SyntaxKind.ConstructorType: {
22622272
const { parameters, type } = node as FunctionOrConstructorTypeNode;
2263-
// parameters.pos === parameters.end only if we used parseMissingList, else should contain at least `()`
2264-
return parameters.pos === parameters.end || typeHasArrowFunctionBlockingParseError(type);
2273+
return isMissingList(parameters) || typeHasArrowFunctionBlockingParseError(type);
22652274
}
22662275
case SyntaxKind.ParenthesizedType:
22672276
return typeHasArrowFunctionBlockingParseError((node as ParenthesizedTypeNode).type);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//// [parseArrowFunctionWithFunctionReturnType.ts]
2+
const fn = <T>(): (() => T) => null as any;
3+
4+
5+
//// [parseArrowFunctionWithFunctionReturnType.js]
6+
var fn = function () { return null; };
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
=== tests/cases/compiler/parseArrowFunctionWithFunctionReturnType.ts ===
2+
const fn = <T>(): (() => T) => null as any;
3+
>fn : Symbol(fn, Decl(parseArrowFunctionWithFunctionReturnType.ts, 0, 5))
4+
>T : Symbol(T, Decl(parseArrowFunctionWithFunctionReturnType.ts, 0, 12))
5+
>T : Symbol(T, Decl(parseArrowFunctionWithFunctionReturnType.ts, 0, 12))
6+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
=== tests/cases/compiler/parseArrowFunctionWithFunctionReturnType.ts ===
2+
const fn = <T>(): (() => T) => null as any;
3+
>fn : <T>() => () => T
4+
><T>(): (() => T) => null as any : <T>() => () => T
5+
>T : T
6+
>T : T
7+
>null as any : any
8+
>null : null
9+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
const fn = <T>(): (() => T) => null as any;

0 commit comments

Comments
 (0)