printer: Support \n\n while printing JSXElement children #1396
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.
The printer seems to treat any number of newlines within a
JSXText
as a single newline. This causes any transform touching these elements to remove newlines that tooling such as Prettier would otherwise not remove.Though I'm a little surprised to not see the same formatting difference in ASTExplorer, though it's running on 0.21.1 instead of the latest version (0.23.6), so maybe this was a regression at some point? I can reproduce it both within the test suite, and transforms using 0.23.6.
Edit: Oh, this was because by default the transform itself was using
parsers.esprima
. It's reproducible if you swap toparsers.babel
, example.Current behavior:
This PR updates the printer for
JSXElement
/JSXFragment
to return two newlines instead of a single newline for any string children which include two adjacent newlines.Proposed behavior:
Thanks in advance for any review. This seems like an innocent enough change, but I'd entirely understand if it's more complicated than I'm imagining. Open to feedback and happy to iterate on this PR!