fix(js_formatter): Avoid double-printing the first leading comments in arrow chains #951
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Playground Example.
Summary
ArrowChain
is a special case ofFormatJsArrowFunctionExpression
that handles formatting all of the nested arrow functions inside of it as a single node point. The top formatting node handles formatting comments, just like any other formatting node, but because all of the other arrow expressions are handled within that node, the chain must print all of their leading comments manually.However, the logic just used a loop and checked each arrow for a leading comment to then print it out if it exists. This included the first arrow expression in the chain as well, meaning the comment would be double printed; once by the parent Format node, and again by the inner loop.
This PR updates the logic to skip printing the leading comment for the first arrow in the chain, leaving it to only be printed once by the parent Format node.
Closes #921.
Test Plan
There aren't any tests that currently cover this case, but since it's just a minor fix to the logic I think it's okay to not have an additional test just for it. It should get handled implicitly by most of the other tests with comments around arrow chains.