From 32562ff094ee7075614735d260163dc934d2b3d1 Mon Sep 17 00:00:00 2001 From: uhyo Date: Wed, 15 Jul 2020 10:15:52 +0900 Subject: [PATCH] refactor isStartOfFunctionType into isStartOfFunctionTypeOrConstructorType --- src/compiler/parser.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index a787a7d8358b3..3aa55a67859a8 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3575,7 +3575,7 @@ namespace ts { // the function type and constructor type shorthand notation // are not allowed directly in unions and intersections, but we'll // try to parse them gracefully and issue a helpful message. - if (isStartOfFunctionType() || token() === SyntaxKind.NewKeyword) { + if (isStartOfFunctionTypeOrConstructorType()) { const type = parseFunctionOrConstructorType(); let diagnostic: DiagnosticMessage; if (isFunctionTypeNode(type)) { @@ -3622,11 +3622,14 @@ namespace ts { return parseUnionOrIntersectionType(SyntaxKind.BarToken, parseIntersectionTypeOrHigher, factory.createUnionTypeNode); } - function isStartOfFunctionType(): boolean { + function isStartOfFunctionTypeOrConstructorType(): boolean { if (token() === SyntaxKind.LessThanToken) { return true; } - return token() === SyntaxKind.OpenParenToken && lookAhead(isUnambiguouslyStartOfFunctionType); + if(token() === SyntaxKind.OpenParenToken && lookAhead(isUnambiguouslyStartOfFunctionType)) { + return true; + } + return token() === SyntaxKind.NewKeyword; } function skipParameterStart(): boolean { @@ -3711,7 +3714,7 @@ namespace ts { } function parseTypeWorker(noConditionalTypes?: boolean): TypeNode { - if (isStartOfFunctionType() || token() === SyntaxKind.NewKeyword) { + if (isStartOfFunctionTypeOrConstructorType()) { return parseFunctionOrConstructorType(); } const pos = getNodePos();