Reinterpret << when parsing TS type arguments#14145
Merged
JLHwung merged 6 commits intobabel:mainfrom Jan 24, 2022
Merged
Conversation
Collaborator
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/50893/ |
Member
nicolo-ribaudo
left a comment
There was a problem hiding this comment.
It looks like it already works, but can you also add a test for <<<? f<<<T>(x) is f << (<T> x) (with JSX disabled)
And also a test for when << is a real bit shift: f<<T>((x)=>string)>(x);
| super.parseClassSuper(node); | ||
| if (node.superClass && this.match(tt.lt)) { | ||
| node.superTypeParameters = this.tsParseTypeArguments(); | ||
| // handle `extends f()<<T> |
Member
There was a problem hiding this comment.
Q: Why f()<<T> and not f<<T>?
Contributor
Author
There was a problem hiding this comment.
Good catch. It can be simplified.
nicolo-ribaudo
approved these changes
Jan 13, 2022
sosukesuzuki
approved these changes
Jan 23, 2022
fisker
added a commit
to prettier/prettier
that referenced
this pull request
Feb 7, 2022
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I didn't port the fixe to Flow because Flow does not support
f<<T>(v: T) => void>(), but it does supportf< <T>(v: T) => void>(). I will open an issue to Flow later. Before Flow supports it let's focus on the TS.In this PR we split
tt.bitShiftintott.bitShiftL(<<) andtt.bitShiftR(>>). Then we reinterpret<<as<when parsing type arguments from ES productions. We don't need to handle<<when we are parsing from TS productions becausegetTokenFromTypeensures that<is always tokenized intott.ltwhenstate.inTypeistrue.