Skip to content

Commit dec8261

Browse files
author
Jesse Trinity
authored
Revert #43460 and #40884 (#44175) (#44177)
* Revert "Only issue matching token errors on non-dupe locations (#43460)" This reverts commit 76a2ae3. * Revert "Adding Diagnostic message for missing ']' and ')' in Array literal and conditional statements (#40884)" This reverts commit 555ef73. * re-add clobbered merge lines
1 parent 22c3c24 commit dec8261

File tree

53 files changed

+336
-255
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+336
-255
lines changed

src/compiler/diagnosticMessages.json

+1-1
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

+35-37
Original file line numberDiff line numberDiff line change
@@ -1336,27 +1336,24 @@ namespace ts {
13361336
return inContext(NodeFlags.AwaitContext);
13371337
}
13381338

1339-
function parseErrorAtCurrentToken(message: DiagnosticMessage, arg0?: any): DiagnosticWithDetachedLocation | undefined {
1340-
return parseErrorAt(scanner.getTokenPos(), scanner.getTextPos(), message, arg0);
1339+
function parseErrorAtCurrentToken(message: DiagnosticMessage, arg0?: any): void {
1340+
parseErrorAt(scanner.getTokenPos(), scanner.getTextPos(), message, arg0);
13411341
}
13421342

1343-
function parseErrorAtPosition(start: number, length: number, message: DiagnosticMessage, arg0?: any): DiagnosticWithDetachedLocation | undefined {
1343+
function parseErrorAtPosition(start: number, length: number, message: DiagnosticMessage, arg0?: any): void {
13441344
// Don't report another error if it would just be at the same position as the last error.
13451345
const lastError = lastOrUndefined(parseDiagnostics);
1346-
let result: DiagnosticWithDetachedLocation | undefined;
13471346
if (!lastError || start !== lastError.start) {
1348-
result = createDetachedDiagnostic(fileName, start, length, message, arg0);
1349-
parseDiagnostics.push(result);
1347+
parseDiagnostics.push(createDetachedDiagnostic(fileName, start, length, message, arg0));
13501348
}
13511349

13521350
// Mark that we've encountered an error. We'll set an appropriate bit on the next
13531351
// node we finish so that it can't be reused incrementally.
13541352
parseErrorBeforeNextFinishedNode = true;
1355-
return result;
13561353
}
13571354

1358-
function parseErrorAt(start: number, end: number, message: DiagnosticMessage, arg0?: any): DiagnosticWithDetachedLocation | undefined {
1359-
return parseErrorAtPosition(start, end - start, message, arg0);
1355+
function parseErrorAt(start: number, end: number, message: DiagnosticMessage, arg0?: any): void {
1356+
parseErrorAtPosition(start, end - start, message, arg0);
13601357
}
13611358

13621359
function parseErrorAtRange(range: TextRange, message: DiagnosticMessage, arg0?: any): void {
@@ -1546,20 +1543,6 @@ namespace ts {
15461543
return false;
15471544
}
15481545

1549-
function parseExpectedMatchingBrackets(openKind: SyntaxKind, closeKind: SyntaxKind, openPosition: number) {
1550-
if (token() === closeKind) {
1551-
nextToken();
1552-
return;
1553-
}
1554-
const lastError = parseErrorAtCurrentToken(Diagnostics._0_expected, tokenToString(closeKind));
1555-
if (lastError) {
1556-
addRelatedInfo(
1557-
lastError,
1558-
createDetachedDiagnostic(fileName, openPosition, 1, Diagnostics.The_parser_expected_to_find_a_1_to_match_the_0_token_here, tokenToString(openKind), tokenToString(closeKind))
1559-
);
1560-
}
1561-
}
1562-
15631546
function parseOptional(t: SyntaxKind): boolean {
15641547
if (token() === t) {
15651548
nextToken();
@@ -5450,11 +5433,10 @@ namespace ts {
54505433

54515434
function parseArrayLiteralExpression(): ArrayLiteralExpression {
54525435
const pos = getNodePos();
5453-
const openBracketPosition = scanner.getTokenPos();
54545436
parseExpected(SyntaxKind.OpenBracketToken);
54555437
const multiLine = scanner.hasPrecedingLineBreak();
54565438
const elements = parseDelimitedList(ParsingContext.ArrayLiteralMembers, parseArgumentOrArrayLiteralElement);
5457-
parseExpectedMatchingBrackets(SyntaxKind.OpenBracketToken, SyntaxKind.CloseBracketToken, openBracketPosition);
5439+
parseExpected(SyntaxKind.CloseBracketToken);
54585440
return finishNode(factory.createArrayLiteralExpression(elements, multiLine), pos);
54595441
}
54605442

@@ -5523,7 +5505,15 @@ namespace ts {
55235505
parseExpected(SyntaxKind.OpenBraceToken);
55245506
const multiLine = scanner.hasPrecedingLineBreak();
55255507
const properties = parseDelimitedList(ParsingContext.ObjectLiteralMembers, parseObjectLiteralElement, /*considerSemicolonAsDelimiter*/ true);
5526-
parseExpectedMatchingBrackets(SyntaxKind.OpenBraceToken, SyntaxKind.CloseBraceToken, openBracePosition);
5508+
if (!parseExpected(SyntaxKind.CloseBraceToken)) {
5509+
const lastError = lastOrUndefined(parseDiagnostics);
5510+
if (lastError && lastError.code === Diagnostics._0_expected.code) {
5511+
addRelatedInfo(
5512+
lastError,
5513+
createDetachedDiagnostic(fileName, openBracePosition, 1, Diagnostics.The_parser_expected_to_find_a_to_match_the_token_here)
5514+
);
5515+
}
5516+
}
55275517
return finishNode(factory.createObjectLiteralExpression(properties, multiLine), pos);
55285518
}
55295519

@@ -5609,7 +5599,15 @@ namespace ts {
56095599
if (parseExpected(SyntaxKind.OpenBraceToken, diagnosticMessage) || ignoreMissingOpenBrace) {
56105600
const multiLine = scanner.hasPrecedingLineBreak();
56115601
const statements = parseList(ParsingContext.BlockStatements, parseStatement);
5612-
parseExpectedMatchingBrackets(SyntaxKind.OpenBraceToken, SyntaxKind.CloseBraceToken, openBracePosition);
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+
}
5610+
}
56135611
const result = withJSDoc(finishNode(factory.createBlock(statements, multiLine), pos), hasJSDoc);
56145612
if (token() === SyntaxKind.EqualsToken) {
56155613
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);
@@ -5665,10 +5663,9 @@ namespace ts {
56655663
const pos = getNodePos();
56665664
const hasJSDoc = hasPrecedingJSDocComment();
56675665
parseExpected(SyntaxKind.IfKeyword);
5668-
const openParenPosition = scanner.getTokenPos();
56695666
parseExpected(SyntaxKind.OpenParenToken);
56705667
const expression = allowInAnd(parseExpression);
5671-
parseExpectedMatchingBrackets(SyntaxKind.OpenParenToken, SyntaxKind.CloseParenToken, openParenPosition);
5668+
parseExpected(SyntaxKind.CloseParenToken);
56725669
const thenStatement = parseStatement();
56735670
const elseStatement = parseOptional(SyntaxKind.ElseKeyword) ? parseStatement() : undefined;
56745671
return withJSDoc(finishNode(factory.createIfStatement(expression, thenStatement, elseStatement), pos), hasJSDoc);
@@ -5680,10 +5677,9 @@ namespace ts {
56805677
parseExpected(SyntaxKind.DoKeyword);
56815678
const statement = parseStatement();
56825679
parseExpected(SyntaxKind.WhileKeyword);
5683-
const openParenPosition = scanner.getTokenPos();
56845680
parseExpected(SyntaxKind.OpenParenToken);
56855681
const expression = allowInAnd(parseExpression);
5686-
parseExpectedMatchingBrackets(SyntaxKind.OpenParenToken, SyntaxKind.CloseParenToken, openParenPosition);
5682+
parseExpected(SyntaxKind.CloseParenToken);
56875683

56885684
// From: https://mail.mozilla.org/pipermail/es-discuss/2011-August/016188.html
56895685
// 157 min --- All allen at wirfs-brock.com CONF --- "do{;}while(false)false" prohibited in
@@ -5697,10 +5693,9 @@ namespace ts {
56975693
const pos = getNodePos();
56985694
const hasJSDoc = hasPrecedingJSDocComment();
56995695
parseExpected(SyntaxKind.WhileKeyword);
5700-
const openParenPosition = scanner.getTokenPos();
57015696
parseExpected(SyntaxKind.OpenParenToken);
57025697
const expression = allowInAnd(parseExpression);
5703-
parseExpectedMatchingBrackets(SyntaxKind.OpenParenToken, SyntaxKind.CloseParenToken, openParenPosition);
5698+
parseExpected(SyntaxKind.CloseParenToken);
57045699
const statement = parseStatement();
57055700
return withJSDoc(finishNode(factory.createWhileStatement(expression, statement), pos), hasJSDoc);
57065701
}
@@ -5776,10 +5771,9 @@ namespace ts {
57765771
const pos = getNodePos();
57775772
const hasJSDoc = hasPrecedingJSDocComment();
57785773
parseExpected(SyntaxKind.WithKeyword);
5779-
const openParenPosition = scanner.getTokenPos();
57805774
parseExpected(SyntaxKind.OpenParenToken);
57815775
const expression = allowInAnd(parseExpression);
5782-
parseExpectedMatchingBrackets(SyntaxKind.OpenParenToken, SyntaxKind.CloseParenToken, openParenPosition);
5776+
parseExpected(SyntaxKind.CloseParenToken);
57835777
const statement = doInsideOfContext(NodeFlags.InWithStatement, parseStatement);
57845778
return withJSDoc(finishNode(factory.createWithStatement(expression, statement), pos), hasJSDoc);
57855779
}
@@ -8010,9 +8004,13 @@ namespace ts {
80108004
hasChildren = true;
80118005
if (child.kind === SyntaxKind.JSDocTypeTag) {
80128006
if (childTypeTag) {
8013-
const lastError = parseErrorAtCurrentToken(Diagnostics.A_JSDoc_typedef_comment_may_not_contain_multiple_type_tags);
8007+
parseErrorAtCurrentToken(Diagnostics.A_JSDoc_typedef_comment_may_not_contain_multiple_type_tags);
8008+
const lastError = lastOrUndefined(parseDiagnostics);
80148009
if (lastError) {
8015-
addRelatedInfo(lastError, createDetachedDiagnostic(fileName, 0, 0, Diagnostics.The_tag_was_first_specified_here));
8010+
addRelatedInfo(
8011+
lastError,
8012+
createDetachedDiagnostic(fileName, 0, 0, Diagnostics.The_tag_was_first_specified_here)
8013+
);
80168014
}
80178015
break;
80188016
}

tests/baselines/reference/constructorWithIncompleteTypeAnnotation.errors.txt

-1
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

tests/baselines/reference/errorRecoveryWithDotFollowedByNamespaceKeyword.errors.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ tests/cases/compiler/errorRecoveryWithDotFollowedByNamespaceKeyword.ts(9,2): err
1616
}
1717

1818
!!! error TS1005: '}' expected.
19-
!!! related TS1007 tests/cases/compiler/errorRecoveryWithDotFollowedByNamespaceKeyword.ts:3:19: The parser expected to find a '}' to match the '{' token here.
19+
!!! related TS1007 tests/cases/compiler/errorRecoveryWithDotFollowedByNamespaceKeyword.ts:3:19: The parser expected to find a '}' to match the '{' token here.
20+
!!! related TS1007 tests/cases/compiler/errorRecoveryWithDotFollowedByNamespaceKeyword.ts:2:20: The parser expected to find a '}' to match the '{' token here.

tests/baselines/reference/missingCloseBracketInArray.errors.txt

-8
This file was deleted.

tests/baselines/reference/missingCloseBracketInArray.js

-5
This file was deleted.

tests/baselines/reference/missingCloseBracketInArray.symbols

-5
This file was deleted.

tests/baselines/reference/missingCloseBracketInArray.types

-11
This file was deleted.

tests/baselines/reference/missingCloseParenStatements.errors.txt

-32
This file was deleted.

tests/baselines/reference/missingCloseParenStatements.js

-28
This file was deleted.

tests/baselines/reference/missingCloseParenStatements.symbols

-37
This file was deleted.

tests/baselines/reference/missingCloseParenStatements.types

-67
This file was deleted.

0 commit comments

Comments
 (0)