-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
[Bug]: Typescript parser crash on as
-style assertion on generic instantiation expression
#15990
Comments
Hey @ethanresnick! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly. If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite. |
Ugh very annoying that this code has two completely different meanings in JavaScript and in TypeScript: let x = foo < 2 > as
F.getter; |
However, given that both Babel and SWC parse it according to the ECMAScript spec even when parsing TypeScript, we might try to get the TS team to change their parsing. NOTE: We should still be able to parse the example in the OP, but let's wait for a decision on the TS side. |
We've just faced the same issue today at work with the following repro case (we use Vite): Valid on TS sideParsing fails with Babel |
How are you using Babel?
Other (Next.js, Gatsby, vue-cli, ...)
Input code
jsonParse<SomeType>
is an instantiation expression, which is followed by a cast. As also shown in the repl, the same code works when the cast is written with angle-bracket syntax.See REPL: https://babel.dev/repl#?browsers=defaults%2C%20not%20ie%2011%2C%20not%20ie_mob%2011&build=&builtIns=false&corejs=3.21&spec=false&loose=false&code_lz=PTAEAcCcHsBMFcDGBTAzqAhhDlXMqPjJAFCLQB2qALqAB6gC8oAVqpQAo54A8AytAC2yACoBPcMgB8mdAAoakAFyhFASwoBzAJRMZAaWRjxkkiRCgA7tEgBrdADMNyMpRr0moHgurLVvjR09UENjCWk2Tm5kfiFRcKkgA&debug=false&forceAllTransforms=false&modules=false&shippedProposals=false&circleciRepo=&evaluate=false&fileSize=false&timeTravel=false&sourceType=module&lineWrap=true&presets=typescript&prettier=false&targets=&version=7.22.20&externalPlugins=&assumptions={}
Configuration file name
No response
Configuration
See REPL.
Current and expected behavior
The code in the REPL (i.e.
const x = jsonParse<SomeType> as (str: string) => KeyType
) should parse successfully, as it's valid TS.Environment
System:
OS: macOS 13.5.1
Binaries:
Node: 20.0.0 - ~/.nvm/versions/node/v20.0.0/bin/node
npm: 9.6.4 - ~/.nvm/versions/node/v20.0.0/bin/npm
Possible solution
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: