TypeScript: `x < y >= z` is incorrectly interpreted as a type argument list
evanw opened this issue · 1 comments
Here's a full example (link):
// Input
fn(x < y, x >= y)
// Sucrase
fn(x = y)
// TypeScript
fn(x < y, x >= y);
Specifically TypeScript's parseTypeArgumentsInExpression
function backtracks unless the trailing >
comes from a >
real token. This is subtle because TypeScript's type argument parser normally strips off the leading >
from a token, which is why >>
works in a<b<c>>(d)
. But it turns out that should only be done when you're in a type context. When you're in an expression context, the trailing >
must not come from a token that has anything else after it. So for example a<b<c>>=(d)
should not be considered a type argument list because parseTypeArgumentsInExpression
encounters a >=
token.
I just fixed this bug in esbuild: evanw/esbuild#3111. I'm reporting it here because Sucrase appears to also have this issue. The bug does not introduce a syntax error, which means the problematic output might be missed before releasing it, so I considered this bug to be higher severity.
Thank you letting me know! Agreed that it's higher severity.