Skip to content

Commit e671bd6

Browse files
Merge pull request microsoft#3351 from Microsoft/minorJsDocMerges
Simple changes to the compiler to make the jsDoc work easier.
2 parents f624c0f + 7ef2cfe commit e671bd6

File tree

4 files changed

+51
-48
lines changed

4 files changed

+51
-48
lines changed

src/compiler/binder.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,12 @@ module ts {
111111
return (<Identifier | LiteralExpression>node.name).text;
112112
}
113113
switch (node.kind) {
114-
case SyntaxKind.ConstructorType:
115114
case SyntaxKind.Constructor:
116115
return "__constructor";
117116
case SyntaxKind.FunctionType:
118117
case SyntaxKind.CallSignature:
119118
return "__call";
119+
case SyntaxKind.ConstructorType:
120120
case SyntaxKind.ConstructSignature:
121121
return "__new";
122122
case SyntaxKind.IndexSignature:
@@ -380,7 +380,7 @@ module ts {
380380
let typeLiteralSymbol = createSymbol(SymbolFlags.TypeLiteral, "__type");
381381
addDeclarationToSymbol(typeLiteralSymbol, node, SymbolFlags.TypeLiteral);
382382
typeLiteralSymbol.members = {};
383-
typeLiteralSymbol.members[node.kind === SyntaxKind.FunctionType ? "__call" : "__new"] = symbol
383+
typeLiteralSymbol.members[symbol.name] = symbol
384384
}
385385

386386
function bindAnonymousDeclaration(node: Declaration, symbolKind: SymbolFlags, name: string, isBlockScopeContainer: boolean) {
@@ -592,10 +592,8 @@ module ts {
592592
bindChildren(node, 0, /*isBlockScopeContainer*/ true);
593593
break;
594594
default:
595-
let saveParent = parent;
596-
parent = node;
597-
forEachChild(node, bind);
598-
parent = saveParent;
595+
bindChildren(node, 0, /*isBlockScopeContainer:*/ false);
596+
break;
599597
}
600598
}
601599

src/compiler/checker.ts

Lines changed: 45 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1799,11 +1799,12 @@ module ts {
17991799
}
18001800

18011801
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)) {
18031804
writePunctuation(writer, SyntaxKind.DotDotDotToken);
18041805
}
18051806
appendSymbolNameOnly(p, writer);
1806-
if (hasQuestionToken(p.valueDeclaration) || (<ParameterDeclaration>p.valueDeclaration).initializer) {
1807+
if (isOptionalParameter(parameterNode)) {
18071808
writePunctuation(writer, SyntaxKind.QuestionToken);
18081809
}
18091810
writePunctuation(writer, SyntaxKind.ColonToken);
@@ -3197,6 +3198,10 @@ module ts {
31973198
return result;
31983199
}
31993200

3201+
function isOptionalParameter(node: ParameterDeclaration) {
3202+
return hasQuestionToken(node) || !!node.initializer;
3203+
}
3204+
32003205
function getSignatureFromDeclaration(declaration: SignatureDeclaration): Signature {
32013206
let links = getNodeLinks(declaration);
32023207
if (!links.resolvedSignature) {
@@ -3244,7 +3249,7 @@ module ts {
32443249
}
32453250

32463251
links.resolvedSignature = createSignature(declaration, typeParameters, parameters, returnType,
3247-
minArgumentCount, hasRestParameters(declaration), hasStringLiterals);
3252+
minArgumentCount, hasRestParameter(declaration), hasStringLiterals);
32483253
}
32493254
return links.resolvedSignature;
32503255
}
@@ -3520,42 +3525,50 @@ module ts {
35203525
type = unknownType;
35213526
}
35223527
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);
35503531
}
35513532
}
35523533
}
35533534

35543535
links.resolvedType = type || unknownType;
35553536
}
3537+
35563538
return links.resolvedType;
35573539
}
35583540

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+
35593572
function getTypeFromTypeQueryNode(node: TypeQueryNode): Type {
35603573
let links = getNodeLinks(node);
35613574
if (!links.resolvedType) {
@@ -5858,7 +5871,7 @@ module ts {
58585871
let contextualSignature = getContextualSignature(func);
58595872
if (contextualSignature) {
58605873

5861-
let funcHasRestParameters = hasRestParameters(func);
5874+
let funcHasRestParameters = hasRestParameter(func);
58625875
let len = func.parameters.length - (funcHasRestParameters ? 1 : 0);
58635876
let indexOfParameter = indexOf(func.parameters, parameter);
58645877
if (indexOfParameter < len) {
@@ -9330,7 +9343,7 @@ module ts {
93309343

93319344
function checkCollisionWithArgumentsInGeneratedCode(node: SignatureDeclaration) {
93329345
// 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)) {
93349347
return;
93359348
}
93369349

src/compiler/emitter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3205,7 +3205,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
32053205
}
32063206

32073207
function emitRestParameter(node: FunctionLikeDeclaration) {
3208-
if (languageVersion < ScriptTarget.ES6 && hasRestParameters(node)) {
3208+
if (languageVersion < ScriptTarget.ES6 && hasRestParameter(node)) {
32093209
let restIndex = node.parameters.length - 1;
32103210
let restParam = node.parameters[restIndex];
32113211

@@ -3333,7 +3333,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
33333333
write("(");
33343334
if (node) {
33353335
let parameters = node.parameters;
3336-
let omitCount = languageVersion < ScriptTarget.ES6 && hasRestParameters(node) ? 1 : 0;
3336+
let omitCount = languageVersion < ScriptTarget.ES6 && hasRestParameter(node) ? 1 : 0;
33373337
emitList(parameters, 0, parameters.length - omitCount, /*multiLine*/ false, /*trailingComma*/ false);
33383338
}
33393339
write(")");

src/compiler/utilities.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -963,10 +963,6 @@ module ts {
963963
}
964964
}
965965

966-
export function hasDotDotDotToken(node: Node) {
967-
return node && node.kind === SyntaxKind.Parameter && (<ParameterDeclaration>node).dotDotDotToken !== undefined;
968-
}
969-
970966
export function hasQuestionToken(node: Node) {
971967
if (node) {
972968
switch (node.kind) {
@@ -986,10 +982,6 @@ module ts {
986982
return false;
987983
}
988984

989-
export function hasRestParameters(s: SignatureDeclaration): boolean {
990-
return s.parameters.length > 0 && lastOrUndefined(s.parameters).dotDotDotToken !== undefined;
991-
}
992-
993985
export function isJSDocConstructSignature(node: Node) {
994986
return node.kind === SyntaxKind.JSDocFunctionType &&
995987
(<JSDocFunctionType>node).parameters.length > 0 &&

0 commit comments

Comments
 (0)