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
[babel 8] Recover from error when parsing <T>() => {}</T>
#14616
[babel 8] Recover from error when parsing <T>() => {}</T>
#14616
Conversation
// If the state was cloned in the JSX parsing branch above but there | ||
// have been any error in the tryParse call, this.state is set to state | ||
// so we still need to clone it. | ||
if (!state || state === this.state) state = this.state.clone(); |
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 change is because the below tryParse
call should always receive a clone of this.state
, and not this.state
itself.
if (!parameter.constraint) { | ||
// A single type parameter must either have constraints | ||
// or a trailing comma, otherwise it's ambiguous with JSX. | ||
this.raise(TSErrors.SingleTypeParameterWithoutTrailingComma, { |
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.
I moved this error within the this.tryParse
call, so that it know that there is a problem with the function. Otherwise, when parsing <T>() => {}</T>
it would give the precedence to the arrow function because it thought that <T>() => {}
could be pared without errors.
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/52071/ |
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.
Amazing work!
It looks like the prettier test is not failing anymore on |
cc @liuxingbaoyu