diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 8a79bb20325..098d908ea6e 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -160,8 +160,6 @@ module ts { Constructor_implementation_expected: { code: 2240, category: DiagnosticCategory.Error, key: "Constructor implementation expected." }, An_export_assignment_cannot_be_used_in_a_module_with_other_exported_elements: { code: 2245, category: DiagnosticCategory.Error, key: "An export assignment cannot be used in a module with other exported elements." }, A_parameter_property_is_only_allowed_in_a_constructor_implementation: { code: 2246, category: DiagnosticCategory.Error, key: "A parameter property is only allowed in a constructor implementation." }, - A_catch_clause_must_be_preceded_by_a_try_statement: { code: 2249, category: DiagnosticCategory.Error, key: "A 'catch' clause must be preceded by a 'try' statement." }, - A_finally_block_must_be_preceded_by_a_try_statement: { code: 2250, category: DiagnosticCategory.Error, key: "A 'finally' block must be preceded by a 'try' statement." }, Circular_definition_of_import_alias_0: { code: 3000, category: DiagnosticCategory.Error, key: "Circular definition of import alias '{0}'." }, Cannot_find_name_0: { code: 3001, category: DiagnosticCategory.Error, key: "Cannot find name '{0}'." }, Module_0_has_no_exported_member_1: { code: 3002, category: DiagnosticCategory.Error, key: "Module '{0}' has no exported member '{1}'." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 93966c1b440..4769121297a 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -632,14 +632,6 @@ "category": "Error", "code": 2246 }, - "A 'catch' clause must be preceded by a 'try' statement.": { - "category": "Error", - "code": 2249 - }, - "A 'finally' block must be preceded by a 'try' statement.": { - "category": "Error", - "code": 2250 - }, "Circular definition of import alias '{0}'.": { "category": "Error", @@ -1246,4 +1238,4 @@ "category": "Error", "code": -9999999 } -} \ No newline at end of file +} diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 0ffe2f5cfbd..27a1906d62a 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -2542,35 +2542,6 @@ module ts { return finishNode(node); } - // This function is used for parsing 'catch'/'finally' blocks - // in spite of them missing a 'try' statement. - function parseCatchOrFinallyBlocksMissingTryStatement(): TryStatement { - - Debug.assert(token === SyntaxKind.CatchKeyword || token === SyntaxKind.FinallyKeyword, - "'parseCatchOrFinallyBlocksMissingTryStatement' should only be called when the current token is a 'catch' or 'finally' keyword."); - - // We're just going to return a bogus TryStatement. - var node = createNode(SyntaxKind.TryStatement); - node.tryBlock = createNode(SyntaxKind.Block); - node.tryBlock.statements = createMissingList(); - - if (token === SyntaxKind.CatchKeyword) { - error(Diagnostics.A_catch_clause_must_be_preceded_by_a_try_statement); - node.catchBlock = parseCatchBlock(); - } - - if (token === SyntaxKind.FinallyKeyword) { - // Only report an error on the 'finally' block if we haven't on the 'catch' block. - if (node.catchBlock === undefined) { - error(Diagnostics.A_finally_block_must_be_preceded_by_a_try_statement); - } - - node.finallyBlock = parseTokenAndBlock(SyntaxKind.FinallyKeyword, SyntaxKind.FinallyBlock); - } - - return finishNode(node); - } - function parseTokenAndBlock(token: SyntaxKind, kind: SyntaxKind): Block { var pos = getNodePos(); parseExpected(token); @@ -2733,10 +2704,10 @@ module ts { case SyntaxKind.ThrowKeyword: return parseThrowStatement(); case SyntaxKind.TryKeyword: - return parseTryStatement(); + // Include the next two for error recovery. case SyntaxKind.CatchKeyword: case SyntaxKind.FinallyKeyword: - return parseCatchOrFinallyBlocksMissingTryStatement(); + return parseTryStatement(); case SyntaxKind.DebuggerKeyword: return parseDebuggerStatement(); default: diff --git a/tests/baselines/reference/invalidTryStatements2.errors.txt b/tests/baselines/reference/invalidTryStatements2.errors.txt index bedc9af1adc..a600210a605 100644 --- a/tests/baselines/reference/invalidTryStatements2.errors.txt +++ b/tests/baselines/reference/invalidTryStatements2.errors.txt @@ -8,7 +8,7 @@ catch(x) { } // error missing try ~~~~~ -!!! A 'catch' clause must be preceded by a 'try' statement. +!!! 'try' expected. finally{ } // potential error; can be absorbed by the 'catch' } @@ -16,10 +16,10 @@ function fn2() { finally { } // error missing try ~~~~~~~ -!!! A 'finally' block must be preceded by a 'try' statement. +!!! 'try' expected. catch (x) { } // error missing try ~~~~~ -!!! A 'catch' clause must be preceded by a 'try' statement. +!!! 'try' expected. // no error try { @@ -30,12 +30,12 @@ // error missing try finally { ~~~~~~~ -!!! A 'finally' block must be preceded by a 'try' statement. +!!! 'try' expected. } // error missing try catch (x) { ~~~~~ -!!! A 'catch' clause must be preceded by a 'try' statement. +!!! 'try' expected. } } \ No newline at end of file