mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-27 23:58:38 -06:00
Simplified error recovery by just using 'parseTryStatement'.
This commit is contained in:
parent
0939f77d77
commit
79735b4431
@ -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}'." },
|
||||
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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 = <TryStatement>createNode(SyntaxKind.TryStatement);
|
||||
node.tryBlock = <Block>createNode(SyntaxKind.Block);
|
||||
node.tryBlock.statements = createMissingList<Statement>();
|
||||
|
||||
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:
|
||||
|
||||
@ -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.
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user