@@ -2359,6 +2359,8 @@ namespace ts {
2359
2359
context.InElementType = false;
2360
2360
const inTypeAlias = context.InTypeAlias;
2361
2361
context.InTypeAlias = false;
2362
+ const inFirstTypeArgument = context.InFirstTypeArgument;
2363
+ context.InFirstTypeArgument = false;
2362
2364
2363
2365
// TODO: should be assert?
2364
2366
if (!type) {
@@ -2367,8 +2369,6 @@ namespace ts {
2367
2369
return undefined;
2368
2370
}
2369
2371
2370
-
2371
-
2372
2372
if (type.flags & TypeFlags.Any) {
2373
2373
return createKeywordTypeNode(SyntaxKind.AnyKeyword);
2374
2374
}
@@ -2586,15 +2586,18 @@ namespace ts {
2586
2586
2587
2587
if (resolved.callSignatures.length === 1 && !resolved.constructSignatures.length) {
2588
2588
const signature = resolved.callSignatures[0];
2589
- const functionTypeNode = <FunctionTypeNode>signatureToSignatureDeclarationHelper(signature, SyntaxKind.FunctionType, context);
2589
+ const signatureNode = <FunctionTypeNode>signatureToSignatureDeclarationHelper(signature, SyntaxKind.FunctionType, context);
2590
2590
return shouldAddParenthesisAroundFunctionType(signature, context) ?
2591
- createParenthesizedTypeNode(functionTypeNode ) :
2592
- functionTypeNode ;
2591
+ createParenthesizedTypeNode(signatureNode ) :
2592
+ signatureNode ;
2593
2593
2594
2594
}
2595
2595
if (resolved.constructSignatures.length === 1 && !resolved.callSignatures.length) {
2596
2596
const signature = resolved.constructSignatures[0];
2597
- return <ConstructorTypeNode>signatureToSignatureDeclarationHelper(signature, SyntaxKind.ConstructorType, context);
2597
+ const signatureNode = <ConstructorTypeNode>signatureToSignatureDeclarationHelper(signature, SyntaxKind.ConstructorType, context);
2598
+ return shouldAddParenthesisAroundFunctionType(signature, context) ?
2599
+ createParenthesizedTypeNode(signatureNode) :
2600
+ signatureNode;
2598
2601
}
2599
2602
}
2600
2603
@@ -2610,7 +2613,7 @@ namespace ts {
2610
2613
if (InElementType) {
2611
2614
return true;
2612
2615
}
2613
- else if (context.InFirstTypeArgument ) {
2616
+ else if (inFirstTypeArgument ) {
2614
2617
// Add parenthesis around function type for the first type argument to avoid ambiguity
2615
2618
const typeParameters = callSignature.target && (context.flags & NodeBuilderFlags.WriteTypeArgumentsOfSignature) ?
2616
2619
callSignature.target.typeParameters : callSignature.typeParameters;
@@ -2690,7 +2693,14 @@ namespace ts {
2690
2693
entityName = nameIdentifier;
2691
2694
}
2692
2695
const typeParameterCount = (type.target.typeParameters || emptyArray).length;
2693
- const typeArgumentNodes = some(typeArguments) ? mapToTypeNodeArray(typeArguments.slice(i, typeParameterCount - i), /*addInElementTypeFlag*/ false) : undefined;
2696
+
2697
+ let typeArgumentNodes: TypeNode[] | undefined;
2698
+ if (some(typeArguments)) {
2699
+ const slice = typeArguments.slice(i, typeParameterCount - i);
2700
+ context.InFirstTypeArgument = true;
2701
+ typeArgumentNodes = mapToTypeNodeArray(slice, /*addInElementTypeFlag*/ false);
2702
+ }
2703
+
2694
2704
return createTypeReferenceNode(entityName, typeArgumentNodes);
2695
2705
}
2696
2706
}
@@ -2851,7 +2861,6 @@ namespace ts {
2851
2861
}
2852
2862
}
2853
2863
2854
- // TODO: add meaning: SymbolFlags argument.
2855
2864
// TODO: add SymbolFormatFlags?? Yes to add outer type parameters. Defer UseOnlyExternalAliasing until a separate symbolbuilder PR.
2856
2865
function symbolToName(symbol: Symbol, expectsIdentifier: true, meaning: SymbolFlags, context: NodeBuilderContext): Identifier;
2857
2866
function symbolToName(symbol: Symbol, expectsIdentifier: false, meaning: SymbolFlags, context: NodeBuilderContext): EntityName;
0 commit comments