diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 19f228a2c54..0a4658f42b5 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3089,23 +3089,14 @@ module ts { parseExpected(SyntaxKind.CatchKeyword); parseExpected(SyntaxKind.OpenParenToken); var variable = parseIdentifier(); - var typeAnnotationColonStart = scanner.getTokenPos(); - var typeAnnotationColonLength = scanner.getTextPos() - typeAnnotationColonStart; var typeAnnotation = parseTypeAnnotation(); parseExpected(SyntaxKind.CloseParenToken); var result = parseBlock(/* ignoreMissingOpenBrace */ false, /*checkForStrictMode*/ false); result.kind = SyntaxKind.CatchBlock; result.pos = pos; result.variable = variable; + result.type = typeAnnotation; - if (typeAnnotation) { - errorAtPos(typeAnnotationColonStart, typeAnnotationColonLength, Diagnostics.Catch_clause_parameter_cannot_have_a_type_annotation); - } - if (isInStrictMode && isEvalOrArgumentsIdentifier(variable)) { - // It is a SyntaxError if a TryStatement with a Catch occurs within strict code and the Identifier of the - // Catch production is eval or arguments - reportInvalidUseInStrictMode(variable); - } return result; } @@ -4086,6 +4077,7 @@ module ts { switch (node.kind) { case SyntaxKind.ArrowFunction: return visitArrowFunction(node); case SyntaxKind.CallSignature: return visitCallSignature(node); + case SyntaxKind.CatchBlock: return visitCatchBlock(node); case SyntaxKind.Constructor: return visitConstructor(node); case SyntaxKind.ConstructorType: return visitConstructorType(node); case SyntaxKind.ConstructSignature: return visitConstructSignature(node); @@ -4136,6 +4128,18 @@ module ts { checkParameterList(node.parameters); } + function visitCatchBlock(node: CatchBlock) { + if (node.type) { + var colonStart = skipTrivia(sourceText, node.variable.end); + grammarErrorAtPos(colonStart, ":".length, Diagnostics.Catch_clause_parameter_cannot_have_a_type_annotation); + } + if (node.flags & NodeFlags.ParsedInStrictMode && isEvalOrArgumentsIdentifier(node.variable)) { + // It is a SyntaxError if a TryStatement with a Catch occurs within strict code and the Identifier of the + // Catch production is eval or arguments + reportInvalidUseInStrictMode(node.variable); + } + } + function visitConstructor(node: ConstructorDeclaration) { checkParameterList(node.parameters) || checkConstructorTypeParameters(node) || diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 227034993ca..1e623a26f7e 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -584,6 +584,7 @@ module ts { export interface CatchBlock extends Block { variable: Identifier; + type?: TypeNode; } export interface ClassDeclaration extends Declaration {