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 missing inner comments in function expressions #13825
Fix missing inner comments in function expressions #13825
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit d86b098:
|
const f = function /*foo*/ () {}; | ||
const g = async function /*foo*/ () {}; | ||
const h = function* /*foo*/ () {}; | ||
const i = async function* /*foo*/ () {}; |
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 a new test case?
const j = function (/*foo*/) {};
it will be printed as
const j = function /*foo*/ () {};
I think we don't have to fix that. It is the nature of using AST for comment attachment targets.
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.
Have pushed another commit adding this case.
I also added cases for other positions of comments in async + generator functions.
const x = async /*foo*/ function () {};
const y = function/*foo*/* () {};
Similarly, these don't come out quite the same as the input, but at least the comment isn't omitted entirely now.
The CI failures seem to be caused by the npm outage. |
Thanks all! |
Same as #13824 but for function expressions.
Similar to #13819, function expressions with inner comments do not have the comments output by
generate()
. This PR fixes that.For async functions, there's some ambiguity as to where the comment should be output i.e.:
or:
I have gone for the latter as for single line comments, putting the comment after
async
is invalid JS. This is not valid:whereas this is: