Skip to content

Commit eb22100

Browse files
author
Ayaz Hafiz
committed
Token hints for missing closing braces: classes, enums, jsx, modules, types
This commit adds token hints for missing close braces in - Class definitions - Enum definitions - JSX expressions - Module definitions (this includes augmentations and namespaces) - Type member lists (this includes interfaces) The token hint refers to the opening brace for which the parser expected a corresponding closing brace. Note that this commit *does not* update all occurences of an expectation for a close brace to provide token hints. Constructs for which this token hint is not provided include: - Mapped types - Switch statements - Object binding patterns - JSX spread attributes (`<div {...props}></div>`) - JSDoc implements/augments tags (`/* @implements {SomeInterface} */`) Part of #35597.
1 parent 5e9c436 commit eb22100

File tree

48 files changed

+9541
-7967
lines changed

Some content is hidden

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

48 files changed

+9541
-7967
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 '}' to match the '{' token here.": {
18+
"The parser expected to find a '{0}' to match the '{1}' token here.": {
1919
"category": "Error",
2020
"code": 1007
2121
},

src/compiler/parser.ts

Lines changed: 9217 additions & 7957 deletions
Large diffs are not rendered by default.

tests/baselines/reference/classMemberWithMissingIdentifier.errors.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ tests/cases/compiler/classMemberWithMissingIdentifier.ts(3,1): error TS1128: Dec
1010
!!! error TS1146: Declaration expected.
1111
~
1212
!!! error TS1005: ';' expected.
13+
!!! related TS1007 tests/cases/compiler/classMemberWithMissingIdentifier.ts:1:9: The parser expected to find a '}' to match the '{' token here.
1314
}
1415
~
1516
!!! error TS1128: Declaration or statement expected.

tests/baselines/reference/classMemberWithMissingIdentifier2.errors.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ tests/cases/compiler/classMemberWithMissingIdentifier2.ts(3,1): error TS1128: De
1414
!!! error TS1146: Declaration expected.
1515
~
1616
!!! error TS1005: ';' expected.
17+
!!! related TS1007 tests/cases/compiler/classMemberWithMissingIdentifier2.ts:1:9: The parser expected to find a '}' to match the '{' token here.
1718
~
1819
!!! error TS1005: ',' expected.
1920
~~~~~~

tests/baselines/reference/constructorWithIncompleteTypeAnnotation.errors.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(261,1): error TS
142142
if (retValue != 0) {
143143
~~
144144
!!! error TS1005: ',' expected.
145+
!!! related TS1007 tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts:15:26: The parser expected to find a '}' to match the '{' token here.
145146
~
146147
!!! error TS1005: ';' expected.
147148

tests/baselines/reference/derivedClassSuperCallsInNonConstructorMembers.errors.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassS
5050
!!! error TS2304: Cannot find name 'super'.
5151
~
5252
!!! error TS1005: ';' expected.
53+
!!! related TS1007 tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsInNonConstructorMembers.ts:7:28: The parser expected to find a '}' to match the '{' token here.
5354
~
5455
!!! error TS1109: Expression expected.
5556
b() {

tests/baselines/reference/errorRecoveryWithDotFollowedByNamespaceKeyword.errors.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ tests/cases/compiler/errorRecoveryWithDotFollowedByNamespaceKeyword.ts(9,2): err
1717

1818
!!! error TS1005: '}' expected.
1919
!!! 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.
20+
!!! related TS1007 tests/cases/compiler/errorRecoveryWithDotFollowedByNamespaceKeyword.ts:2:20: The parser expected to find a '}' to match the '{' token here.
21+
!!! related TS1007 tests/cases/compiler/errorRecoveryWithDotFollowedByNamespaceKeyword.ts:1:13: The parser expected to find a '}' to match the '{' token here.

tests/baselines/reference/jsxAndTypeAssertion.errors.txt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ tests/cases/conformance/jsx/jsxAndTypeAssertion.tsx(18,69): error TS1381: Unexpe
2121
tests/cases/conformance/jsx/jsxAndTypeAssertion.tsx(18,76): error TS1381: Unexpected token. Did you mean `{'}'}` or `&rbrace;`?
2222
tests/cases/conformance/jsx/jsxAndTypeAssertion.tsx(21,1): error TS1005: ':' expected.
2323
tests/cases/conformance/jsx/jsxAndTypeAssertion.tsx(21,1): error TS1005: '</' expected.
24+
tests/cases/conformance/jsx/jsxAndTypeAssertion.tsx(21,1): error TS1005: '</' expected.
25+
tests/cases/conformance/jsx/jsxAndTypeAssertion.tsx(21,1): error TS1005: '</' expected.
2426

2527

26-
==== tests/cases/conformance/jsx/jsxAndTypeAssertion.tsx (23 errors) ====
28+
==== tests/cases/conformance/jsx/jsxAndTypeAssertion.tsx (25 errors) ====
2729
declare var createElement: any;
2830

2931
class foo {}
@@ -36,6 +38,7 @@ tests/cases/conformance/jsx/jsxAndTypeAssertion.tsx(21,1): error TS1005: '</' ex
3638
!!! error TS2582: Cannot find name 'test'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha`.
3739
~
3840
!!! error TS1005: '}' expected.
41+
!!! related TS1007 tests/cases/conformance/jsx/jsxAndTypeAssertion.tsx:6:11: The parser expected to find a '}' to match the '{' token here.
3942
~
4043
!!! error TS1381: Unexpected token. Did you mean `{'}'}` or `&rbrace;`?
4144

@@ -50,6 +53,7 @@ tests/cases/conformance/jsx/jsxAndTypeAssertion.tsx(21,1): error TS1005: '</' ex
5053
!!! error TS1381: Unexpected token. Did you mean `{'}'}` or `&rbrace;`?
5154
~
5255
!!! error TS1005: '}' expected.
56+
!!! related TS1007 tests/cases/conformance/jsx/jsxAndTypeAssertion.tsx:10:16: The parser expected to find a '}' to match the '{' token here.
5357

5458
x = <foo test={<foo>{}}>hello</foo>;
5559
~
@@ -58,6 +62,7 @@ tests/cases/conformance/jsx/jsxAndTypeAssertion.tsx(21,1): error TS1005: '</' ex
5862
!!! error TS1382: Unexpected token. Did you mean `{'>'}` or `&gt;`?
5963
~
6064
!!! error TS1005: '}' expected.
65+
!!! related TS1007 tests/cases/conformance/jsx/jsxAndTypeAssertion.tsx:12:15: The parser expected to find a '}' to match the '{' token here.
6166

6267
x = <foo test={<foo>{}}>hello{<foo>{}}</foo>;
6368
~~~
@@ -70,6 +75,7 @@ tests/cases/conformance/jsx/jsxAndTypeAssertion.tsx(21,1): error TS1005: '</' ex
7075
!!! error TS1381: Unexpected token. Did you mean `{'}'}` or `&rbrace;`?
7176
~
7277
!!! error TS1005: '}' expected.
78+
!!! related TS1007 tests/cases/conformance/jsx/jsxAndTypeAssertion.tsx:14:30: The parser expected to find a '}' to match the '{' token here.
7379

7480
x = <foo>x</foo>, x = <foo/>;
7581

@@ -89,5 +95,12 @@ tests/cases/conformance/jsx/jsxAndTypeAssertion.tsx(21,1): error TS1005: '</' ex
8995

9096

9197
!!! error TS1005: ':' expected.
98+
!!! related TS1007 tests/cases/conformance/jsx/jsxAndTypeAssertion.tsx:18:17: The parser expected to find a '}' to match the '{' token here.
99+
100+
!!! error TS1005: '</' expected.
101+
!!! related TS1007 tests/cases/conformance/jsx/jsxAndTypeAssertion.tsx:14:15: The parser expected to find a '}' to match the '{' token here.
102+
103+
!!! error TS1005: '</' expected.
104+
!!! related TS1007 tests/cases/conformance/jsx/jsxAndTypeAssertion.tsx:18:6: The parser expected to find a '}' to match the '{' token here.
92105

93106
!!! error TS1005: '</' expected.

tests/baselines/reference/jsxInvalidEsprimaTestSuite.errors.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ tests/cases/conformance/jsx/9.tsx(1,16): error TS1109: Expression expected.
244244
<a>{"str";}</a>;
245245
~
246246
!!! error TS1005: '}' expected.
247+
!!! related TS1007 tests/cases/conformance/jsx/20.tsx:1:4: The parser expected to find a '}' to match the '{' token here.
247248
~
248249
!!! error TS1381: Unexpected token. Did you mean `{'}'}` or `&rbrace;`?
249250
==== tests/cases/conformance/jsx/21.tsx (1 errors) ====
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
tests/cases/compiler/missingCloseBraceInClassDeclaration.ts(7,1): error TS1005: '}' expected.
2+
3+
4+
==== tests/cases/compiler/missingCloseBraceInClassDeclaration.ts (1 errors) ====
5+
class TestCls {
6+
prop = 0;
7+
method() {
8+
return this.prop;
9+
}
10+
11+
12+
13+
!!! error TS1005: '}' expected.
14+
!!! related TS1007 tests/cases/compiler/missingCloseBraceInClassDeclaration.ts:1:15: The parser expected to find a '}' to match the '{' token here.

0 commit comments

Comments
 (0)