Skip to content

Commit bcef31c

Browse files
committed
Revert "Only issue matching token errors on non-dupe locations (#43460)"
This reverts commit 76a2ae3.
1 parent e67da8a commit bcef31c

File tree

40 files changed

+334
-25
lines changed

40 files changed

+334
-25
lines changed

src/compiler/parser.ts

Lines changed: 31 additions & 22 deletions
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 {
@@ -1547,17 +1544,17 @@ namespace ts {
15471544
}
15481545

15491546
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-
);
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;
15601556
}
1557+
return true;
15611558
}
15621559

15631560
function parseOptional(t: SyntaxKind): boolean {
@@ -5523,7 +5520,15 @@ namespace ts {
55235520
parseExpected(SyntaxKind.OpenBraceToken);
55245521
const multiLine = scanner.hasPrecedingLineBreak();
55255522
const properties = parseDelimitedList(ParsingContext.ObjectLiteralMembers, parseObjectLiteralElement, /*considerSemicolonAsDelimiter*/ true);
5526-
parseExpectedMatchingBrackets(SyntaxKind.OpenBraceToken, SyntaxKind.CloseBraceToken, openBracePosition);
5523+
if (!parseExpected(SyntaxKind.CloseBraceToken)) {
5524+
const lastError = lastOrUndefined(parseDiagnostics);
5525+
if (lastError && lastError.code === Diagnostics._0_expected.code) {
5526+
addRelatedInfo(
5527+
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))
5529+
);
5530+
}
5531+
}
55275532
return finishNode(factory.createObjectLiteralExpression(properties, multiLine), pos);
55285533
}
55295534

@@ -8010,9 +8015,13 @@ namespace ts {
80108015
hasChildren = true;
80118016
if (child.kind === SyntaxKind.JSDocTypeTag) {
80128017
if (childTypeTag) {
8013-
const lastError = parseErrorAtCurrentToken(Diagnostics.A_JSDoc_typedef_comment_may_not_contain_multiple_type_tags);
8018+
parseErrorAtCurrentToken(Diagnostics.A_JSDoc_typedef_comment_may_not_contain_multiple_type_tags);
8019+
const lastError = lastOrUndefined(parseDiagnostics);
80148020
if (lastError) {
8015-
addRelatedInfo(lastError, createDetachedDiagnostic(fileName, 0, 0, Diagnostics.The_tag_was_first_specified_here));
8021+
addRelatedInfo(
8022+
lastError,
8023+
createDetachedDiagnostic(fileName, 0, 0, Diagnostics.The_tag_was_first_specified_here)
8024+
);
80168025
}
80178026
break;
80188027
}

tests/baselines/reference/constructorWithIncompleteTypeAnnotation.errors.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,7 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(261,1): error TS
505505
!!! error TS1135: Argument expression expected.
506506
~
507507
!!! error TS1005: '(' expected.
508+
!!! related TS1007 tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts:257:33: The parser expected to find a ')' to match the '(' token here.
508509
~~~~~~
509510
!!! error TS2693: 'string' only refers to a type, but is being used as a value here.
510511
~~~

tests/baselines/reference/destructuringParameterDeclaration2.errors.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ 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.
4243
a0([1, 2, [["world"]], "string"]); // Error
4344
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4445
!!! error TS2345: Argument of type '[number, number, string[][], string]' is not assignable to parameter of type '[number, number, string[][]]'.

tests/baselines/reference/errorRecoveryWithDotFollowedByNamespaceKeyword.errors.txt

Lines changed: 2 additions & 1 deletion
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/nestedClassDeclaration.errors.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ tests/cases/conformance/classes/nestedClassDeclaration.ts(17,1): error TS1128: D
3232
!!! error TS2304: Cannot find name 'C4'.
3333
~
3434
!!! error TS1005: ',' expected.
35+
!!! related TS1007 tests/cases/conformance/classes/nestedClassDeclaration.ts:14:9: The parser expected to find a '}' to match the '{' token here.
3536
}
3637
}
3738
~

tests/baselines/reference/objectLiteralWithSemicolons4.errors.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ tests/cases/compiler/objectLiteralWithSemicolons4.ts(3,1): error TS1005: ',' exp
99
!!! error TS18004: No value exists in scope for the shorthand property 'a'. Either declare one or provide an initializer.
1010
;
1111
~
12-
!!! error TS1005: ',' expected.
12+
!!! error TS1005: ',' expected.
13+
!!! related TS1007 tests/cases/compiler/objectLiteralWithSemicolons4.ts:1:9: The parser expected to find a '}' to match the '{' token here.

tests/baselines/reference/objectSpreadNegativeParse.errors.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ tests/cases/conformance/types/spread/objectSpreadNegativeParse.ts(4,20): error T
2828
!!! error TS2304: Cannot find name 'matchMedia'.
2929
~
3030
!!! error TS1005: ',' expected.
31+
!!! related TS1007 tests/cases/conformance/types/spread/objectSpreadNegativeParse.ts:3:10: The parser expected to find a '}' to match the '{' token here.
3132
~
3233
!!! error TS1128: Declaration or statement expected.
3334
let o10 = { ...get x() { return 12; }};

tests/baselines/reference/parseErrorIncorrectReturnToken.errors.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ tests/cases/compiler/parseErrorIncorrectReturnToken.ts(12,1): error TS1128: Decl
2525
m(n: number) => string {
2626
~~
2727
!!! error TS1005: '{' expected.
28+
!!! related TS1007 tests/cases/compiler/parseErrorIncorrectReturnToken.ts:8:9: The parser expected to find a '}' to match the '{' token here.
2829
~~~~~~
2930
!!! error TS2693: 'string' only refers to a type, but is being used as a value here.
3031
~

tests/baselines/reference/parserErrorRecoveryArrayLiteralExpression3.errors.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ 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.
1112
~~~~~~~~~
1213
!!! error TS2695: Left side of comma operator is unused and has no side effects.
1314
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

tests/baselines/reference/parserFuzz1.errors.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserFuzz1.ts(2,15): e
2020
~~~~~~
2121
!!! error TS1005: ';' expected.
2222

23-
!!! error TS1005: '{' expected.
23+
!!! error TS1005: '{' expected.
24+
!!! related TS1007 tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserFuzz1.ts:1:9: The parser expected to find a '}' to match the '{' token here.

tests/baselines/reference/reservedWords2.errors.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ tests/cases/compiler/reservedWords2.ts(12,17): error TS1138: Parameter declarati
105105
!!! error TS1005: ';' expected.
106106
~
107107
!!! error TS1005: '(' expected.
108+
!!! related TS1007 tests/cases/compiler/reservedWords2.ts:9:18: The parser expected to find a ')' to match the '(' token here.
108109
~
109110
!!! error TS1128: Declaration or statement expected.
110111
enum void {}

tests/baselines/reference/tsbuild/noEmitOnError/initial-build/syntax-errors-with-incremental.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ Output::
4747
4 ;
4848
  ~
4949

50+
src/src/main.ts:2:11
51+
2 const a = {
52+
   ~
53+
The parser expected to find a '}' to match the '{' token here.
54+
5055

5156
Found 1 error.
5257

@@ -76,6 +81,11 @@ Output::
7681
4 ;
7782
  ~
7883

84+
src/src/main.ts:2:11
85+
2 const a = {
86+
   ~
87+
The parser expected to find a '}' to match the '{' token here.
88+
7989

8090
Found 1 error.
8191

tests/baselines/reference/tsbuild/noEmitOnError/initial-build/syntax-errors.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ Output::
4747
4 ;
4848
  ~
4949

50+
src/src/main.ts:2:11
51+
2 const a = {
52+
   ~
53+
The parser expected to find a '}' to match the '{' token here.
54+
5055

5156
Found 1 error.
5257

@@ -76,6 +81,11 @@ Output::
7681
4 ;
7782
  ~
7883

84+
src/src/main.ts:2:11
85+
2 const a = {
86+
   ~
87+
The parser expected to find a '}' to match the '{' token here.
88+
7989

8090
Found 1 error.
8191

tests/baselines/reference/tsbuild/watchMode/noEmitOnError/does-not-emit-any-files-on-error-with-incremental.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ Output::
5656
4 ;
5757
  ~
5858

59+
src/main.ts:2:11
60+
2 const a = {
61+
   ~
62+
The parser expected to find a '}' to match the '{' token here.
63+
5964
[12:00:35 AM] Found 1 error. Watching for file changes.
6065

6166

@@ -108,6 +113,11 @@ Output::
108113
4 ;
109114
  ~
110115

116+
src/main.ts:2:11
117+
2 const a = {
118+
   ~
119+
The parser expected to find a '}' to match the '{' token here.
120+
111121
[12:00:42 AM] Found 1 error. Watching for file changes.
112122

113123

tests/baselines/reference/tsbuild/watchMode/noEmitOnError/does-not-emit-any-files-on-error.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ Output::
5656
4 ;
5757
  ~
5858

59+
src/main.ts:2:11
60+
2 const a = {
61+
   ~
62+
The parser expected to find a '}' to match the '{' token here.
63+
5964
[12:00:35 AM] Found 1 error. Watching for file changes.
6065

6166

@@ -108,6 +113,11 @@ Output::
108113
4 ;
109114
  ~
110115

116+
src/main.ts:2:11
117+
2 const a = {
118+
   ~
119+
The parser expected to find a '}' to match the '{' token here.
120+
111121
[12:00:42 AM] Found 1 error. Watching for file changes.
112122

113123

tests/baselines/reference/tsc/incremental/initial-build/with-noEmitOnError-syntax-errors.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ Output::
4747
4 ;
4848
  ~
4949

50+
src/src/main.ts:2:11
51+
2 const a = {
52+
   ~
53+
The parser expected to find a '}' to match the '{' token here.
54+
5055

5156
Found 1 error.
5257

@@ -155,6 +160,11 @@ Output::
155160
4 ;
156161
  ~
157162

163+
src/src/main.ts:2:11
164+
2 const a = {
165+
   ~
166+
The parser expected to find a '}' to match the '{' token here.
167+
158168

159169
Found 1 error.
160170

tests/baselines/reference/tscWatch/emitAndErrorUpdates/assumeChangesOnlyAffectDirectDependencies/with-noEmitOnError-with-incremental.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ Output::
4343
4 ;
4444
  ~
4545

46+
src/main.ts:2:11
47+
2 const a = {
48+
   ~
49+
The parser expected to find a '}' to match the '{' token here.
50+
4651
[12:00:37 AM] Found 1 error. Watching for file changes.
4752

4853

@@ -175,6 +180,11 @@ Output::
175180
4 ;
176181
  ~
177182

183+
src/main.ts:2:11
184+
2 const a = {
185+
   ~
186+
The parser expected to find a '}' to match the '{' token here.
187+
178188
[12:00:44 AM] Found 1 error. Watching for file changes.
179189

180190

tests/baselines/reference/tscWatch/emitAndErrorUpdates/assumeChangesOnlyAffectDirectDependencies/with-noEmitOnError.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ Output::
4343
4 ;
4444
  ~
4545

46+
src/main.ts:2:11
47+
2 const a = {
48+
   ~
49+
The parser expected to find a '}' to match the '{' token here.
50+
4651
[12:00:32 AM] Found 1 error. Watching for file changes.
4752

4853

@@ -99,6 +104,11 @@ Output::
99104
4 ;
100105
  ~
101106

107+
src/main.ts:2:11
108+
2 const a = {
109+
   ~
110+
The parser expected to find a '}' to match the '{' token here.
111+
102112
[12:00:37 AM] Found 1 error. Watching for file changes.
103113

104114

tests/baselines/reference/tscWatch/emitAndErrorUpdates/assumeChangesOnlyAffectDirectDependenciesAndD/with-noEmitOnError-with-incremental.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ Output::
4343
4 ;
4444
  ~
4545

46+
src/main.ts:2:11
47+
2 const a = {
48+
   ~
49+
The parser expected to find a '}' to match the '{' token here.
50+
4651
[12:00:37 AM] Found 1 error. Watching for file changes.
4752

4853

@@ -176,6 +181,11 @@ Output::
176181
4 ;
177182
  ~
178183

184+
src/main.ts:2:11
185+
2 const a = {
186+
   ~
187+
The parser expected to find a '}' to match the '{' token here.
188+
179189
[12:00:44 AM] Found 1 error. Watching for file changes.
180190

181191

tests/baselines/reference/tscWatch/emitAndErrorUpdates/assumeChangesOnlyAffectDirectDependenciesAndD/with-noEmitOnError.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ Output::
4343
4 ;
4444
  ~
4545

46+
src/main.ts:2:11
47+
2 const a = {
48+
   ~
49+
The parser expected to find a '}' to match the '{' token here.
50+
4651
[12:00:32 AM] Found 1 error. Watching for file changes.
4752

4853

@@ -99,6 +104,11 @@ Output::
99104
4 ;
100105
  ~
101106

107+
src/main.ts:2:11
108+
2 const a = {
109+
   ~
110+
The parser expected to find a '}' to match the '{' token here.
111+
102112
[12:00:37 AM] Found 1 error. Watching for file changes.
103113

104114

0 commit comments

Comments
 (0)