Skip to content

Commit f8b34c9

Browse files
authored
Merge pull request microsoft#11118 from Microsoft/fix11081
Fix11081
2 parents c5e1cb8 + 33789cb commit f8b34c9

10 files changed

+229
-13
lines changed

src/compiler/parser.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1394,8 +1394,8 @@ namespace ts {
13941394
// Tokens other than ')' and ']' (the latter for index signatures) are here for better error recovery
13951395
return token() === SyntaxKind.CloseParenToken || token() === SyntaxKind.CloseBracketToken /*|| token === SyntaxKind.OpenBraceToken*/;
13961396
case ParsingContext.TypeArguments:
1397-
// Tokens other than '>' are here for better error recovery
1398-
return token() === SyntaxKind.GreaterThanToken || token() === SyntaxKind.OpenParenToken;
1397+
// All other tokens should cause the type-argument to terminate except comma token
1398+
return token() !== SyntaxKind.CommaToken;
13991399
case ParsingContext.HeritageClauses:
14001400
return token() === SyntaxKind.OpenBraceToken || token() === SyntaxKind.CloseBraceToken;
14011401
case ParsingContext.JsxAttributes:
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,31 @@
11
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/TypeArgumentLists/TypeArgumentList1.ts(1,1): error TS2304: Cannot find name 'Foo'.
2+
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/TypeArgumentLists/TypeArgumentList1.ts(1,1): error TS2695: Left side of comma operator is unused and has no side effects.
3+
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/TypeArgumentLists/TypeArgumentList1.ts(1,1): error TS2695: Left side of comma operator is unused and has no side effects.
4+
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/TypeArgumentLists/TypeArgumentList1.ts(1,5): error TS2304: Cannot find name 'A'.
5+
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/TypeArgumentLists/TypeArgumentList1.ts(1,7): error TS2304: Cannot find name 'B'.
26
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/TypeArgumentLists/TypeArgumentList1.ts(1,9): error TS1127: Invalid character.
7+
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/TypeArgumentLists/TypeArgumentList1.ts(1,11): error TS2304: Cannot find name 'C'.
8+
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/TypeArgumentLists/TypeArgumentList1.ts(1,14): error TS2695: Left side of comma operator is unused and has no side effects.
9+
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/TypeArgumentLists/TypeArgumentList1.ts(1,14): error TS2695: Left side of comma operator is unused and has no side effects.
310

411

5-
==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/TypeArgumentLists/TypeArgumentList1.ts (2 errors) ====
12+
==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/TypeArgumentLists/TypeArgumentList1.ts (9 errors) ====
613
Foo<A,B,\ C>(4, 5, 6);
714
~~~
815
!!! error TS2304: Cannot find name 'Foo'.
16+
~~~~~
17+
!!! error TS2695: Left side of comma operator is unused and has no side effects.
18+
~~~~~~~
19+
!!! error TS2695: Left side of comma operator is unused and has no side effects.
20+
~
21+
!!! error TS2304: Cannot find name 'A'.
22+
~
23+
!!! error TS2304: Cannot find name 'B'.
924

10-
!!! error TS1127: Invalid character.
25+
!!! error TS1127: Invalid character.
26+
~
27+
!!! error TS2304: Cannot find name 'C'.
28+
~
29+
!!! error TS2695: Left side of comma operator is unused and has no side effects.
30+
~~~~
31+
!!! error TS2695: Left side of comma operator is unused and has no side effects.

tests/baselines/reference/TypeArgumentList1.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
Foo<A,B,\ C>(4, 5, 6);
33

44
//// [TypeArgumentList1.js]
5-
Foo(4, 5, 6);
5+
Foo < A, B, ;
6+
C > (4, 5, 6);
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
tests/cases/conformance/parser/ecmascript5/SkippedTokens/parserSkippedTokens20.ts(1,8): error TS2304: Cannot find name 'X'.
22
tests/cases/conformance/parser/ecmascript5/SkippedTokens/parserSkippedTokens20.ts(1,12): error TS1127: Invalid character.
3-
tests/cases/conformance/parser/ecmascript5/SkippedTokens/parserSkippedTokens20.ts(1,13): error TS1005: '>' expected.
43

54

6-
==== tests/cases/conformance/parser/ecmascript5/SkippedTokens/parserSkippedTokens20.ts (3 errors) ====
5+
==== tests/cases/conformance/parser/ecmascript5/SkippedTokens/parserSkippedTokens20.ts (2 errors) ====
76
var v: X<T \
87
~
98
!!! error TS2304: Cannot find name 'X'.
109

11-
!!! error TS1127: Invalid character.
12-
13-
!!! error TS1005: '>' expected.
10+
!!! error TS1127: Invalid character.
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,31 @@
11
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/TypeArgumentLists/parserX_TypeArgumentList1.ts(1,1): error TS2304: Cannot find name 'Foo'.
2+
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/TypeArgumentLists/parserX_TypeArgumentList1.ts(1,1): error TS2695: Left side of comma operator is unused and has no side effects.
3+
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/TypeArgumentLists/parserX_TypeArgumentList1.ts(1,1): error TS2695: Left side of comma operator is unused and has no side effects.
4+
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/TypeArgumentLists/parserX_TypeArgumentList1.ts(1,5): error TS2304: Cannot find name 'A'.
5+
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/TypeArgumentLists/parserX_TypeArgumentList1.ts(1,7): error TS2304: Cannot find name 'B'.
26
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/TypeArgumentLists/parserX_TypeArgumentList1.ts(1,9): error TS1127: Invalid character.
7+
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/TypeArgumentLists/parserX_TypeArgumentList1.ts(1,11): error TS2304: Cannot find name 'C'.
8+
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/TypeArgumentLists/parserX_TypeArgumentList1.ts(1,14): error TS2695: Left side of comma operator is unused and has no side effects.
9+
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/TypeArgumentLists/parserX_TypeArgumentList1.ts(1,14): error TS2695: Left side of comma operator is unused and has no side effects.
310

411

5-
==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/TypeArgumentLists/parserX_TypeArgumentList1.ts (2 errors) ====
12+
==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/TypeArgumentLists/parserX_TypeArgumentList1.ts (9 errors) ====
613
Foo<A,B,\ C>(4, 5, 6);
714
~~~
815
!!! error TS2304: Cannot find name 'Foo'.
16+
~~~~~
17+
!!! error TS2695: Left side of comma operator is unused and has no side effects.
18+
~~~~~~~
19+
!!! error TS2695: Left side of comma operator is unused and has no side effects.
20+
~
21+
!!! error TS2304: Cannot find name 'A'.
22+
~
23+
!!! error TS2304: Cannot find name 'B'.
924

10-
!!! error TS1127: Invalid character.
25+
!!! error TS1127: Invalid character.
26+
~
27+
!!! error TS2304: Cannot find name 'C'.
28+
~
29+
!!! error TS2695: Left side of comma operator is unused and has no side effects.
30+
~~~~
31+
!!! error TS2695: Left side of comma operator is unused and has no side effects.

tests/baselines/reference/parserX_TypeArgumentList1.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
Foo<A,B,\ C>(4, 5, 6);
33

44
//// [parserX_TypeArgumentList1.js]
5-
Foo(4, 5, 6);
5+
Foo < A, B, ;
6+
C > (4, 5, 6);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//// [tsxCorrectlyParseLessThanComparison1.tsx]
2+
declare module JSX {
3+
interface Element {
4+
div: string;
5+
}
6+
}
7+
declare namespace React {
8+
class Component<P, S> {
9+
constructor(props?: P, context?: any);
10+
props: P;
11+
}
12+
}
13+
14+
export class ShortDetails extends React.Component<{ id: number }, {}> {
15+
public render(): JSX.Element {
16+
if (this.props.id < 1) {
17+
return (<div></div>);
18+
}
19+
}
20+
}
21+
22+
//// [tsxCorrectlyParseLessThanComparison1.js]
23+
"use strict";
24+
var __extends = (this && this.__extends) || function (d, b) {
25+
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
26+
function __() { this.constructor = d; }
27+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
28+
};
29+
var ShortDetails = (function (_super) {
30+
__extends(ShortDetails, _super);
31+
function ShortDetails() {
32+
_super.apply(this, arguments);
33+
}
34+
ShortDetails.prototype.render = function () {
35+
if (this.props.id < 1) {
36+
return (React.createElement("div", null));
37+
}
38+
};
39+
return ShortDetails;
40+
}(React.Component));
41+
exports.ShortDetails = ShortDetails;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
=== tests/cases/conformance/jsx/tsxCorrectlyParseLessThanComparison1.tsx ===
2+
declare module JSX {
3+
>JSX : Symbol(JSX, Decl(tsxCorrectlyParseLessThanComparison1.tsx, 0, 0))
4+
5+
interface Element {
6+
>Element : Symbol(Element, Decl(tsxCorrectlyParseLessThanComparison1.tsx, 0, 20))
7+
8+
div: string;
9+
>div : Symbol(Element.div, Decl(tsxCorrectlyParseLessThanComparison1.tsx, 1, 23))
10+
}
11+
}
12+
declare namespace React {
13+
>React : Symbol(React, Decl(tsxCorrectlyParseLessThanComparison1.tsx, 4, 1))
14+
15+
class Component<P, S> {
16+
>Component : Symbol(Component, Decl(tsxCorrectlyParseLessThanComparison1.tsx, 5, 25))
17+
>P : Symbol(P, Decl(tsxCorrectlyParseLessThanComparison1.tsx, 6, 20))
18+
>S : Symbol(S, Decl(tsxCorrectlyParseLessThanComparison1.tsx, 6, 22))
19+
20+
constructor(props?: P, context?: any);
21+
>props : Symbol(props, Decl(tsxCorrectlyParseLessThanComparison1.tsx, 7, 20))
22+
>P : Symbol(P, Decl(tsxCorrectlyParseLessThanComparison1.tsx, 6, 20))
23+
>context : Symbol(context, Decl(tsxCorrectlyParseLessThanComparison1.tsx, 7, 30))
24+
25+
props: P;
26+
>props : Symbol(Component.props, Decl(tsxCorrectlyParseLessThanComparison1.tsx, 7, 46))
27+
>P : Symbol(P, Decl(tsxCorrectlyParseLessThanComparison1.tsx, 6, 20))
28+
}
29+
}
30+
31+
export class ShortDetails extends React.Component<{ id: number }, {}> {
32+
>ShortDetails : Symbol(ShortDetails, Decl(tsxCorrectlyParseLessThanComparison1.tsx, 10, 1))
33+
>React.Component : Symbol(React.Component, Decl(tsxCorrectlyParseLessThanComparison1.tsx, 5, 25))
34+
>React : Symbol(React, Decl(tsxCorrectlyParseLessThanComparison1.tsx, 4, 1))
35+
>Component : Symbol(React.Component, Decl(tsxCorrectlyParseLessThanComparison1.tsx, 5, 25))
36+
>id : Symbol(id, Decl(tsxCorrectlyParseLessThanComparison1.tsx, 12, 51))
37+
38+
public render(): JSX.Element {
39+
>render : Symbol(ShortDetails.render, Decl(tsxCorrectlyParseLessThanComparison1.tsx, 12, 71))
40+
>JSX : Symbol(JSX, Decl(tsxCorrectlyParseLessThanComparison1.tsx, 0, 0))
41+
>Element : Symbol(JSX.Element, Decl(tsxCorrectlyParseLessThanComparison1.tsx, 0, 20))
42+
43+
if (this.props.id < 1) {
44+
>this.props.id : Symbol(id, Decl(tsxCorrectlyParseLessThanComparison1.tsx, 12, 51))
45+
>this.props : Symbol(React.Component.props, Decl(tsxCorrectlyParseLessThanComparison1.tsx, 7, 46))
46+
>this : Symbol(ShortDetails, Decl(tsxCorrectlyParseLessThanComparison1.tsx, 10, 1))
47+
>props : Symbol(React.Component.props, Decl(tsxCorrectlyParseLessThanComparison1.tsx, 7, 46))
48+
>id : Symbol(id, Decl(tsxCorrectlyParseLessThanComparison1.tsx, 12, 51))
49+
50+
return (<div></div>);
51+
>div : Symbol(unknown)
52+
>div : Symbol(unknown)
53+
}
54+
}
55+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
=== tests/cases/conformance/jsx/tsxCorrectlyParseLessThanComparison1.tsx ===
2+
declare module JSX {
3+
>JSX : any
4+
5+
interface Element {
6+
>Element : Element
7+
8+
div: string;
9+
>div : string
10+
}
11+
}
12+
declare namespace React {
13+
>React : typeof React
14+
15+
class Component<P, S> {
16+
>Component : Component<P, S>
17+
>P : P
18+
>S : S
19+
20+
constructor(props?: P, context?: any);
21+
>props : P
22+
>P : P
23+
>context : any
24+
25+
props: P;
26+
>props : P
27+
>P : P
28+
}
29+
}
30+
31+
export class ShortDetails extends React.Component<{ id: number }, {}> {
32+
>ShortDetails : ShortDetails
33+
>React.Component : React.Component<{ id: number; }, {}>
34+
>React : typeof React
35+
>Component : typeof React.Component
36+
>id : number
37+
38+
public render(): JSX.Element {
39+
>render : () => JSX.Element
40+
>JSX : any
41+
>Element : JSX.Element
42+
43+
if (this.props.id < 1) {
44+
>this.props.id < 1 : boolean
45+
>this.props.id : number
46+
>this.props : { id: number; }
47+
>this : this
48+
>props : { id: number; }
49+
>id : number
50+
>1 : 1
51+
52+
return (<div></div>);
53+
>(<div></div>) : any
54+
><div></div> : any
55+
>div : any
56+
>div : any
57+
}
58+
}
59+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// @jsx: react
2+
declare module JSX {
3+
interface Element {
4+
div: string;
5+
}
6+
}
7+
declare namespace React {
8+
class Component<P, S> {
9+
constructor(props?: P, context?: any);
10+
props: P;
11+
}
12+
}
13+
14+
export class ShortDetails extends React.Component<{ id: number }, {}> {
15+
public render(): JSX.Element {
16+
if (this.props.id < 1) {
17+
return (<div></div>);
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)