[Bug]: x < y >= z
is incorrectly considered an assignment expression in TypeScript
#15628
Closed
1 task
Labels
area: typescript
i: bug
outdated
A closed issue/PR that is archived due to age. Recommended to make a new issue
pkg: parser
💻
How are you using Babel?
Other (Next.js, Gatsby, vue-cli, ...)
Input code
REPL: link
Configuration file name
No response
Configuration
No response
Current and expected behavior
When this TypeScript code is transformed into JavaScript by Babel, Babel fails with the following error:
The official TypeScript compiler succeeds with the following output instead:
Environment
(I only ran Babel via the REPL)
Possible solution
Here's what I discovered when I fixed this for esbuild: 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 ina<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 examplea<b<c>>=(d)
should not be considered a type argument list becauseparseTypeArgumentsInExpression
encounters a>=
token.Additional context
I just fixed this bug in esbuild: evanw/esbuild#3111. I'm reporting it here because Babel appears to have a similar issue.
The text was updated successfully, but these errors were encountered: