Issue/34870 (#35586)

* Add new error message when missing brace

* Add test for missing close brace

* Update other tests which were affected
This commit is contained in:
Toxyxer 2019-12-10 01:31:23 +01:00 committed by Daniel Rosenwasser
parent 64a886700f
commit f8cacf97e1
12 changed files with 95 additions and 5 deletions

View file

@ -15,6 +15,10 @@
"category": "Error",
"code": 1006
},
"The parser expected to find a '}' to match the '{' token here.": {
"category": "Error",
"code": 1007
},
"Trailing comma not allowed.": {
"category": "Error",
"code": 1009

View file

@ -5059,13 +5059,22 @@ namespace ts {
// STATEMENTS
function parseBlock(ignoreMissingOpenBrace: boolean, diagnosticMessage?: DiagnosticMessage): Block {
const node = <Block>createNode(SyntaxKind.Block);
const openBracePosition = scanner.getTokenPos();
if (parseExpected(SyntaxKind.OpenBraceToken, diagnosticMessage) || ignoreMissingOpenBrace) {
if (scanner.hasPrecedingLineBreak()) {
node.multiLine = true;
}
node.statements = parseList(ParsingContext.BlockStatements, parseStatement);
parseExpected(SyntaxKind.CloseBraceToken);
if (!parseExpected(SyntaxKind.CloseBraceToken)) {
const lastError = lastOrUndefined(parseDiagnostics);
if (lastError && lastError.code === Diagnostics._0_expected.code) {
addRelatedInfo(
lastError,
createFileDiagnostic(sourceFile, openBracePosition, 1, Diagnostics.The_parser_expected_to_find_a_to_match_the_token_here)
);
}
}
}
else {
node.statements = createMissingList<Statement>();

View file

@ -15,4 +15,6 @@ tests/cases/compiler/errorRecoveryWithDotFollowedByNamespaceKeyword.ts(9,2): err
export function baz() { }
}
!!! error TS1005: '}' expected.
!!! error TS1005: '}' expected.
!!! related TS1007 tests/cases/compiler/errorRecoveryWithDotFollowedByNamespaceKeyword.ts:3:19: The parser expected to find a '}' to match the '{' token here.
!!! related TS1007 tests/cases/compiler/errorRecoveryWithDotFollowedByNamespaceKeyword.ts:2:20: The parser expected to find a '}' to match the '{' token here.

View file

@ -6,4 +6,5 @@ tests/cases/compiler/exportInFunction.ts(3,1): error TS1005: '}' expected.
export = 0;
!!! error TS1005: '}' expected.
!!! error TS1005: '}' expected.
!!! related TS1007 tests/cases/compiler/exportInFunction.ts:1:14: The parser expected to find a '}' to match the '{' token here.

View file

@ -0,0 +1,16 @@
tests/cases/compiler/missingCloseBrace.ts(9,1): error TS1005: '}' expected.
==== tests/cases/compiler/missingCloseBrace.ts (1 errors) ====
function base_init() {
{
}
function me() {
}
!!! error TS1005: '}' expected.
!!! related TS1007 tests/cases/compiler/missingCloseBrace.ts:1:22: The parser expected to find a '}' to match the '{' token here.

View file

@ -0,0 +1,18 @@
//// [missingCloseBrace.ts]
function base_init() {
{
}
function me() {
}
//// [missingCloseBrace.js]
function base_init() {
{
}
function me() {
}
}

View file

@ -0,0 +1,12 @@
=== tests/cases/compiler/missingCloseBrace.ts ===
function base_init() {
>base_init : Symbol(base_init, Decl(missingCloseBrace.ts, 0, 0))
{
}
function me() {
>me : Symbol(me, Decl(missingCloseBrace.ts, 3, 5))
}

View file

@ -0,0 +1,12 @@
=== tests/cases/compiler/missingCloseBrace.ts ===
function base_init() {
>base_init : () => void
{
}
function me() {
>me : () => void
}

View file

@ -15,4 +15,5 @@ tests/cases/conformance/parser/ecmascript5/ErrorRecovery/SwitchStatements/parser
!!! error TS1130: 'case' or 'default' expected.
}
!!! error TS1005: '}' expected.
!!! error TS1005: '}' expected.
!!! related TS1007 tests/cases/conformance/parser/ecmascript5/ErrorRecovery/SwitchStatements/parserErrorRecovery_SwitchStatement2.ts:2:17: The parser expected to find a '}' to match the '{' token here.

View file

@ -20,4 +20,5 @@ tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserFuzz1.ts(2,15): e
~~~~~~
!!! error TS1005: ';' expected.
!!! error TS1005: '{' expected.
!!! error TS1005: '{' expected.
!!! related TS1007 tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserFuzz1.ts:1:9: The parser expected to find a '}' to match the '{' token here.

View file

@ -3,11 +3,17 @@
2
  
tests/cases/compiler/index.ts:1:11
1 if (true) {
   ~
The parser expected to find a '}' to match the '{' token here.
==== tests/cases/compiler/index.ts (1 errors) ====
if (true) {
!!! error TS1005: '}' expected.
!!! related TS1007 tests/cases/compiler/index.ts:1:11: The parser expected to find a '}' to match the '{' token here.
Found 1 error.

View file

@ -0,0 +1,8 @@
function base_init() {
{
}
function me() {
}