fix(core): 🐛 Preserve meaningful whitespace #1219
Open
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.
Fixes #1218
Description
Some code generators were joining blocks with newlines (
\n
), which, when run through thededent
helper, would then trim any trailing whitespace. This ended up causing problems with significant whitespace in some scenarios.This PR simply changes the join operation to use the empty string. The parser for mitosis already preserves the significant whitespace, so this makes the output components more closely resemble their mitosis source code. Prettier can still be used to format the output code, which will use a syntax tree that preserves meaningful whitespace while avoiding excessively long line lengths and adding stylistic line breaks.
The main focus for review should be:
componentToX
function that calls ablockToX
function recursively and joins children together, would it make sense to have a helper method for the join operation so that this type of change can be made more accurately across generators?