mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-07-02 06:35:09 -05:00
parser: Fix testing for missing list (#25411)
* parser: Fix testing for missing list * Fix return type
This commit is contained in:
@@ -2090,8 +2090,18 @@ namespace ts {
|
||||
return result;
|
||||
}
|
||||
|
||||
function createMissingList<T extends Node>(): NodeArray<T> {
|
||||
return createNodeArray<T>([], getNodePos());
|
||||
interface MissingList<T extends Node> extends NodeArray<T> {
|
||||
isMissingList: true;
|
||||
}
|
||||
|
||||
function createMissingList<T extends Node>(): MissingList<T> {
|
||||
const list = createNodeArray<T>([], getNodePos()) as MissingList<T>;
|
||||
list.isMissingList = true;
|
||||
return list;
|
||||
}
|
||||
|
||||
function isMissingList(arr: NodeArray<Node>): boolean {
|
||||
return !!(arr as MissingList<Node>).isMissingList;
|
||||
}
|
||||
|
||||
function parseBracketedList<T extends Node>(kind: ParsingContext, parseElement: () => T, open: SyntaxKind, close: SyntaxKind): NodeArray<T> {
|
||||
@@ -2260,8 +2270,7 @@ namespace ts {
|
||||
case SyntaxKind.FunctionType:
|
||||
case SyntaxKind.ConstructorType: {
|
||||
const { parameters, type } = node as FunctionOrConstructorTypeNode;
|
||||
// parameters.pos === parameters.end only if we used parseMissingList, else should contain at least `()`
|
||||
return parameters.pos === parameters.end || typeHasArrowFunctionBlockingParseError(type);
|
||||
return isMissingList(parameters) || typeHasArrowFunctionBlockingParseError(type);
|
||||
}
|
||||
case SyntaxKind.ParenthesizedType:
|
||||
return typeHasArrowFunctionBlockingParseError((node as ParenthesizedTypeNode).type);
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
//// [parseArrowFunctionWithFunctionReturnType.ts]
|
||||
const fn = <T>(): (() => T) => null as any;
|
||||
|
||||
|
||||
//// [parseArrowFunctionWithFunctionReturnType.js]
|
||||
var fn = function () { return null; };
|
||||
@@ -0,0 +1,6 @@
|
||||
=== tests/cases/compiler/parseArrowFunctionWithFunctionReturnType.ts ===
|
||||
const fn = <T>(): (() => T) => null as any;
|
||||
>fn : Symbol(fn, Decl(parseArrowFunctionWithFunctionReturnType.ts, 0, 5))
|
||||
>T : Symbol(T, Decl(parseArrowFunctionWithFunctionReturnType.ts, 0, 12))
|
||||
>T : Symbol(T, Decl(parseArrowFunctionWithFunctionReturnType.ts, 0, 12))
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
=== tests/cases/compiler/parseArrowFunctionWithFunctionReturnType.ts ===
|
||||
const fn = <T>(): (() => T) => null as any;
|
||||
>fn : <T>() => () => T
|
||||
><T>(): (() => T) => null as any : <T>() => () => T
|
||||
>T : T
|
||||
>T : T
|
||||
>null as any : any
|
||||
>null : null
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
const fn = <T>(): (() => T) => null as any;
|
||||
Reference in New Issue
Block a user