diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 1cff181c76c..97ea6c1fba4 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8095,7 +8095,11 @@ module ts { function checkTryStatement(node: TryStatement) { checkBlock(node.tryBlock); - if (node.catchClause) checkBlock(node.catchClause.block); + if (node.catchClause) { + // Grammar checking + checkGrammarCatchClause(node.catchClause); + checkBlock(node.catchClause.block); + } if (node.finallyBlock) checkBlock(node.finallyBlock); } @@ -9939,6 +9943,19 @@ module ts { } } + function checkGrammarCatchClause(node: CatchClause) { + if (node.type) { + var sourceFile = getSourceFileOfNode(node); + var colonStart = skipTrivia(sourceFile.text, node.name.end); + grammarErrorAtPos(sourceFile, colonStart, ":".length, Diagnostics.Catch_clause_parameter_cannot_have_a_type_annotation); + } + if (node.parserContextFlags & ParserContextFlags.StrictMode && isEvalOrArgumentsIdentifier(node.name)) { + // 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 + reportGrammarErrorOfInvalidUseInStrictMode(node.name); + } + } + function hasParseDiagnostics(sourceFile: SourceFile): boolean { return sourceFile.parseDiagnostics.length > 0; } diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 5d3ac16d7ab..f1edf8911bd 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -4636,7 +4636,7 @@ module ts { case SyntaxKind.EnumDeclaration: return checkEnumDeclaration(node); //case SyntaxKind.BinaryExpression: return checkBinaryExpression(node); //case SyntaxKind.BindingElement: return checkBindingElement(node); - case SyntaxKind.CatchClause: return checkCatchClause(node); + //case SyntaxKind.CatchClause: return checkCatchClause(node); case SyntaxKind.ClassDeclaration: return checkClassDeclaration(node); case SyntaxKind.ComputedPropertyName: return checkComputedPropertyName(node); case SyntaxKind.Constructor: return checkConstructor(node);