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 microsoft#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.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//// [missingCloseBraceInClassDeclaration.ts]
2+
class TestCls {
3+
prop = 0;
4+
method() {
5+
return this.prop;
6+
}
7+
8+
9+
10+
//// [missingCloseBraceInClassDeclaration.js]
11+
var TestCls = /** @class */ (function () {
12+
function TestCls() {
13+
this.prop = 0;
14+
}
15+
TestCls.prototype.method = function () {
16+
return this.prop;
17+
};
18+
return TestCls;
19+
}());
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
=== tests/cases/compiler/missingCloseBraceInClassDeclaration.ts ===
2+
class TestCls {
3+
>TestCls : Symbol(TestCls, Decl(missingCloseBraceInClassDeclaration.ts, 0, 0))
4+
5+
prop = 0;
6+
>prop : Symbol(TestCls.prop, Decl(missingCloseBraceInClassDeclaration.ts, 0, 15))
7+
8+
method() {
9+
>method : Symbol(TestCls.method, Decl(missingCloseBraceInClassDeclaration.ts, 1, 11))
10+
11+
return this.prop;
12+
>this.prop : Symbol(TestCls.prop, Decl(missingCloseBraceInClassDeclaration.ts, 0, 15))
13+
>this : Symbol(TestCls, Decl(missingCloseBraceInClassDeclaration.ts, 0, 0))
14+
>prop : Symbol(TestCls.prop, Decl(missingCloseBraceInClassDeclaration.ts, 0, 15))
15+
}
16+
17+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
=== tests/cases/compiler/missingCloseBraceInClassDeclaration.ts ===
2+
class TestCls {
3+
>TestCls : TestCls
4+
5+
prop = 0;
6+
>prop : number
7+
>0 : 0
8+
9+
method() {
10+
>method : () => number
11+
12+
return this.prop;
13+
>this.prop : number
14+
>this : this
15+
>prop : number
16+
}
17+
18+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
tests/cases/compiler/missingCloseBraceInEnum.ts(6,1): error TS1005: '}' expected.
2+
3+
4+
==== tests/cases/compiler/missingCloseBraceInEnum.ts (1 errors) ====
5+
enum Colors {
6+
Red,
7+
Green,
8+
Blue,
9+
10+
11+
12+
!!! error TS1005: '}' expected.
13+
!!! related TS1007 tests/cases/compiler/missingCloseBraceInEnum.ts:1:13: The parser expected to find a '}' to match the '{' token here.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//// [missingCloseBraceInEnum.ts]
2+
enum Colors {
3+
Red,
4+
Green,
5+
Blue,
6+
7+
8+
9+
//// [missingCloseBraceInEnum.js]
10+
var Colors;
11+
(function (Colors) {
12+
Colors[Colors["Red"] = 0] = "Red";
13+
Colors[Colors["Green"] = 1] = "Green";
14+
Colors[Colors["Blue"] = 2] = "Blue";
15+
})(Colors || (Colors = {}));
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
=== tests/cases/compiler/missingCloseBraceInEnum.ts ===
2+
enum Colors {
3+
>Colors : Symbol(Colors, Decl(missingCloseBraceInEnum.ts, 0, 0))
4+
5+
Red,
6+
>Red : Symbol(Colors.Red, Decl(missingCloseBraceInEnum.ts, 0, 13))
7+
8+
Green,
9+
>Green : Symbol(Colors.Green, Decl(missingCloseBraceInEnum.ts, 1, 6))
10+
11+
Blue,
12+
>Blue : Symbol(Colors.Blue, Decl(missingCloseBraceInEnum.ts, 2, 8))
13+
14+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
=== tests/cases/compiler/missingCloseBraceInEnum.ts ===
2+
enum Colors {
3+
>Colors : Colors
4+
5+
Red,
6+
>Red : Colors.Red
7+
8+
Green,
9+
>Green : Colors.Green
10+
11+
Blue,
12+
>Blue : Colors.Blue
13+
14+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
tests/cases/compiler/missingCloseBraceInJsxAttributeExpression.tsx(1,23): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.
2+
tests/cases/compiler/missingCloseBraceInJsxAttributeExpression.tsx(1,30): error TS1109: Expression expected.
3+
tests/cases/compiler/missingCloseBraceInJsxAttributeExpression.tsx(1,31): error TS1109: Expression expected.
4+
tests/cases/compiler/missingCloseBraceInJsxAttributeExpression.tsx(2,1): error TS1005: '}' expected.
5+
6+
7+
==== tests/cases/compiler/missingCloseBraceInJsxAttributeExpression.tsx (4 errors) ====
8+
let el = <input prop={'abc' />
9+
~~~~~
10+
!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.
11+
~
12+
!!! error TS1109: Expression expected.
13+
14+
!!! error TS1109: Expression expected.
15+
16+
17+
!!! error TS1005: '}' expected.
18+
!!! related TS1007 tests/cases/compiler/missingCloseBraceInJsxAttributeExpression.tsx:1:22: The parser expected to find a '}' to match the '{' token here.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//// [missingCloseBraceInJsxAttributeExpression.tsx]
2+
let el = <input prop={'abc' />
3+
4+
5+
//// [missingCloseBraceInJsxAttributeExpression.jsx]
6+
var el = <input prop={'abc' / >
7+
}/>;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
=== tests/cases/compiler/missingCloseBraceInJsxAttributeExpression.tsx ===
2+
let el = <input prop={'abc' />
3+
>el : Symbol(el, Decl(missingCloseBraceInJsxAttributeExpression.tsx, 0, 3))
4+
>prop : Symbol(prop, Decl(missingCloseBraceInJsxAttributeExpression.tsx, 0, 15))
5+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
=== tests/cases/compiler/missingCloseBraceInJsxAttributeExpression.tsx ===
2+
let el = <input prop={'abc' />
3+
>el : any
4+
><input prop={'abc' /> : any
5+
>input : any
6+
>prop : boolean
7+
>'abc' /> : boolean
8+
>'abc' / : number
9+
>'abc' : "abc"
10+
> : any
11+
12+
> : any
13+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
tests/cases/compiler/missingCloseBraceInJsxExpression.tsx(1,23): error TS1005: '}' expected.
2+
3+
4+
==== tests/cases/compiler/missingCloseBraceInJsxExpression.tsx (1 errors) ====
5+
let el = <div>{'hello'</div>
6+
~~
7+
!!! error TS1005: '}' expected.
8+
!!! related TS1007 tests/cases/compiler/missingCloseBraceInJsxExpression.tsx:1:15: The parser expected to find a '}' to match the '{' token here.
9+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//// [missingCloseBraceInJsxExpression.tsx]
2+
let el = <div>{'hello'</div>
3+
4+
5+
//// [missingCloseBraceInJsxExpression.jsx]
6+
var el = <div>{'hello'}</div>;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
=== tests/cases/compiler/missingCloseBraceInJsxExpression.tsx ===
2+
let el = <div>{'hello'</div>
3+
>el : Symbol(el, Decl(missingCloseBraceInJsxExpression.tsx, 0, 3))
4+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
=== tests/cases/compiler/missingCloseBraceInJsxExpression.tsx ===
2+
let el = <div>{'hello'</div>
3+
>el : any
4+
><div>{'hello'</div> : any
5+
>div : any
6+
>'hello' : "hello"
7+
>div : any
8+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
tests/cases/compiler/missingCloseBraceInModuleBlock.ts(4,1): error TS1005: '}' expected.
2+
3+
4+
==== tests/cases/compiler/missingCloseBraceInModuleBlock.ts (1 errors) ====
5+
module "dummy" {
6+
interface Dummy {}
7+
8+
9+
10+
!!! error TS1005: '}' expected.
11+
!!! related TS1007 tests/cases/compiler/missingCloseBraceInModuleBlock.ts:1:16: The parser expected to find a '}' to match the '{' token here.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//// [missingCloseBraceInModuleBlock.ts]
2+
module "dummy" {
3+
interface Dummy {}
4+
5+
6+
7+
//// [missingCloseBraceInModuleBlock.js]
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
=== tests/cases/compiler/missingCloseBraceInModuleBlock.ts ===
2+
module "dummy" {
3+
>"dummy" : Symbol("dummy", Decl(missingCloseBraceInModuleBlock.ts, 0, 0))
4+
5+
interface Dummy {}
6+
>Dummy : Symbol(Dummy, Decl(missingCloseBraceInModuleBlock.ts, 0, 16))
7+
8+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
=== tests/cases/compiler/missingCloseBraceInModuleBlock.ts ===
2+
module "dummy" {
3+
>"dummy" : typeof import("dummy")
4+
5+
interface Dummy {}
6+
7+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
tests/cases/compiler/missingCloseBraceInTypeMemberList.ts(4,1): error TS1005: '}' expected.
2+
3+
4+
==== tests/cases/compiler/missingCloseBraceInTypeMemberList.ts (1 errors) ====
5+
type ITest = {
6+
num: number;
7+
8+
9+
10+
!!! error TS1005: '}' expected.
11+
!!! related TS1007 tests/cases/compiler/missingCloseBraceInTypeMemberList.ts:1:14: The parser expected to find a '}' to match the '{' token here.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//// [missingCloseBraceInTypeMemberList.ts]
2+
type ITest = {
3+
num: number;
4+
5+
6+
7+
//// [missingCloseBraceInTypeMemberList.js]
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
=== tests/cases/compiler/missingCloseBraceInTypeMemberList.ts ===
2+
type ITest = {
3+
>ITest : Symbol(ITest, Decl(missingCloseBraceInTypeMemberList.ts, 0, 0))
4+
5+
num: number;
6+
>num : Symbol(num, Decl(missingCloseBraceInTypeMemberList.ts, 0, 14))
7+
8+

0 commit comments

Comments
 (0)