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
Reinterpret << when parsing TS type arguments #14145
Conversation
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/50893/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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);
@@ -2818,8 +2829,9 @@ export default (superClass: Class<Parser>): Class<Parser> => | |||
|
|||
parseClassSuper(node: N.Class): void { | |||
super.parseClassSuper(node); | |||
if (node.superClass && this.match(tt.lt)) { | |||
node.superTypeParameters = this.tsParseTypeArguments(); | |||
// handle `extends f()<<T> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q: Why f()<<T>
and not f<<T>
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. It can be simplified.
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.bitShift
intott.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 becausegetTokenFromType
ensures that<
is always tokenized intott.lt
whenstate.inType
istrue
.