-
Notifications
You must be signed in to change notification settings - Fork 143
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
Support TypeScript 4.0 and logical assignment operators #550
Comments
Happy to help out with any of these if needed! |
@Rugvip thanks! Sorry, I haven't had a lot of bandwidth to work on this project, so help would definitely be appreciated! Happy to take a look at a PR and provide any guidance. Some thoughts on what the best implementation approach is: Labeled tuple elements and unknown on catch clause bindingsThese are both purely type system extensions, so only the parser needs to change here. As long as parsing completes successfully any type-related tokens have TypeScript features tend to be implemented in Babel in a timely manner, so the best way to pull in new syntax like this is by looking through the babel-parser changes since the last pass and applying any that are relevant to Sucrase. Sucrase's The last PR where I ported changes over was #523, and you can find others in the history. It would be nice to keep the commit description in the same format as #523: a comprehensive list of commits in the babel-parser package starting from 2020-04-12, with a 🚫 or ✅ for whether they need to be applied. To list the relevant commits to consider, you can clone the
As you can probabbly see from #523, most commits don't need any action, in part due to Sucrase having an intentionally smaller scope. Some examples of commits to skip:
To properly apply a PR, I'd recommend reading the actual pull request (e.g. babel/babel#11755 ) to understand the context around the change. For the TS features, you might also want to dig into the git history of the TypeScript repo and read its implementation of the parsing. In any case, having good test coverage in Sucrase (generally with tests in You'll also want to get rid of any of the "[skip ci]" directives in commit titles, since that will cause CI for your PR to get skipped. If you hit issues, feel free to raise them as questions in the PR, or apply a smaller commit range to keep the PR scope smaller. Logical assignment operatorsHigher-level thought: It may be best to not implement this transform for the sake of simplicity, but ultimately it depends on how hard the transform is. This case falls under "Sucrase is hesitant to implement upcoming JS features" from the README. Just like class fields and optional chaining, logical assignment operators will eventually be widely supported natively and not needed as a Sucrase transform. My impression is that logical assignment operators aren't nearly as high-value as class fields or optional chaining, so the value may not be enough to justify the implementation/complexity cost. But if you or others feel strongly about the value, or if the implementation actually isn't so bad, it seems reasonable to include. Assuming it makes sense to implement, a few thoughts come to mind:
Hope that all helps! Again, happy to take a look at a PR or answer questions. |
#556 Now has the parser updates required for "Labeled tuple elements" and "unknown on catch clause bindings". Regarding "Logical assignment operators" I'll dive into looking at a transform for a bit, since the syntax is not gonna be supported in widely used NodeJS versions for some time. |
This is not supported by Sucrase and would break Node 14 attempts to build the client: alangpierce/sucrase#550
TypeScript 4.0 was released yesterday, and it incorporates a number of additions, some of which Sucrase does not support:
Labeled tuple elements
unknown
oncatch
clause bindingsLogical assignment operators
This is, of course, not specific to TypeScript, but a TC39 proposal that became Stage 4 in July and is due for inclusion in ECMAScript 2021.
Sucrase outputs:
tsc
and Babel compile these operators down toobj.prop && (obj.prop = foo());
The text was updated successfully, but these errors were encountered: