@@ -1799,11 +1799,12 @@ module ts {
1799
1799
}
1800
1800
1801
1801
function buildParameterDisplay(p: Symbol, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, typeStack?: Type[]) {
1802
- if (hasDotDotDotToken(p.valueDeclaration)) {
1802
+ let parameterNode = <ParameterDeclaration>p.valueDeclaration;
1803
+ if (isRestParameter(parameterNode)) {
1803
1804
writePunctuation(writer, SyntaxKind.DotDotDotToken);
1804
1805
}
1805
1806
appendSymbolNameOnly(p, writer);
1806
- if (hasQuestionToken(p.valueDeclaration) || (<ParameterDeclaration>p.valueDeclaration).initializer ) {
1807
+ if (isOptionalParameter(parameterNode) ) {
1807
1808
writePunctuation(writer, SyntaxKind.QuestionToken);
1808
1809
}
1809
1810
writePunctuation(writer, SyntaxKind.ColonToken);
@@ -3197,6 +3198,10 @@ module ts {
3197
3198
return result;
3198
3199
}
3199
3200
3201
+ function isOptionalParameter(node: ParameterDeclaration) {
3202
+ return hasQuestionToken(node) || !!node.initializer;
3203
+ }
3204
+
3200
3205
function getSignatureFromDeclaration(declaration: SignatureDeclaration): Signature {
3201
3206
let links = getNodeLinks(declaration);
3202
3207
if (!links.resolvedSignature) {
@@ -3244,7 +3249,7 @@ module ts {
3244
3249
}
3245
3250
3246
3251
links.resolvedSignature = createSignature(declaration, typeParameters, parameters, returnType,
3247
- minArgumentCount, hasRestParameters (declaration), hasStringLiterals);
3252
+ minArgumentCount, hasRestParameter (declaration), hasStringLiterals);
3248
3253
}
3249
3254
return links.resolvedSignature;
3250
3255
}
@@ -3520,42 +3525,50 @@ module ts {
3520
3525
type = unknownType;
3521
3526
}
3522
3527
else {
3523
- type = getDeclaredTypeOfSymbol(symbol);
3524
- if (type.flags & (TypeFlags.Class | TypeFlags.Interface) && type.flags & TypeFlags.Reference) {
3525
- // In a type reference, the outer type parameters of the referenced class or interface are automatically
3526
- // supplied as type arguments and the type reference only specifies arguments for the local type parameters
3527
- // of the class or interface.
3528
- let localTypeParameters = (<InterfaceType>type).localTypeParameters;
3529
- let expectedTypeArgCount = localTypeParameters ? localTypeParameters.length : 0;
3530
- let typeArgCount = node.typeArguments ? node.typeArguments.length : 0;
3531
- if (typeArgCount === expectedTypeArgCount) {
3532
- // When no type arguments are expected we already have the right type because all outer type parameters
3533
- // have themselves as default type arguments.
3534
- if (typeArgCount) {
3535
- type = createTypeReference(<GenericType>type, concatenate((<InterfaceType>type).outerTypeParameters,
3536
- map(node.typeArguments, getTypeFromTypeNode)));
3537
- }
3538
- }
3539
- else {
3540
- error(node, Diagnostics.Generic_type_0_requires_1_type_argument_s, typeToString(type, /*enclosingDeclaration*/ undefined, TypeFormatFlags.WriteArrayAsGenericType), expectedTypeArgCount);
3541
- type = undefined;
3542
- }
3543
- }
3544
- else {
3545
- if (node.typeArguments) {
3546
- error(node, Diagnostics.Type_0_is_not_generic, typeToString(type));
3547
- type = undefined;
3548
- }
3549
- }
3528
+ type = createTypeReferenceIfGeneric(
3529
+ getDeclaredTypeOfSymbol(symbol),
3530
+ node, node.typeArguments);
3550
3531
}
3551
3532
}
3552
3533
}
3553
3534
3554
3535
links.resolvedType = type || unknownType;
3555
3536
}
3537
+
3556
3538
return links.resolvedType;
3557
3539
}
3558
3540
3541
+ function createTypeReferenceIfGeneric(type: Type, node: Node, typeArguments: NodeArray<TypeNode>): Type {
3542
+ if (type.flags & (TypeFlags.Class | TypeFlags.Interface) && type.flags & TypeFlags.Reference) {
3543
+ // In a type reference, the outer type parameters of the referenced class or interface are automatically
3544
+ // supplied as type arguments and the type reference only specifies arguments for the local type parameters
3545
+ // of the class or interface.
3546
+ let localTypeParameters = (<InterfaceType>type).localTypeParameters;
3547
+ let expectedTypeArgCount = localTypeParameters ? localTypeParameters.length : 0;
3548
+ let typeArgCount = typeArguments ? typeArguments.length : 0;
3549
+ if (typeArgCount === expectedTypeArgCount) {
3550
+ // When no type arguments are expected we already have the right type because all outer type parameters
3551
+ // have themselves as default type arguments.
3552
+ if (typeArgCount) {
3553
+ return createTypeReference(<GenericType>type, concatenate((<InterfaceType>type).outerTypeParameters,
3554
+ map(typeArguments, getTypeFromTypeNode)));
3555
+ }
3556
+ }
3557
+ else {
3558
+ error(node, Diagnostics.Generic_type_0_requires_1_type_argument_s, typeToString(type, /*enclosingDeclaration*/ undefined, TypeFormatFlags.WriteArrayAsGenericType), expectedTypeArgCount);
3559
+ return undefined;
3560
+ }
3561
+ }
3562
+ else {
3563
+ if (typeArguments) {
3564
+ error(node, Diagnostics.Type_0_is_not_generic, typeToString(type));
3565
+ return undefined;
3566
+ }
3567
+ }
3568
+
3569
+ return type;
3570
+ }
3571
+
3559
3572
function getTypeFromTypeQueryNode(node: TypeQueryNode): Type {
3560
3573
let links = getNodeLinks(node);
3561
3574
if (!links.resolvedType) {
@@ -5858,7 +5871,7 @@ module ts {
5858
5871
let contextualSignature = getContextualSignature(func);
5859
5872
if (contextualSignature) {
5860
5873
5861
- let funcHasRestParameters = hasRestParameters (func);
5874
+ let funcHasRestParameters = hasRestParameter (func);
5862
5875
let len = func.parameters.length - (funcHasRestParameters ? 1 : 0);
5863
5876
let indexOfParameter = indexOf(func.parameters, parameter);
5864
5877
if (indexOfParameter < len) {
@@ -9330,7 +9343,7 @@ module ts {
9330
9343
9331
9344
function checkCollisionWithArgumentsInGeneratedCode(node: SignatureDeclaration) {
9332
9345
// no rest parameters \ declaration context \ overload - no codegen impact
9333
- if (!hasRestParameters (node) || isInAmbientContext(node) || nodeIsMissing((<FunctionLikeDeclaration>node).body)) {
9346
+ if (!hasRestParameter (node) || isInAmbientContext(node) || nodeIsMissing((<FunctionLikeDeclaration>node).body)) {
9334
9347
return;
9335
9348
}
9336
9349
0 commit comments