Move grammar checking: catchCaluse

This commit is contained in:
Yui T
2014-12-11 14:53:30 -08:00
parent b34a453cd4
commit f13308be31
2 changed files with 19 additions and 2 deletions
+18 -1
View File
@@ -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;
}
+1 -1
View File
@@ -4636,7 +4636,7 @@ module ts {
case SyntaxKind.EnumDeclaration: return checkEnumDeclaration(<EnumDeclaration>node);
//case SyntaxKind.BinaryExpression: return checkBinaryExpression(<BinaryExpression>node);
//case SyntaxKind.BindingElement: return checkBindingElement(<BindingElement>node);
case SyntaxKind.CatchClause: return checkCatchClause(<CatchClause>node);
//case SyntaxKind.CatchClause: return checkCatchClause(<CatchClause>node);
case SyntaxKind.ClassDeclaration: return checkClassDeclaration(<ClassDeclaration>node);
case SyntaxKind.ComputedPropertyName: return checkComputedPropertyName(<ComputedPropertyName>node);
case SyntaxKind.Constructor: return checkConstructor(<ConstructorDeclaration>node);