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 nestled JSDoc comments #13445
Conversation
/** Trailing nestled comment 1 | ||
*/ /** Trailing nestled comment 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.
Should they stick together?
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.
Depends on whether we need to support this for single-line comments.
Oops! Forgot to test dangling comments: Prettier pr-13445 --parser babel Input: {{{{{{{
o={
/**
* nestled
*//**
* nestled
*/
}
}}}}}}} Output: {
{
{
{
{
{
{
o = {
/**
* nestled
*/
/**
* nestled
*/
};
}
}
}
}
}
}
} |
Maybe easier to merge them into one comment after parse? |
The code for printing dangling comments needs to be refined anyway. Now it's very basic. It prints every comment on a new line and doesn't preserve blank lines between comments. Instead its logic should be similar to how trailing comments are printed. But it's something for a separate PR. As for this PR, what if we just skip this feature for dangling comments for now? I'll just add a check that dangling comments can't be considered nestled. |
Any comment on this idea? #13445 |
IDK. Merging would work too, but it's difficult to say if it's going to make things simpler. |
Shouldn't it work without any change to the print part? |
For the print part - yes. I thought merging itself might be a bit tricky, but I may be wrong. |
Aren't they looks like one comment? Would like to try? |
Yes, I'm going to try that approach. |
666c538
to
98d4265
Compare
isIndentableBlockComment(comment) && | ||
isBlockComment(nextComment) && | ||
isIndentableBlockComment(nextComment) && | ||
locEnd(comment) === locStart(nextComment) |
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.
loc
compare should be faster than isIndentableBlockComment
check, let's move this condition up
Maybe we should extract Size Change: +605 kB (+6%) 🔍 Total Size: 11.5 MB
|
badb842
to
5751d96
Compare
BTW, I agree with this opinion on default exports https://mobile.twitter.com/stefanjudis/status/1566047068510093315 :) |
...comment, | ||
value: comment.value + "*//*" + followingComment.value, | ||
range: [locStart(comment), locEnd(followingComment)], | ||
}; |
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.
We already mutate the array, let's mutate the comment directly?
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 job!
Co-authored-by: fisker Cheung <lionkay@gmail.com>
c45541c
to
796d25b
Compare
796d25b
to
7d5f852
Compare
@@ -329,7 +330,6 @@ module.exports = { | |||
functions: ["hasComment", "getComments"], | |||
}, | |||
"src/language-js/pragma.js", | |||
"src/language-js/parse/postprocess/*.js", |
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 didn't work because the rule doesn't resolve globs.
Description
Fixes #12653
Checklist
docs/
directory).changelog_unreleased/*/XXXX.md
file followingchangelog_unreleased/TEMPLATE.md
.✨Try the playground for this PR✨