Don't report an error directly when parsing a function body.

This commit is contained in:
Cyrus Najmabadi 2014-12-01 00:31:31 -08:00
parent 7eb4e742d1
commit f91996a80c
7 changed files with 16 additions and 20 deletions

View File

@ -106,7 +106,7 @@ module ts {
Type_argument_expected: { code: 1140, category: DiagnosticCategory.Error, key: "Type argument expected." },
String_literal_expected: { code: 1141, category: DiagnosticCategory.Error, key: "String literal expected." },
Line_break_not_permitted_here: { code: 1142, category: DiagnosticCategory.Error, key: "Line break not permitted here." },
Block_or_expected: { code: 1144, category: DiagnosticCategory.Error, key: "Block or ';' expected." },
or_expected: { code: 1144, category: DiagnosticCategory.Error, key: "'{' or ';' expected." },
Modifiers_not_permitted_on_index_signature_members: { code: 1145, category: DiagnosticCategory.Error, key: "Modifiers not permitted on index signature members." },
Declaration_expected: { code: 1146, category: DiagnosticCategory.Error, key: "Declaration expected." },
Import_declarations_in_an_internal_module_cannot_reference_an_external_module: { code: 1147, category: DiagnosticCategory.Error, key: "Import declarations in an internal module cannot reference an external module." },

View File

@ -415,7 +415,7 @@
"category": "Error",
"code": 1142
},
"Block or ';' expected.": {
"'{' or ';' expected.": {
"category": "Error",
"code": 1144
},

View File

@ -1226,7 +1226,7 @@ module ts {
return token === SyntaxKind.CloseBraceToken || token === SyntaxKind.EndOfFileToken || scanner.hasPrecedingLineBreak();
}
function parseSemicolon(): void {
function parseSemicolon(diagnosticMessage?: DiagnosticMessage): void {
if (canParseSemicolon()) {
if (token === SyntaxKind.SemicolonToken) {
// consume the semicolon if it was explicitly provided.
@ -1234,7 +1234,7 @@ module ts {
}
}
else {
parseExpected(SyntaxKind.SemicolonToken);
parseExpected(SyntaxKind.SemicolonToken, diagnosticMessage);
}
}
@ -3572,12 +3572,8 @@ module ts {
return parseFunctionBlock(isGenerator, /* ignoreMissingOpenBrace */ false);
}
if (canParseSemicolon()) {
parseSemicolon();
return undefined;
}
error(Diagnostics.Block_or_expected); // block or ';' expected
parseSemicolon(Diagnostics.or_expected);
return undefined;
}
// DECLARATIONS

View File

@ -1,4 +1,4 @@
tests/cases/compiler/dottedModuleName.ts(3,29): error TS1144: Block or ';' expected.
tests/cases/compiler/dottedModuleName.ts(3,29): error TS1144: '{' or ';' expected.
tests/cases/compiler/dottedModuleName.ts(3,18): error TS2391: Function implementation is missing or not immediately following the declaration.
tests/cases/compiler/dottedModuleName.ts(3,33): error TS2304: Cannot find name 'x'.
@ -8,7 +8,7 @@ tests/cases/compiler/dottedModuleName.ts(3,33): error TS2304: Cannot find name '
export module N {
export function f(x:number)=>2*x;
~~
!!! error TS1144: Block or ';' expected.
!!! error TS1144: '{' or ';' expected.
~
!!! error TS2391: Function implementation is missing or not immediately following the declaration.
~

View File

@ -2,11 +2,11 @@ tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWith
tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWithOptionalProperties2.ts(4,9): error TS1131: Property or signature expected.
tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWithOptionalProperties2.ts(8,8): error TS1005: ';' expected.
tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWithOptionalProperties2.ts(8,9): error TS1131: Property or signature expected.
tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWithOptionalProperties2.ts(12,8): error TS1144: Block or ';' expected.
tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWithOptionalProperties2.ts(12,8): error TS1144: '{' or ';' expected.
tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWithOptionalProperties2.ts(12,9): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected.
tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWithOptionalProperties2.ts(16,8): error TS1005: ';' expected.
tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWithOptionalProperties2.ts(16,9): error TS1131: Property or signature expected.
tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWithOptionalProperties2.ts(20,8): error TS1144: Block or ';' expected.
tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWithOptionalProperties2.ts(20,8): error TS1144: '{' or ';' expected.
tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWithOptionalProperties2.ts(20,9): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected.
tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWithOptionalProperties2.ts(25,8): error TS1005: '{' expected.
tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWithOptionalProperties2.ts(25,9): error TS1136: Property assignment expected.
@ -37,7 +37,7 @@ tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWith
class C {
x()?: number; // error
~
!!! error TS1144: Block or ';' expected.
!!! error TS1144: '{' or ';' expected.
~
!!! error TS1068: Unexpected token. A constructor, method, accessor, or property was expected.
~
@ -55,7 +55,7 @@ tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWith
class C2<T> {
x()?: T; // error
~
!!! error TS1144: Block or ';' expected.
!!! error TS1144: '{' or ';' expected.
~
!!! error TS1068: Unexpected token. A constructor, method, accessor, or property was expected.
~

View File

@ -1,10 +1,10 @@
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserErrantEqualsGreaterThanAfterFunction1.ts(1,14): error TS1144: Block or ';' expected.
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserErrantEqualsGreaterThanAfterFunction1.ts(1,14): error TS1144: '{' or ';' expected.
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserErrantEqualsGreaterThanAfterFunction1.ts(1,10): error TS2391: Function implementation is missing or not immediately following the declaration.
==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserErrantEqualsGreaterThanAfterFunction1.ts (2 errors) ====
function f() => 4;
~~
!!! error TS1144: Block or ';' expected.
!!! error TS1144: '{' or ';' expected.
~
!!! error TS2391: Function implementation is missing or not immediately following the declaration.

View File

@ -1,4 +1,4 @@
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserErrantEqualsGreaterThanAfterFunction2.ts(1,18): error TS1144: Block or ';' expected.
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserErrantEqualsGreaterThanAfterFunction2.ts(1,18): error TS1144: '{' or ';' expected.
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserErrantEqualsGreaterThanAfterFunction2.ts(1,10): error TS2391: Function implementation is missing or not immediately following the declaration.
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserErrantEqualsGreaterThanAfterFunction2.ts(1,15): error TS2304: Cannot find name 'A'.
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserErrantEqualsGreaterThanAfterFunction2.ts(1,21): error TS2304: Cannot find name 'p'.
@ -7,7 +7,7 @@ tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserErrantEqualsGreat
==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserErrantEqualsGreaterThanAfterFunction2.ts (4 errors) ====
function f(p: A) => p;
~~
!!! error TS1144: Block or ';' expected.
!!! error TS1144: '{' or ';' expected.
~
!!! error TS2391: Function implementation is missing or not immediately following the declaration.
~