diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 3628ac304a984..b96d8b1dd53cf 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -1380,8 +1380,8 @@ namespace ts { // Tokens other than ')' and ']' (the latter for index signatures) are here for better error recovery return token() === SyntaxKind.CloseParenToken || token() === SyntaxKind.CloseBracketToken /*|| token === SyntaxKind.OpenBraceToken*/; case ParsingContext.TypeArguments: - // Tokens other than '>' are here for better error recovery - return token() === SyntaxKind.GreaterThanToken || token() === SyntaxKind.OpenParenToken; + // All other tokens should cause the type-argument to terminate except comma token + return token() !== SyntaxKind.CommaToken; case ParsingContext.HeritageClauses: return token() === SyntaxKind.OpenBraceToken || token() === SyntaxKind.CloseBraceToken; case ParsingContext.JsxAttributes: diff --git a/tests/baselines/reference/TypeArgumentList1.errors.txt b/tests/baselines/reference/TypeArgumentList1.errors.txt index 4138f3f8cc514..7c7d788fd5419 100644 --- a/tests/baselines/reference/TypeArgumentList1.errors.txt +++ b/tests/baselines/reference/TypeArgumentList1.errors.txt @@ -1,10 +1,19 @@ tests/cases/conformance/parser/ecmascript5/ErrorRecovery/TypeArgumentLists/TypeArgumentList1.ts(1,1): error TS2304: Cannot find name 'Foo'. +tests/cases/conformance/parser/ecmascript5/ErrorRecovery/TypeArgumentLists/TypeArgumentList1.ts(1,5): error TS2304: Cannot find name 'A'. +tests/cases/conformance/parser/ecmascript5/ErrorRecovery/TypeArgumentLists/TypeArgumentList1.ts(1,7): error TS2304: Cannot find name 'B'. tests/cases/conformance/parser/ecmascript5/ErrorRecovery/TypeArgumentLists/TypeArgumentList1.ts(1,9): error TS1127: Invalid character. +tests/cases/conformance/parser/ecmascript5/ErrorRecovery/TypeArgumentLists/TypeArgumentList1.ts(1,11): error TS2304: Cannot find name 'C'. -==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/TypeArgumentLists/TypeArgumentList1.ts (2 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/TypeArgumentLists/TypeArgumentList1.ts (5 errors) ==== Foo(4, 5, 6); ~~~ !!! error TS2304: Cannot find name 'Foo'. + ~ +!!! error TS2304: Cannot find name 'A'. + ~ +!!! error TS2304: Cannot find name 'B'. -!!! error TS1127: Invalid character. \ No newline at end of file +!!! error TS1127: Invalid character. + ~ +!!! error TS2304: Cannot find name 'C'. \ No newline at end of file diff --git a/tests/baselines/reference/TypeArgumentList1.js b/tests/baselines/reference/TypeArgumentList1.js index b87b310a9afef..f6f5412ce1624 100644 --- a/tests/baselines/reference/TypeArgumentList1.js +++ b/tests/baselines/reference/TypeArgumentList1.js @@ -2,4 +2,5 @@ Foo(4, 5, 6); //// [TypeArgumentList1.js] -Foo(4, 5, 6); +Foo < A, B, ; +C > (4, 5, 6); diff --git a/tests/baselines/reference/parserSkippedTokens20.errors.txt b/tests/baselines/reference/parserSkippedTokens20.errors.txt index 4e66b51f48d17..774443d4d9a9f 100644 --- a/tests/baselines/reference/parserSkippedTokens20.errors.txt +++ b/tests/baselines/reference/parserSkippedTokens20.errors.txt @@ -1,13 +1,10 @@ tests/cases/conformance/parser/ecmascript5/SkippedTokens/parserSkippedTokens20.ts(1,8): error TS2304: Cannot find name 'X'. tests/cases/conformance/parser/ecmascript5/SkippedTokens/parserSkippedTokens20.ts(1,12): error TS1127: Invalid character. -tests/cases/conformance/parser/ecmascript5/SkippedTokens/parserSkippedTokens20.ts(1,13): error TS1005: '>' expected. -==== tests/cases/conformance/parser/ecmascript5/SkippedTokens/parserSkippedTokens20.ts (3 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/SkippedTokens/parserSkippedTokens20.ts (2 errors) ==== var v: X' expected. \ No newline at end of file +!!! error TS1127: Invalid character. \ No newline at end of file diff --git a/tests/baselines/reference/parserX_TypeArgumentList1.errors.txt b/tests/baselines/reference/parserX_TypeArgumentList1.errors.txt index 13956c86e7d78..f6e910855b4fa 100644 --- a/tests/baselines/reference/parserX_TypeArgumentList1.errors.txt +++ b/tests/baselines/reference/parserX_TypeArgumentList1.errors.txt @@ -1,10 +1,19 @@ tests/cases/conformance/parser/ecmascript5/ErrorRecovery/TypeArgumentLists/parserX_TypeArgumentList1.ts(1,1): error TS2304: Cannot find name 'Foo'. +tests/cases/conformance/parser/ecmascript5/ErrorRecovery/TypeArgumentLists/parserX_TypeArgumentList1.ts(1,5): error TS2304: Cannot find name 'A'. +tests/cases/conformance/parser/ecmascript5/ErrorRecovery/TypeArgumentLists/parserX_TypeArgumentList1.ts(1,7): error TS2304: Cannot find name 'B'. tests/cases/conformance/parser/ecmascript5/ErrorRecovery/TypeArgumentLists/parserX_TypeArgumentList1.ts(1,9): error TS1127: Invalid character. +tests/cases/conformance/parser/ecmascript5/ErrorRecovery/TypeArgumentLists/parserX_TypeArgumentList1.ts(1,11): error TS2304: Cannot find name 'C'. -==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/TypeArgumentLists/parserX_TypeArgumentList1.ts (2 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/TypeArgumentLists/parserX_TypeArgumentList1.ts (5 errors) ==== Foo(4, 5, 6); ~~~ !!! error TS2304: Cannot find name 'Foo'. + ~ +!!! error TS2304: Cannot find name 'A'. + ~ +!!! error TS2304: Cannot find name 'B'. -!!! error TS1127: Invalid character. \ No newline at end of file +!!! error TS1127: Invalid character. + ~ +!!! error TS2304: Cannot find name 'C'. \ No newline at end of file diff --git a/tests/baselines/reference/parserX_TypeArgumentList1.js b/tests/baselines/reference/parserX_TypeArgumentList1.js index f1bd7f595ee28..c83223ee3fb49 100644 --- a/tests/baselines/reference/parserX_TypeArgumentList1.js +++ b/tests/baselines/reference/parserX_TypeArgumentList1.js @@ -2,4 +2,5 @@ Foo(4, 5, 6); //// [parserX_TypeArgumentList1.js] -Foo(4, 5, 6); +Foo < A, B, ; +C > (4, 5, 6); diff --git a/tests/baselines/reference/tsxCorrectlyParseLessThanComparison1.js b/tests/baselines/reference/tsxCorrectlyParseLessThanComparison1.js new file mode 100644 index 0000000000000..d466bb3ea3f51 --- /dev/null +++ b/tests/baselines/reference/tsxCorrectlyParseLessThanComparison1.js @@ -0,0 +1,41 @@ +//// [tsxCorrectlyParseLessThanComparison1.tsx] +declare module JSX { + interface Element { + div: string; + } +} +declare namespace React { + class Component { + constructor(props?: P, context?: any); + props: P; + } +} + +export class ShortDetails extends React.Component<{ id: number }, {}> { + public render(): JSX.Element { + if (this.props.id < 1) { + return (
); + } + } +} + +//// [tsxCorrectlyParseLessThanComparison1.js] +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var ShortDetails = (function (_super) { + __extends(ShortDetails, _super); + function ShortDetails() { + _super.apply(this, arguments); + } + ShortDetails.prototype.render = function () { + if (this.props.id < 1) { + return (React.createElement("div", null)); + } + }; + return ShortDetails; +}(React.Component)); +exports.ShortDetails = ShortDetails; diff --git a/tests/baselines/reference/tsxCorrectlyParseLessThanComparison1.symbols b/tests/baselines/reference/tsxCorrectlyParseLessThanComparison1.symbols new file mode 100644 index 0000000000000..d00b4ca115ff2 --- /dev/null +++ b/tests/baselines/reference/tsxCorrectlyParseLessThanComparison1.symbols @@ -0,0 +1,55 @@ +=== tests/cases/conformance/jsx/tsxCorrectlyParseLessThanComparison1.tsx === +declare module JSX { +>JSX : Symbol(JSX, Decl(tsxCorrectlyParseLessThanComparison1.tsx, 0, 0)) + + interface Element { +>Element : Symbol(Element, Decl(tsxCorrectlyParseLessThanComparison1.tsx, 0, 20)) + + div: string; +>div : Symbol(Element.div, Decl(tsxCorrectlyParseLessThanComparison1.tsx, 1, 23)) + } +} +declare namespace React { +>React : Symbol(React, Decl(tsxCorrectlyParseLessThanComparison1.tsx, 4, 1)) + + class Component { +>Component : Symbol(Component, Decl(tsxCorrectlyParseLessThanComparison1.tsx, 5, 25)) +>P : Symbol(P, Decl(tsxCorrectlyParseLessThanComparison1.tsx, 6, 20)) +>S : Symbol(S, Decl(tsxCorrectlyParseLessThanComparison1.tsx, 6, 22)) + + constructor(props?: P, context?: any); +>props : Symbol(props, Decl(tsxCorrectlyParseLessThanComparison1.tsx, 7, 20)) +>P : Symbol(P, Decl(tsxCorrectlyParseLessThanComparison1.tsx, 6, 20)) +>context : Symbol(context, Decl(tsxCorrectlyParseLessThanComparison1.tsx, 7, 30)) + + props: P; +>props : Symbol(Component.props, Decl(tsxCorrectlyParseLessThanComparison1.tsx, 7, 46)) +>P : Symbol(P, Decl(tsxCorrectlyParseLessThanComparison1.tsx, 6, 20)) + } +} + +export class ShortDetails extends React.Component<{ id: number }, {}> { +>ShortDetails : Symbol(ShortDetails, Decl(tsxCorrectlyParseLessThanComparison1.tsx, 10, 1)) +>React.Component : Symbol(React.Component, Decl(tsxCorrectlyParseLessThanComparison1.tsx, 5, 25)) +>React : Symbol(React, Decl(tsxCorrectlyParseLessThanComparison1.tsx, 4, 1)) +>Component : Symbol(React.Component, Decl(tsxCorrectlyParseLessThanComparison1.tsx, 5, 25)) +>id : Symbol(id, Decl(tsxCorrectlyParseLessThanComparison1.tsx, 12, 51)) + + public render(): JSX.Element { +>render : Symbol(ShortDetails.render, Decl(tsxCorrectlyParseLessThanComparison1.tsx, 12, 71)) +>JSX : Symbol(JSX, Decl(tsxCorrectlyParseLessThanComparison1.tsx, 0, 0)) +>Element : Symbol(JSX.Element, Decl(tsxCorrectlyParseLessThanComparison1.tsx, 0, 20)) + + if (this.props.id < 1) { +>this.props.id : Symbol(id, Decl(tsxCorrectlyParseLessThanComparison1.tsx, 12, 51)) +>this.props : Symbol(React.Component.props, Decl(tsxCorrectlyParseLessThanComparison1.tsx, 7, 46)) +>this : Symbol(ShortDetails, Decl(tsxCorrectlyParseLessThanComparison1.tsx, 10, 1)) +>props : Symbol(React.Component.props, Decl(tsxCorrectlyParseLessThanComparison1.tsx, 7, 46)) +>id : Symbol(id, Decl(tsxCorrectlyParseLessThanComparison1.tsx, 12, 51)) + + return (
); +>div : Symbol(unknown) +>div : Symbol(unknown) + } + } +} diff --git a/tests/baselines/reference/tsxCorrectlyParseLessThanComparison1.types b/tests/baselines/reference/tsxCorrectlyParseLessThanComparison1.types new file mode 100644 index 0000000000000..ca1bc492909a6 --- /dev/null +++ b/tests/baselines/reference/tsxCorrectlyParseLessThanComparison1.types @@ -0,0 +1,59 @@ +=== tests/cases/conformance/jsx/tsxCorrectlyParseLessThanComparison1.tsx === +declare module JSX { +>JSX : any + + interface Element { +>Element : Element + + div: string; +>div : string + } +} +declare namespace React { +>React : typeof React + + class Component { +>Component : Component +>P : P +>S : S + + constructor(props?: P, context?: any); +>props : P +>P : P +>context : any + + props: P; +>props : P +>P : P + } +} + +export class ShortDetails extends React.Component<{ id: number }, {}> { +>ShortDetails : ShortDetails +>React.Component : React.Component<{ id: number; }, {}> +>React : typeof React +>Component : typeof React.Component +>id : number + + public render(): JSX.Element { +>render : () => JSX.Element +>JSX : any +>Element : JSX.Element + + if (this.props.id < 1) { +>this.props.id < 1 : boolean +>this.props.id : number +>this.props : { id: number; } +>this : this +>props : { id: number; } +>id : number +>1 : number + + return (
); +>(
) : any +>
: any +>div : any +>div : any + } + } +} diff --git a/tests/cases/conformance/jsx/tsxCorrectlyParseLessThanComparison1.tsx b/tests/cases/conformance/jsx/tsxCorrectlyParseLessThanComparison1.tsx new file mode 100644 index 0000000000000..87a3d2d12aa37 --- /dev/null +++ b/tests/cases/conformance/jsx/tsxCorrectlyParseLessThanComparison1.tsx @@ -0,0 +1,20 @@ +// @jsx: react +declare module JSX { + interface Element { + div: string; + } +} +declare namespace React { + class Component { + constructor(props?: P, context?: any); + props: P; + } +} + +export class ShortDetails extends React.Component<{ id: number }, {}> { + public render(): JSX.Element { + if (this.props.id < 1) { + return (
); + } + } +} \ No newline at end of file