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:
parent
64a886700f
commit
f8cacf97e1
|
@ -15,6 +15,10 @@
|
||||||
"category": "Error",
|
"category": "Error",
|
||||||
"code": 1006
|
"code": 1006
|
||||||
},
|
},
|
||||||
|
"The parser expected to find a '}' to match the '{' token here.": {
|
||||||
|
"category": "Error",
|
||||||
|
"code": 1007
|
||||||
|
},
|
||||||
"Trailing comma not allowed.": {
|
"Trailing comma not allowed.": {
|
||||||
"category": "Error",
|
"category": "Error",
|
||||||
"code": 1009
|
"code": 1009
|
||||||
|
|
|
@ -5059,13 +5059,22 @@ namespace ts {
|
||||||
// STATEMENTS
|
// STATEMENTS
|
||||||
function parseBlock(ignoreMissingOpenBrace: boolean, diagnosticMessage?: DiagnosticMessage): Block {
|
function parseBlock(ignoreMissingOpenBrace: boolean, diagnosticMessage?: DiagnosticMessage): Block {
|
||||||
const node = <Block>createNode(SyntaxKind.Block);
|
const node = <Block>createNode(SyntaxKind.Block);
|
||||||
|
const openBracePosition = scanner.getTokenPos();
|
||||||
if (parseExpected(SyntaxKind.OpenBraceToken, diagnosticMessage) || ignoreMissingOpenBrace) {
|
if (parseExpected(SyntaxKind.OpenBraceToken, diagnosticMessage) || ignoreMissingOpenBrace) {
|
||||||
if (scanner.hasPrecedingLineBreak()) {
|
if (scanner.hasPrecedingLineBreak()) {
|
||||||
node.multiLine = true;
|
node.multiLine = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
node.statements = parseList(ParsingContext.BlockStatements, parseStatement);
|
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 {
|
else {
|
||||||
node.statements = createMissingList<Statement>();
|
node.statements = createMissingList<Statement>();
|
||||||
|
|
|
@ -16,3 +16,5 @@ tests/cases/compiler/errorRecoveryWithDotFollowedByNamespaceKeyword.ts(9,2): err
|
||||||
}
|
}
|
||||||
|
|
||||||
!!! 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.
|
|
@ -7,3 +7,4 @@ tests/cases/compiler/exportInFunction.ts(3,1): error TS1005: '}' expected.
|
||||||
|
|
||||||
|
|
||||||
!!! 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.
|
16
tests/baselines/reference/missingCloseBrace.errors.txt
Normal file
16
tests/baselines/reference/missingCloseBrace.errors.txt
Normal 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.
|
18
tests/baselines/reference/missingCloseBrace.js
Normal file
18
tests/baselines/reference/missingCloseBrace.js
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
//// [missingCloseBrace.ts]
|
||||||
|
function base_init() {
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function me() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//// [missingCloseBrace.js]
|
||||||
|
function base_init() {
|
||||||
|
{
|
||||||
|
}
|
||||||
|
function me() {
|
||||||
|
}
|
||||||
|
}
|
12
tests/baselines/reference/missingCloseBrace.symbols
Normal file
12
tests/baselines/reference/missingCloseBrace.symbols
Normal 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))
|
||||||
|
|
||||||
|
}
|
||||||
|
|
12
tests/baselines/reference/missingCloseBrace.types
Normal file
12
tests/baselines/reference/missingCloseBrace.types
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
=== tests/cases/compiler/missingCloseBrace.ts ===
|
||||||
|
function base_init() {
|
||||||
|
>base_init : () => void
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function me() {
|
||||||
|
>me : () => void
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -16,3 +16,4 @@ tests/cases/conformance/parser/ecmascript5/ErrorRecovery/SwitchStatements/parser
|
||||||
}
|
}
|
||||||
|
|
||||||
!!! 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.
|
|
@ -21,3 +21,4 @@ tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserFuzz1.ts(2,15): e
|
||||||
!!! error TS1005: ';' expected.
|
!!! 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.
|
|
@ -3,11 +3,17 @@
|
||||||
[7m2[0m
|
[7m2[0m
|
||||||
[7m [0m [91m[0m
|
[7m [0m [91m[0m
|
||||||
|
|
||||||
|
[96mtests/cases/compiler/index.ts[0m:[93m1[0m:[93m11[0m
|
||||||
|
[7m1[0m if (true) {
|
||||||
|
[7m [0m [96m ~[0m
|
||||||
|
The parser expected to find a '}' to match the '{' token here.
|
||||||
|
|
||||||
|
|
||||||
==== tests/cases/compiler/index.ts (1 errors) ====
|
==== tests/cases/compiler/index.ts (1 errors) ====
|
||||||
if (true) {
|
if (true) {
|
||||||
|
|
||||||
|
|
||||||
!!! error TS1005: '}' expected.
|
!!! 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.
|
Found 1 error.
|
||||||
|
|
||||||
|
|
8
tests/cases/compiler/missingCloseBrace.ts
Normal file
8
tests/cases/compiler/missingCloseBrace.ts
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
function base_init() {
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function me() {
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue