Skip to content

Commit fbb2f79

Browse files
committed
Revert "Adding Diagnostic message for missing ']' and ')' in Array literal and conditional statements (#40884)"
This reverts commit 555ef73.
1 parent bcef31c commit fbb2f79

20 files changed

+17
-251
lines changed

src/compiler/diagnosticMessages.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"category": "Error",
1616
"code": 1006
1717
},
18-
"The parser expected to find a '{1}' to match the '{0}' token here.": {
18+
"The parser expected to find a '}' to match the '{' token here.": {
1919
"category": "Error",
2020
"code": 1007
2121
},

src/compiler/parser.ts

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,20 +1543,6 @@ namespace ts {
15431543
return false;
15441544
}
15451545

1546-
function parseExpectedMatchingBrackets(openKind: SyntaxKind, closeKind: SyntaxKind, openPosition: number) {
1547-
if (!parseExpected(closeKind)) {
1548-
const lastError = lastOrUndefined(parseDiagnostics);
1549-
if (lastError && lastError.code === Diagnostics._0_expected.code) {
1550-
addRelatedInfo(
1551-
lastError,
1552-
createDetachedDiagnostic(fileName, openPosition, 1, Diagnostics.The_parser_expected_to_find_a_1_to_match_the_0_token_here, tokenToString(openKind), tokenToString(closeKind))
1553-
);
1554-
}
1555-
return false;
1556-
}
1557-
return true;
1558-
}
1559-
15601546
function parseOptional(t: SyntaxKind): boolean {
15611547
if (token() === t) {
15621548
nextToken();
@@ -5447,11 +5433,10 @@ namespace ts {
54475433

54485434
function parseArrayLiteralExpression(): ArrayLiteralExpression {
54495435
const pos = getNodePos();
5450-
const openBracketPosition = scanner.getTokenPos();
54515436
parseExpected(SyntaxKind.OpenBracketToken);
54525437
const multiLine = scanner.hasPrecedingLineBreak();
54535438
const elements = parseDelimitedList(ParsingContext.ArrayLiteralMembers, parseArgumentOrArrayLiteralElement);
5454-
parseExpectedMatchingBrackets(SyntaxKind.OpenBracketToken, SyntaxKind.CloseBracketToken, openBracketPosition);
5439+
parseExpected(SyntaxKind.CloseBracketToken);
54555440
return finishNode(factory.createArrayLiteralExpression(elements, multiLine), pos);
54565441
}
54575442

@@ -5525,7 +5510,7 @@ namespace ts {
55255510
if (lastError && lastError.code === Diagnostics._0_expected.code) {
55265511
addRelatedInfo(
55275512
lastError,
5528-
createDetachedDiagnostic(fileName, openBracePosition, 1, Diagnostics.The_parser_expected_to_find_a_1_to_match_the_0_token_here, tokenToString(SyntaxKind.OpenBraceToken), tokenToString(SyntaxKind.CloseBraceToken))
5513+
createDetachedDiagnostic(fileName, openBracePosition, 1, Diagnostics.The_parser_expected_to_find_a_to_match_the_token_here)
55295514
);
55305515
}
55315516
}
@@ -5614,14 +5599,16 @@ namespace ts {
56145599
if (parseExpected(SyntaxKind.OpenBraceToken, diagnosticMessage) || ignoreMissingOpenBrace) {
56155600
const multiLine = scanner.hasPrecedingLineBreak();
56165601
const statements = parseList(ParsingContext.BlockStatements, parseStatement);
5617-
parseExpectedMatchingBrackets(SyntaxKind.OpenBraceToken, SyntaxKind.CloseBraceToken, openBracePosition);
5618-
const result = withJSDoc(finishNode(factory.createBlock(statements, multiLine), pos), hasJSDoc);
5619-
if (token() === SyntaxKind.EqualsToken) {
5620-
parseErrorAtCurrentToken(Diagnostics.Declaration_or_statement_expected_This_follows_a_block_of_statements_so_if_you_intended_to_write_a_destructuring_assignment_you_might_need_to_wrap_the_the_whole_assignment_in_parentheses);
5621-
nextToken();
5602+
if (!parseExpected(SyntaxKind.CloseBraceToken)) {
5603+
const lastError = lastOrUndefined(parseDiagnostics);
5604+
if (lastError && lastError.code === Diagnostics._0_expected.code) {
5605+
addRelatedInfo(
5606+
lastError,
5607+
createDetachedDiagnostic(fileName, openBracePosition, 1, Diagnostics.The_parser_expected_to_find_a_to_match_the_token_here)
5608+
);
5609+
}
56225610
}
5623-
5624-
return result;
5611+
return finishNode(factory.createBlock(statements, multiLine), pos);
56255612
}
56265613
else {
56275614
const statements = createMissingList<Statement>();
@@ -5670,10 +5657,9 @@ namespace ts {
56705657
const pos = getNodePos();
56715658
const hasJSDoc = hasPrecedingJSDocComment();
56725659
parseExpected(SyntaxKind.IfKeyword);
5673-
const openParenPosition = scanner.getTokenPos();
56745660
parseExpected(SyntaxKind.OpenParenToken);
56755661
const expression = allowInAnd(parseExpression);
5676-
parseExpectedMatchingBrackets(SyntaxKind.OpenParenToken, SyntaxKind.CloseParenToken, openParenPosition);
5662+
parseExpected(SyntaxKind.CloseParenToken);
56775663
const thenStatement = parseStatement();
56785664
const elseStatement = parseOptional(SyntaxKind.ElseKeyword) ? parseStatement() : undefined;
56795665
return withJSDoc(finishNode(factory.createIfStatement(expression, thenStatement, elseStatement), pos), hasJSDoc);
@@ -5685,10 +5671,9 @@ namespace ts {
56855671
parseExpected(SyntaxKind.DoKeyword);
56865672
const statement = parseStatement();
56875673
parseExpected(SyntaxKind.WhileKeyword);
5688-
const openParenPosition = scanner.getTokenPos();
56895674
parseExpected(SyntaxKind.OpenParenToken);
56905675
const expression = allowInAnd(parseExpression);
5691-
parseExpectedMatchingBrackets(SyntaxKind.OpenParenToken, SyntaxKind.CloseParenToken, openParenPosition);
5676+
parseExpected(SyntaxKind.CloseParenToken);
56925677

56935678
// From: https://mail.mozilla.org/pipermail/es-discuss/2011-August/016188.html
56945679
// 157 min --- All allen at wirfs-brock.com CONF --- "do{;}while(false)false" prohibited in
@@ -5702,10 +5687,9 @@ namespace ts {
57025687
const pos = getNodePos();
57035688
const hasJSDoc = hasPrecedingJSDocComment();
57045689
parseExpected(SyntaxKind.WhileKeyword);
5705-
const openParenPosition = scanner.getTokenPos();
57065690
parseExpected(SyntaxKind.OpenParenToken);
57075691
const expression = allowInAnd(parseExpression);
5708-
parseExpectedMatchingBrackets(SyntaxKind.OpenParenToken, SyntaxKind.CloseParenToken, openParenPosition);
5692+
parseExpected(SyntaxKind.CloseParenToken);
57095693
const statement = parseStatement();
57105694
return withJSDoc(finishNode(factory.createWhileStatement(expression, statement), pos), hasJSDoc);
57115695
}
@@ -5781,10 +5765,9 @@ namespace ts {
57815765
const pos = getNodePos();
57825766
const hasJSDoc = hasPrecedingJSDocComment();
57835767
parseExpected(SyntaxKind.WithKeyword);
5784-
const openParenPosition = scanner.getTokenPos();
57855768
parseExpected(SyntaxKind.OpenParenToken);
57865769
const expression = allowInAnd(parseExpression);
5787-
parseExpectedMatchingBrackets(SyntaxKind.OpenParenToken, SyntaxKind.CloseParenToken, openParenPosition);
5770+
parseExpected(SyntaxKind.CloseParenToken);
57885771
const statement = doInsideOfContext(NodeFlags.InWithStatement, parseStatement);
57895772
return withJSDoc(finishNode(factory.createWithStatement(expression, statement), pos), hasJSDoc);
57905773
}

tests/baselines/reference/constructorWithIncompleteTypeAnnotation.errors.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(261,1): error TS
121121
if (retValue != 0 ^= {
122122
~~
123123
!!! error TS1005: ')' expected.
124-
!!! related TS1007 tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts:22:20: The parser expected to find a ')' to match the '(' token here.
125124
~
126125

127126

@@ -505,7 +504,6 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(261,1): error TS
505504
!!! error TS1135: Argument expression expected.
506505
~
507506
!!! error TS1005: '(' expected.
508-
!!! related TS1007 tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts:257:33: The parser expected to find a ')' to match the '(' token here.
509507
~~~~~~
510508
!!! error TS2693: 'string' only refers to a type, but is being used as a value here.
511509
~~~

tests/baselines/reference/destructuringParameterDeclaration2.errors.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(
3939
!!! error TS2322: Type 'string' is not assignable to type 'number'.
4040
~
4141
!!! error TS1005: ',' expected.
42-
!!! related TS1007 tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts:7:4: The parser expected to find a ']' to match the '[' token here.
4342
a0([1, 2, [["world"]], "string"]); // Error
4443
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4544
!!! error TS2345: Argument of type '[number, number, string[][], string]' is not assignable to parameter of type '[number, number, string[][]]'.

tests/baselines/reference/missingCloseBracketInArray.errors.txt

Lines changed: 0 additions & 8 deletions
This file was deleted.

tests/baselines/reference/missingCloseBracketInArray.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

tests/baselines/reference/missingCloseBracketInArray.symbols

Lines changed: 0 additions & 5 deletions
This file was deleted.

tests/baselines/reference/missingCloseBracketInArray.types

Lines changed: 0 additions & 11 deletions
This file was deleted.

tests/baselines/reference/missingCloseParenStatements.errors.txt

Lines changed: 0 additions & 32 deletions
This file was deleted.

tests/baselines/reference/missingCloseParenStatements.js

Lines changed: 0 additions & 28 deletions
This file was deleted.

tests/baselines/reference/missingCloseParenStatements.symbols

Lines changed: 0 additions & 37 deletions
This file was deleted.

tests/baselines/reference/missingCloseParenStatements.types

Lines changed: 0 additions & 67 deletions
This file was deleted.

tests/baselines/reference/parserErrorRecoveryArrayLiteralExpression3.errors.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArrayLiteralExpressions
88
var texCoords = [2, 2, 0.5000001192092895, 0.8749999 ; 403953552, 0.5000001192092895, 0.8749999403953552];
99
~
1010
!!! error TS1005: ',' expected.
11-
!!! related TS1007 tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArrayLiteralExpressions/parserErrorRecoveryArrayLiteralExpression3.ts:1:17: The parser expected to find a ']' to match the '[' token here.
1211
~~~~~~~~~
1312
!!! error TS2695: Left side of comma operator is unused and has no side effects.
1413
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

tests/baselines/reference/parserErrorRecoveryIfStatement2.errors.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ tests/cases/conformance/parser/ecmascript5/ErrorRecovery/IfStatements/parserErro
1111
}
1212
~
1313
!!! error TS1005: ')' expected.
14-
!!! related TS1007 tests/cases/conformance/parser/ecmascript5/ErrorRecovery/IfStatements/parserErrorRecoveryIfStatement2.ts:3:8: The parser expected to find a ')' to match the '(' token here.
1514
f2() {
1615
}
1716
f3() {

tests/baselines/reference/parserErrorRecoveryIfStatement3.errors.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ tests/cases/conformance/parser/ecmascript5/ErrorRecovery/IfStatements/parserErro
1111
}
1212
~
1313
!!! error TS1005: ')' expected.
14-
!!! related TS1007 tests/cases/conformance/parser/ecmascript5/ErrorRecovery/IfStatements/parserErrorRecoveryIfStatement3.ts:3:8: The parser expected to find a ')' to match the '(' token here.
1514
f2() {
1615
}
1716
f3() {

tests/baselines/reference/reservedWords2.errors.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ tests/cases/compiler/reservedWords2.ts(12,17): error TS1138: Parameter declarati
4545
!!! error TS2580: Cannot find name 'require'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`.
4646
~
4747
!!! error TS1005: ')' expected.
48-
!!! related TS1007 tests/cases/compiler/reservedWords2.ts:1:14: The parser expected to find a ')' to match the '(' token here.
4948
import * as while from "foo"
5049

5150
!!! error TS2300: Duplicate identifier '(Missing)'.
@@ -59,7 +58,6 @@ tests/cases/compiler/reservedWords2.ts(12,17): error TS1138: Parameter declarati
5958
!!! error TS2304: Cannot find name 'from'.
6059
~~~~~
6160
!!! error TS1005: ')' expected.
62-
!!! related TS1007 tests/cases/compiler/reservedWords2.ts:2:20: The parser expected to find a ')' to match the '(' token here.
6361

6462
var typeof = 10;
6563
~~~~~~
@@ -105,7 +103,6 @@ tests/cases/compiler/reservedWords2.ts(12,17): error TS1138: Parameter declarati
105103
!!! error TS1005: ';' expected.
106104
~
107105
!!! error TS1005: '(' expected.
108-
!!! related TS1007 tests/cases/compiler/reservedWords2.ts:9:18: The parser expected to find a ')' to match the '(' token here.
109106
~
110107
!!! error TS1128: Declaration or statement expected.
111108
enum void {}

0 commit comments

Comments
 (0)