Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly re-scan > token in type argument list determination logic #49560

Merged
merged 2 commits into from Jun 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/compiler/parser.ts
Expand Up @@ -5764,10 +5764,11 @@ namespace ts {
nextToken();

const typeArguments = parseDelimitedList(ParsingContext.TypeArguments, parseType);
if (!parseExpected(SyntaxKind.GreaterThanToken)) {
if (reScanGreaterToken() !== SyntaxKind.GreaterThanToken) {
// If it doesn't have the closing `>` then it's definitely not an type argument list.
return undefined;
}
nextToken();

// We successfully parsed a type argument list. The next token determines whether we want to
// treat it as such. If the type argument list is followed by `(` or a template literal, as in
Expand Down
Expand Up @@ -140,4 +140,10 @@ tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiationExpr
protected specialFoo = f<string>
protected bar = 123
}

// Repro from #49551

const enum MyVer { v1 = 1, v2 = 2 }
let ver = 21
const a = ver < (MyVer.v1 >= MyVer.v2 ? MyVer.v1 : MyVer.v2)

14 changes: 14 additions & 0 deletions tests/baselines/reference/instantiationExpressionErrors.js
Expand Up @@ -96,6 +96,12 @@ class C4 {
protected specialFoo = f<string>
protected bar = 123
}

// Repro from #49551

const enum MyVer { v1 = 1, v2 = 2 }
let ver = 21
const a = ver < (MyVer.v1 >= MyVer.v2 ? MyVer.v1 : MyVer.v2)


//// [instantiationExpressionErrors.js]
Expand Down Expand Up @@ -179,6 +185,8 @@ var C4 = /** @class */ (function () {
}
return C4;
}());
var ver = 21;
var a = ver < (1 /* MyVer.v1 */ >= 2 /* MyVer.v2 */ ? 1 /* MyVer.v1 */ : 2 /* MyVer.v2 */);


//// [instantiationExpressionErrors.d.ts]
Expand Down Expand Up @@ -283,3 +291,9 @@ declare class C4 {
};
protected bar: number;
}
declare const enum MyVer {
v1 = 1,
v2 = 2
}
declare let ver: number;
declare const a: boolean;
26 changes: 26 additions & 0 deletions tests/baselines/reference/instantiationExpressionErrors.symbols
Expand Up @@ -239,3 +239,29 @@ class C4 {
>bar : Symbol(C4.bar, Decl(instantiationExpressionErrors.ts, 94, 36))
}

// Repro from #49551

const enum MyVer { v1 = 1, v2 = 2 }
>MyVer : Symbol(MyVer, Decl(instantiationExpressionErrors.ts, 96, 1))
>v1 : Symbol(MyVer.v1, Decl(instantiationExpressionErrors.ts, 100, 18))
>v2 : Symbol(MyVer.v2, Decl(instantiationExpressionErrors.ts, 100, 26))

let ver = 21
>ver : Symbol(ver, Decl(instantiationExpressionErrors.ts, 101, 3))

const a = ver < (MyVer.v1 >= MyVer.v2 ? MyVer.v1 : MyVer.v2)
>a : Symbol(a, Decl(instantiationExpressionErrors.ts, 102, 5))
>ver : Symbol(ver, Decl(instantiationExpressionErrors.ts, 101, 3))
>MyVer.v1 : Symbol(MyVer.v1, Decl(instantiationExpressionErrors.ts, 100, 18))
>MyVer : Symbol(MyVer, Decl(instantiationExpressionErrors.ts, 96, 1))
>v1 : Symbol(MyVer.v1, Decl(instantiationExpressionErrors.ts, 100, 18))
>MyVer.v2 : Symbol(MyVer.v2, Decl(instantiationExpressionErrors.ts, 100, 26))
>MyVer : Symbol(MyVer, Decl(instantiationExpressionErrors.ts, 96, 1))
>v2 : Symbol(MyVer.v2, Decl(instantiationExpressionErrors.ts, 100, 26))
>MyVer.v1 : Symbol(MyVer.v1, Decl(instantiationExpressionErrors.ts, 100, 18))
>MyVer : Symbol(MyVer, Decl(instantiationExpressionErrors.ts, 96, 1))
>v1 : Symbol(MyVer.v1, Decl(instantiationExpressionErrors.ts, 100, 18))
>MyVer.v2 : Symbol(MyVer.v2, Decl(instantiationExpressionErrors.ts, 100, 26))
>MyVer : Symbol(MyVer, Decl(instantiationExpressionErrors.ts, 96, 1))
>v2 : Symbol(MyVer.v2, Decl(instantiationExpressionErrors.ts, 100, 26))

33 changes: 33 additions & 0 deletions tests/baselines/reference/instantiationExpressionErrors.types
Expand Up @@ -325,3 +325,36 @@ class C4 {
>123 : 123
}

// Repro from #49551

const enum MyVer { v1 = 1, v2 = 2 }
>MyVer : MyVer
>v1 : MyVer.v1
>1 : 1
>v2 : MyVer.v2
>2 : 2

let ver = 21
>ver : number
>21 : 21

const a = ver < (MyVer.v1 >= MyVer.v2 ? MyVer.v1 : MyVer.v2)
>a : boolean
>ver < (MyVer.v1 >= MyVer.v2 ? MyVer.v1 : MyVer.v2) : boolean
>ver : number
>(MyVer.v1 >= MyVer.v2 ? MyVer.v1 : MyVer.v2) : MyVer
>MyVer.v1 >= MyVer.v2 ? MyVer.v1 : MyVer.v2 : MyVer
>MyVer.v1 >= MyVer.v2 : boolean
>MyVer.v1 : MyVer.v1
>MyVer : typeof MyVer
>v1 : MyVer.v1
>MyVer.v2 : MyVer.v2
>MyVer : typeof MyVer
>v2 : MyVer.v2
>MyVer.v1 : MyVer.v1
>MyVer : typeof MyVer
>v1 : MyVer.v1
>MyVer.v2 : MyVer.v2
>MyVer : typeof MyVer
>v2 : MyVer.v2

Expand Up @@ -98,3 +98,9 @@ class C4 {
protected specialFoo = f<string>
protected bar = 123
}

// Repro from #49551

const enum MyVer { v1 = 1, v2 = 2 }
let ver = 21
const a = ver < (MyVer.v1 >= MyVer.v2 ? MyVer.v1 : MyVer.v2)