Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
PR feedback
  • Loading branch information
rbuckton committed Apr 6, 2015
commit 98c56ae9a8aac5bc5024a4ebd8db943418530755
25 changes: 18 additions & 7 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8768,19 +8768,28 @@ module ts {
*/
function checkTypeAnnotationAsExpression(node: AccessorDeclaration | PropertyDeclaration | ParameterDeclaration | MethodDeclaration) {
switch (node.kind) {
case SyntaxKind.PropertyDeclaration: return checkTypeNodeAsExpression((<PropertyDeclaration>node).type);
case SyntaxKind.Parameter: return checkTypeNodeAsExpression((<ParameterDeclaration>node).type);
case SyntaxKind.MethodDeclaration: return checkTypeNodeAsExpression((<MethodDeclaration>node).type);
case SyntaxKind.GetAccessor: return checkTypeNodeAsExpression((<AccessorDeclaration>node).type);
case SyntaxKind.SetAccessor: return checkTypeNodeAsExpression(getSetAccessorTypeAnnotationNode(<AccessorDeclaration>node));
case SyntaxKind.PropertyDeclaration:
checkTypeNodeAsExpression((<PropertyDeclaration>node).type);
break;
case SyntaxKind.Parameter: checkTypeNodeAsExpression((<ParameterDeclaration>node).type);
break;
case SyntaxKind.MethodDeclaration:
checkTypeNodeAsExpression((<MethodDeclaration>node).type);
break;
case SyntaxKind.GetAccessor:
checkTypeNodeAsExpression((<AccessorDeclaration>node).type);
break;
case SyntaxKind.SetAccessor:
checkTypeNodeAsExpression(getSetAccessorTypeAnnotationNode(<AccessorDeclaration>node));
break;
}
}

/** Checks the type annotation of the parameters of a function/method or the constructor of a class as expressions */
function checkParameterTypeAnnotationsAsExpressions(node: FunctionLikeDeclaration) {
// ensure all type annotations with a value declaration are checked as an expression
if (node) {
forEach(node.parameters, checkTypeAnnotationAsExpression);
for (let parameter of node.parameters) {
checkTypeAnnotationAsExpression(parameter);
}
}

Expand Down Expand Up @@ -11624,7 +11633,9 @@ module ts {
case SyntaxKind.TypeLiteral:
case SyntaxKind.UnionType:
case SyntaxKind.AnyKeyword:
break;
default:
Debug.fail("Cannot serialize unexpected type node.");
break;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly assert here that somethign was missed. That way if we add a new type kind in the future we know we have to update this.

}
}
Expand Down