-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Ensure we treat "type assertions" as JSX within a unary expression #52667
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
Conversation
I seem to recall a change was made a year or so ago to deliberately not parse legacy type assertions in JS in order to resolve ambiguity with expressions like |
Unfortunately, I can’t seem to find the issue/PR for that now. I did find several comments— including one from Ryan—suggesting JSX is always parsed in |
My impression was that we conditionalized a lot of the parser on the file extension, including JSX stuff. But that's still a good point, and I need to go figure out if this production should even be parsed. |
So yep, you're right; we do generally treat JS as JSX. Going though this, though, here's what's happening; given: const foo = <number> bar Here, we see that there's a But, if we instead stick a unary operator at the front, like: const foo = +<number> bar We see that it's not an update expression, so we parse a "simple" unary expression, but as the parser currently operates, a simple unary expression only ever parses more simple unary expressions afterwards, i.e. I'm pretty sure that we need to be parsing JSX here as you've said, so, thanks for the catch. That's what esbuild does too (try changing the extension around between ts/js/tsx/jsx, and I think that's correct. |
@typescript-bot test this |
Heya @jakebailey, I've started to run the diff-based user code test suite (tsserver) on this PR at f027812. You can monitor the build here. Update: The results are in! |
Heya @jakebailey, I've started to run the parallelized Definitely Typed test suite on this PR at f027812. You can monitor the build here. |
Heya @jakebailey, I've started to run the diff-based top-repos suite on this PR at f027812. You can monitor the build here. Update: The results are in! |
Heya @jakebailey, I've started to run the extended test suite on this PR at f027812. You can monitor the build here. |
Heya @jakebailey, I've started to run the tarball bundle task on this PR at f027812. You can monitor the build here. |
Heya @jakebailey, I've started to run the diff-based user code test suite on this PR at f027812. You can monitor the build here. Update: The results are in! |
Heya @jakebailey, I've started to run the perf test suite on this PR at f027812. You can monitor the build here. Update: The results are in! |
Hey @jakebailey, I've packed this into an installable tgz. You can install it for testing by referencing it in your
and then running There is also a playground for this build and an npm module you can use via |
@jakebailey Here are the results of running the user test suite comparing Everything looks good! |
@jakebailey Here are the results of running the user test suite comparing Something interesting changed - please have a look. Detailsnpm
|
Heya @jakebailey, I've run the RWC suite on this PR - assuming you're on the TS core team, you can view the resulting diff here. |
@jakebailey Here they are:
CompilerComparison Report - main..52667
System
Hosts
Scenarios
TSServerComparison Report - main..52667
System
Hosts
Scenarios
StartupComparison Report - main..52667
System
Hosts
Scenarios
Developer Information: |
@jakebailey Here are the results of running the top-repos suite comparing Everything looks good! |
@jakebailey Here are the results of running the top-repos suite comparing Something interesting changed - please have a look. Detailsakveo/ngx-admin
|
@jakebailey Here are some more interesting changes from running the top-repos suite Detailsbackstage/backstage
|
@jakebailey Here are some more interesting changes from running the top-repos suite Detailsfelixrieseberg/windows95
|
@jakebailey Here are some more interesting changes from running the top-repos suite Detailsmicrosoft/vscode
|
@jakebailey Here are some more interesting changes from running the top-repos suite Detailspalantir/blueprint
|
@jakebailey Here are some more interesting changes from running the top-repos suite DetailsReactiveX/rxjs
|
@jakebailey Here are some more interesting changes from running the top-repos suite Detailstypeorm/typeorm
|
Fixes #50675
The comment claims we won't parse these in JS files, but that's not true; we can pretty easily parse them just like we doas
and should error on them just like we doas
.See: #52667 (comment)