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 more inner comments #15008
Support more inner comments #15008
Conversation
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/53221/ |
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.
Can you add this test? (I don't think we can properly print it and that's fine)
class A {
async /* 1 */ * /* 2 */ method /* 3 */ ( /* 4 */ ) /* 5 */ {}
}
Yeah. When an AST node has more than one empty spot, the inner comments are not sufficient for recreating code exactly from AST. But at least the printer can preserve such comments instead of discarding them silently. |
Can this be postponed for a while? I'm going to rebase this after the #14979 merge, it's a bit cumbersome to rebase that one. Thanks! |
a676067
to
4d8910e
Compare
@@ -1 +1 @@ | |||
const x = (foo /*: string*/) => {}; | |||
const x = foo /*: string*/ => {}; |
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 is not a valid Flow comment. If the arrow function has a single parameter with a trailing block comment that starts with :
, we should still print the parentheses.
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.
Sad that flow does not support that. In that case we can partially revert the arrow function commit.
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.
There doesn't seem to be a change here?
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.
Ah I forgot to update the plugin test fixtures.
4d8910e
to
bf82944
Compare
This PR supports inner comments attached to generators, async methods and async do expressions. Because such inner comments must be block comments due to the noLineTerminator restrictions, we then ensure that such restrictions are respected by the babel-generator.
This PR also relaxes the condition when Babel prints single arrow binding
x => {}
. Before this PR we prints(x) => {}
whenx
has attached comments. In this PR we relaxes the condition so that we can still output/* leading */x/* trailing */ => {}
.