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
Fix parsing typescript function types with destructuring #9035
Conversation
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/9401/ |
@@ -747,6 +753,22 @@ export default (superClass: Class<Parser>): Class<Parser> => | |||
this.next(); | |||
return true; | |||
} | |||
|
|||
if (this.match(tt.braceL)) { | |||
const braceStack = [tt.braceL]; |
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.
This can be an integer instead of an array, since the check only uses its length.
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.
changed
const braceStack = [tt.braceL]; | ||
this.next(); | ||
|
||
while (braceStack.length > 0) { |
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.
Is it safe to skip the code between braces without parsing it?
e.g., wouldn't this loop accept something like {bar: {}{foo = 2=>{} }}
?
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 does ignore everything, even if its invalid, but this function is only used in a lookahead() and it's job is to try to skip the first param after (
.
it is used here:
tsIsUnambiguouslyStartOfFunctionType(): boolean { |
and this in turn is used here:
tsIsStartOfFunctionType() { |
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.
Oh ok 👍
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.
Nice! 👍
Allows parsing of destructured params in function type declarations.