Skip to content

Commit

Permalink
refactor isStartOfFunctionType into isStartOfFunctionTypeOrConstructo…
Browse files Browse the repository at this point in the history
…rType
  • Loading branch information
uhyo committed Jul 15, 2020
1 parent 38167bc commit 32562ff
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -3711,7 +3714,7 @@ namespace ts {
}

function parseTypeWorker(noConditionalTypes?: boolean): TypeNode {
if (isStartOfFunctionType() || token() === SyntaxKind.NewKeyword) {
if (isStartOfFunctionTypeOrConstructorType()) {
return parseFunctionOrConstructorType();
}
const pos = getNodePos();
Expand Down

0 comments on commit 32562ff

Please sign in to comment.